Hello to all over here .
Am trying to make this work , it principe is simple , i have 6 push buttons on PORTA & 6 leds to light up one by one on a infinite loop .
What i know about switch case statement is that it switchs the state of a PORT
according to the condition of another port state .
For exaple here i want the leds to be lit one by one in a loop without pressing the PORTA buttons .
I know it not necessary to use the push buttons but am just trying to make the switch function work .
Here is the code text .
Am trying to make this work , it principe is simple , i have 6 push buttons on PORTA & 6 leds to light up one by one on a infinite loop .
What i know about switch case statement is that it switchs the state of a PORT
according to the condition of another port state .
For exaple here i want the leds to be lit one by one in a loop without pressing the PORTA buttons .
I know it not necessary to use the push buttons but am just trying to make the switch function work .
Here is the code text .
Rich (BB code):
void main() {
PORTA=0x00;
PORTB=0x00;
TRISA=0xff;
TRISB=0x00;
while(1){
switch(PORTA){
case 1:
PORTB.B0=1;
break;
delay_ms(500);
case 2:
PORTB.B1=1;
break;
delay_ms(500);
case 4:
PORTB.B2=1;
break;
delay_ms(500);
case 8:
PORTB.B3=1;
break;
delay_ms(500);
case 16:
PORTB.B4=1;
break;
delay_ms(500);
case 32:
PORTB.B5=1;
break;
delay_ms(500);
}
}
}
Attachments
-
118 KB Views: 46