This article introduces you to the very basic operation of taking an output from the microcontroller AT89C51. It demonstrates the principle behind interfacing LEDs with 8051 microcontroller. Here we have demonstrated the aforesaid principles by blinking LEDs continuously i.e., switching them on and off.
AT89C51, which belongs to the family of 8051 series of microcontrollers, is very commonly used by a large community of hobbyist and engineers. Its simplicity and ease of programming with inbuilt features easily makes its position in the top preferred list of microcontroller for both beginners and advanced user.
LEDs are by far the most widely used means of taking output. They find huge application as indicators during experimentations to check the validity of results at different stages. They are very cheap and easily available in a variety of shape, size and colors.
The principle of operation of LEDs is simple. The commonly available LEDs have a drop voltage of 1.7 V and need 10 mA to glow at full intensity. The following circuit describes “how to glow an led”.
Fig. 2: Circguit Diagram to Glow LED
The value of resistance R can be calculated using the equation, R= (V-1.7)/10 mA. Since most of the controllers work on 5V, so substituting V= 5V, the value of resistance comes out to be 330 ohm. The resistance 220 ohm, 470 ohm is commonly used substitute in case 330 ohm is not available.
AT89C51 is a 40 pin microcontroller which belongs to 8051 series of microcontroller. It has four ports each of 8 bits P0, P1, P2 and P3.The AT89C51 has 4K bytes of programmable flash. The port P0 covers the pin 32 to pin 39, the port P1 covers the pin 1 to pin 8, the port P2 covers the pin 21 to pin 28 and the port P3 covers the pin 10 to pin 17. Pin 9 is the reset pin. The reset is active high. Whenever the controller is given supply, the reset pin must be given a high signal to reset the controller and bring the program counter to the starting address 0x0000. The controller can be reset by manually connecting a switch or by connecting a combination of resistor and capacitor as shown in the circuit diagram. A 12 MHz crystal is connected between pin 18 pin 19. Pin 40 is Vcc and pin 20 is ground. Pin 31, is connected to Vcc as we are using the internal memory of the controller.
LEDs are connected to the port P0. LEDs need approximately 10mA current to flow through them in order to glow at maximum intensity. However the output of the controller is not sufficient enough to drive the LEDs, so if the positive leg of the LED is connected to the pin and the negative to ground as shown in the figure, the LED will not glow at full illumination.
Fig. 3: Circuit Diagram of LED connected with AT89C51
To overcome this problem LEDs are connected in the reverse order and they run on negative logic i.e., whenever 1 is given on any pin of the port, the LED will switch off and when logic 0 is provided the LED will glow at full intensity.
As soon as we provide supply to the controller, the LEDs start blinking i.e., they become on for a certain time duration and then become off for the same time duration. This delay is provided by calling the delay function. The values inside the delay function have been set to provide a delay in multiples of millisecond (delay (100) will provide a delay of 100 millisecond).
Project Source Code
###
// Program to blink the LEDs. LEDs are connected to port 0. #include<reg51.h> void delay(int time) //This function produces a delay in msec. { int i,j; for(i=0;i<time;i++) for(j=0;j<1275;j++); } void main() { while(1) { P0=0x00; delay(50); P0=0xff; delay(50); } }###
Circuit Diagrams
Project Components
Project Video
Filed Under: 8051 Microcontroller
Filed Under: 8051 Microcontroller
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.