Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

coding to change the state of led using push button

Status
Not open for further replies.

apizbaygon

Junior Member level 3
Junior Member level 3
Joined
Jan 5, 2013
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,431
i have a problem with my coding to change state of leds in pic16f877a when push button is active...i want to change the led pattern in port b, and d when press the push button..

i have 3 condition for this system and of course it can't use 'if' and 'else' right???
anyone please help me???
 

thi is my code.the problem is after i compile,it show ';' expected but LED0 found


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;

}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top