nandini88
Junior Member level 2
why the LED keep blinking even thought i not press any button. pls anybody correct the code for me. thank you
Code:
unsigned short i;
void main()
{
TRISB= 0xFF;
PORTB=0x00;
TRISD = 0x00; // PORTB as ouput
PORTD = 0x00; // Set port output as all 0's
while(1){
if(TRISB.F0==1) { // Detect logical one to zero
for(i=0;i <50; i++){ //repeat 50 times
PORTD.F0 = 0; //switch on LED at PORTB pin 0
delay_ms(150); //short delay
PORTD.F0 = 1; //switch off LED
delay_ms(150);
}
}
if(TRISB.F1==1) { // Detect logical one to zero
for(i=0;i < 100; i++){ //repeat 100 times
PORTD.F0 = 0; //switch on LED at PORTB pin 0
delay_ms(150); //short delay
PORTD.F0 = 1; //switch off LED
delay_ms(150);
}
}
if(TRISB.F2==1) { // Detect logical one to zero
for(i=0; i<1000; i++){ //repeat 1000 times
PORTD.F0 = 0; //switch on LED at PORTB pin 0
delay_ms(150); //short delay
PORTD.F0 = 1; //switch off LED
delay_ms(150);
}
}
}
}
Last edited: