Traffic Light Control Using 8051
Traffic Light Control Using 8051
ALP:
org 00h
;origin directive
again: mov p0,#00h
;clear port 0 bits
acall delay
;call delay
mov p0,#55h
;sets even pins of port 0 to high
acall delay
mov p0,#0aah
;sets odd pins of port 0 to high
acall delay
mov p0,#0ffh
;sets all the pins of port 0 to high
acall delay
sjmp again
;short jump to the given label
delay: mov r0,#06h
;loads r0 with the immediate value of 6
loop: djnz r0,loop
;loop till zero flag is not set
ret
;returns to the main program
end
;end directive
C-code:
#include<reg51.h>
// special function register declarations for the
intended 8051 derivative
void delay(void);
//function declaration
void main (void)
{
while(1)
//infinite loop
{
P0= 0x00;
//clear port 0
delay();
//call delay function
P0= 0x55;
//odd LEDs blinking
delay();
P0= 0xaa;
//even LEDs blinking
delay();
P0= 0xff;
//all LEDs blinking
delay();
}
}
void delay(void)
//defining delay function
{
int i;
for(i=0;i<3;i++)
{
;}
}