0

So I'm building a simple MikroC program that sets PORTB.B0 if PORTA.B0 is equaled to 1

void main() {
   PORTA.B0=1;
   while(1){
   if(PORTA.B0){
        PORTB.B0=1;
   }
   }
}

However it doesn't give me anything PortB.B0 isn't equal to 1 only portA.

Can anyone help?

David Daniels
  • 131
  • 1
  • 7

2 Answers2

1

According to your code you, you must have initialized the direction of the portb.rb0 and porta.ra0 bits as output and input respectively. Also you need to give a little delay for de-bouncing.

void main()
{
ANSEL=0x00;
trisa.ra0=1; //for input
trisb.rb0=0; //for output
while(1)
{
   if (porta.ra0)
   {
     portb.rb0=1;  // setting high
     delay_ms(300); // time to stabilize mechanical button
    }
}

}
0

Just try if(PORTA.B0==1). This should work.

FouLiNuX
  • 51
  • 6