
In this way, LED attached to P1.0 pin is made to blink using the code given below.
The ‘delay’ function executes null statements every time when it executes.Ī value of 60000 (compiled using Keil micro-vision4 software) generates about 1 seconds (delay time) null statement execution time when 11.0592 MHz crystal is being used. In the main function, LED is toggled after every half second. In the code below, the LED is defined as the pin 0 of the port 1. As we know that 8051 Microcontroller executes an instruction in 12 CPU cycles, hence this 11.0592Mhz crystal makes this 8051 run at 0.92 MIPS (Million of instructions per second). A crystal of 11.0592 MHz is connected for generating the clock. Furthermore, refer this link “ Embedded C Programming Tutorial with Keil Language”. I will explain the program code in detail. An LED is connected to the pin-0 of port-1.
Interface 2 will glow LED, only if the PIN value of the MC is LOW as current flows towards PIN due to its lower potential. Interface 1 will glow LED, only if the PIN value of the MC is HIGH as current flows towards the ground. The resistor is important in LED interfacing to limit the flowing current and avoid damaging the LED and/or MCU. And vice versa with the interface 1 connections. Observe carefully the interface LED 2 is in forward biased because the input voltage of 5v connected to the positive terminal of the LED, So here the Microcontroller pin should be at LOW level. This article provides the information on LED interfacing with 8051 and LED blinking code for AT89C52/ AT89C51 Microcontroller. But the connections and programming techniques will be different. There are two ways which we can interface LED to the Microcontroller 8051. Another way to recognize the polarity is, connecting leads, POSITIVE terminal has more length than NEGATIVE terminal. The larger end inside the led is -ve (cathode) and the shorter one is +ve (anode), that is how we find out the polarity of the LED. The only way to know polarity is either to test it with a multimeter or by carefully observing inside the LED.