0% found this document useful (0 votes)
735 views1 page

Traffic Light Control Using 8051

This document shows code for interfacing LEDs to an 8051 microcontroller. The assembly code uses port 0 and calls a delay function to blink the LEDs connected to the port pins in different patterns. The C code defines equivalent functions to clear and set the port pins, call a delay function in a loop to blink the LEDs, and defines the delay function to create a short delay.

Uploaded by

Raghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
735 views1 page

Traffic Light Control Using 8051

This document shows code for interfacing LEDs to an 8051 microcontroller. The assembly code uses port 0 and calls a delay function to blink the LEDs connected to the port pins in different patterns. The C code defines equivalent functions to clear and set the port pins, call a delay function in a loop to blink the LEDs, and defines the delay function to create a short delay.

Uploaded by

Raghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

Interfacing LEDs to 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++)
{
;}
}

You might also like