LED Lighting / Control LED / Interfacing two LED / LED blinking
/ Toggle two LED by 8051 and keil
In this topic I shall discuss about the code to control two
LED in 8051 and keil. Now I will show you how to interface LED with AT89c51. The
code is like that….
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//LED blinking//
#include <REG52.H>
sbit LED1=P1^0;
sbit LED2=P1^2;
void delay_ms(int milisec)
{
int i,j,k;
for(j=0;j<milisec;j++);
{
for(k=0;k<20;k++)
for(i=0;i<4898;i++);
}
}
void main(void)
{
P1=0x00; //Set P1 port in O/P mode
while(1)
{
LED1=1;
LED2=0;
delay_ms(500); //delay of 500 ms
LED1=0;
LED2=1;
delay_ms(500);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Here I have used Atmel AT89c51 microcontroller, but you can
use this code for any AT89xxx family.
The circuit is given below/…..
In this circuit the value of crystal is 12
If you cannot understand the above code you can see
this…………….
No comments:
Post a Comment