alpha91
Full Member level 3
Hi all, I am learning Switch Statement in C currently and i wrote a code for testing with MikroC.
The code is compile and no error but it just now working. Can anyone help me to check what's my mistake here?
Function of the code:
When button at Port A0 is pressed, it should change the LED output style.
My code is as below:
i checked my hardware. everything is fine.
The code is compile and no error but it just now working. Can anyone help me to check what's my mistake here?
Function of the code:
When button at Port A0 is pressed, it should change the LED output style.
My code is as below:
unsigned short num;
unsigned i;
void main() {
CMCON = 0x07;
TRISB = 0x00;
TRISA = 0xFF;
num = 1;
while (1){
switch (num){
case 1: PORTB = 0x01;
delay_ms(300);
PORTB = 0x00;
delay_ms(300);
break;
case 2: PORTB = 0x02;
delay_ms(300);
PORTB = 0x00;
delay_ms(300);
break;
case 3: PORTB = 0x03;
delay_ms(300);
PORTB = 0x00;
delay_ms(300);
break;
}
if (PORTA.F0 == 1) {
delay_ms(50);
if (PORTA.F0 == 1) {
i++;
num = i;
}
}
}
}
i checked my hardware. everything is fine.