apizbaygon
Junior Member level 3
- Joined
- Jan 5, 2013
- Messages
- 26
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,431
This is my coding to change the led patterns when pushbutton is active but it doesn't work..the message show ';' expected but LED0 found...someone please help me..here is my coding
Code:
#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
static bit LED0 @ PORTBIT(PORTC, 0) ;
static bit LED1 @ PORTBIT(PORTC, 1) ;
static bit LED2 @ PORTBIT(PORTC, 2) ;
static bit LED3 @ PORTBIT(PORTC, 3) ;
unsigned int pattern = 1; // Initialize pattern equal to zero
void main()
{
ANSEL = 0; // Intialize A/D ports off
PORTC = 0x00; //Clear PortC port
TRISC = 0x00; //All PortC I/O outputs
TRISA = 0xFF; //All PortA I/O inputs
while(1==1) //loop forever
{
//check if button is pressed
if(RA3==0)
{
while (!RA3); // Hold here until switch is released
_delay_ms(10); // Delay 10 milliseconds and check again
while (!RA3); // For simple debounce of switch
pattern=pattern+1;
if(pattern>3) {pattern=1;}
}
LED0 = 1;
delay_ms(500);
LED0 = 0;
LED1 = 1;
delay_ms(500);
LED1 = 0;
LED2 = 1;
delay_ms(500);
LED2 = 0;
LED3 = 1;
delay_ms(500);
LED3 = 0;
LED2 = 1;
delay_ms(10);
LED2 = 0;
LED1 = 1;
delay_ms(10);
LED1 = 0;
LED0 = 1;
delay_ms(10);
PORTC = 0b00000000;
}
if(pattern==2)
{
// LED1=1;
PORTC = 0b10101010;
delay_ms(10);
PORTC = 0b01010101;
delay_ms(20);
}
if(pattern==3)
{
//forward
LED0 = 1;
delay_ms(300);
LED0 = 0;
LED1 = 1;
delay_ms(300);
LED1 = 0;
LED2 = 1;
delay_ms(300);
LED2 = 0;
LED3 = 1;
delay_ms(300);
LED3 = 0;
LED2 = 1;
delay_ms(300);
LED2 = 0;
LED1 = 1;
delay_ms(300);
LED1 = 0;
LED0 = 1;
delay_ms(300);
PORTC = 0b00000000;
}