LED Blink is very basic programme to start programming with any microcontroller. To learn embedded system first start programming with 8051. 8051 is 8-bit microcontroller having 4 8-bit IO - Ports.there are two timer timer0 and timer1 ,two external interrupt interrupt0 and interrupt1 and three internal interrupt, one UART,counter.
In this tutorial you'll learn how to interface LED with 8051 microcontroller ATMEL (AT89S52)(89C51,89C52) NXP(89V51RD2).
LED interfacing circuit diagram
Show in above circuit diagram LED is connected with P2.0 of PORT2 through current limiting resistor R2. Anode of LED is connected with P2.0 through resistor R2 and cathode of LED is directly connected with ground of power supply.When P2.0 high LED turn on and when P2.0 low LED turn off.Now its time to do some coding.
Embedded C Code:
Show in above circuit diagram LED is connected with P2.0 of PORT2 through current limiting resistor R2. Anode of LED is connected with P2.0 through resistor R2 and cathode of LED is directly connected with ground of power supply.When P2.0 high LED turn on and when P2.0 low LED turn off.Now its time to do some coding.
Embedded C Code:
#include<reg51.h>
void delay_ms(unsigned int ms); //delay function to generate delay of ms second
sbit LED = P2^0;//LED is connected with
void main()
{
while(1) //Infinity loop
{
LED = 1; //Turn on LED
delay_ms(1000);//delay for ~1 sec = 1000ms
LED = 0;//Turn off LED
delay_ms(1000);//delay for ~1 sec = 1000ms
}
}
void delay_ms(unsigned int ms)//Delay function generates delay of ms milliseconds
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<127;j++);
}
sbit it is use to access individual bit within the SFR. Show in code in which LED is connected to pin 0 of PORT2. In main function LED is toggled with some random delay . The delay_ms function generates delay of ms milliseconds. Here while(1) is infinite loop which never end program and continuously blink LED at ~1 sec delay.
No comments:
Post a Comment