Friday, 22 July 2011

Chasing LED's Using Microcontroller 89C52/89S52

This mini-project is especially meant for a newbie in Embedded Systems. This project will give you a clear idea of how to think and implement your code in practical life. In this article, we will cover the programming details for LED blinking and how you can code your microcontroller to show different patterns of LED blinking. After learning the logic for LED blinking you can code any microcontroller with the same logic.


  • 1 microcontroller 89C52(89S52 will also do)
  • 1 potentiometer-10k
  • 2 ceramic capacitors-22pF
  • 1 switch(button for reset purpose)
  • 1 electrolytic capacitor-10uF,25V
  • 1 crystal oscillator-11.0592MHz
  • 1 resistor-10k
  • 8 LED's
  • 8 330 ohm resistor
  • 2 switches (SPST) 

 Schematic Diagram


Softwares Used: 

This project is made with the help of Proteus software. If you are unaware of the software you can learn the basics by watching the video tutorial that I recommended in one of my articles.

The connection of the circuit is explained below:

  • Port 1 of the microcontroller is used as the input Port
  • Port 2 of the microcontroller is used as the output Port
  • The LED's are connected to the output of Port 2
  • Two switches are connected to the input of Port 1
    one switch is connected to the 5th pin of the Port 1 whereas the other switch is connected to the 8th pin of the Port 1
  • Other components like the crystal and switch are used for the working of the microcontroller


The programming is done using Keil compiler. The circuit is configured for two modes namely (1) The LED Blinking mode and the (2) Chasing LEd mode.when the switch connected to the 8th pin of the Port 1 is closed , the microcontroller works in the Blinking mode wherein all the LED's glow simultaneously for one second and remain switched off for the other one second and this process continues as long as the microcontroller is receiving the power supply .The blinking LED's are shown below:


When the switch connected to the 5th pin of the micro controller is closed and the switch connected to the 8th pin is open, the micro controller works in the Chasing LED mode i.e. the LED's glow one after the another for a second and looks something like this:


The detail explanation of the coding is done below

#include <REGX52.H>
# include"delay.h" /* header file of the delay is added */
void main()
{ P1=0xFF; /*Port 1 is defined as input*/
P2=0x00; /* Port 2 is defined as output*/
{/* code for the chasing LED's */
if(P1_4==0)/* if switch connected to P1_4 is closed*/
{ P2=0X01; /*glow the LED connected to P2_0 for 1 sec*/
P2=0x02; /*glow the LED connected to P2_1 for 1 sec*/
delay_sec(1);/* code for chasing LED's complete*/
}/* codes for chasing LED's */
if(P1_7==0) /* if switch connected to P1_7 is closed*/
{ P2=0xFF; /*glow all the LED's connected to port P2 for 1 sec*/
P2=0x00; /*switch off all the LED's connected to port P2 for 1 sec*/

Some things that you can try      

You can play around with the code to get your own LED pattern. Try using P2=0xAA, then provide a delay of 1 second and put the value of P2 as P2=0X55 and again provide a delay of 1 second. Similarly you can try other patterns and have fun. This way you will be able to develop your skill in programming.

Download files     

Please comment if you further want to improve the project or if you have doubts in the above code.


VaibhavSingh said...

it's very helpfull thanx..add some other programming related to ic 89c52

RITUBallav H. said...

will the programming be different if we use a AT89C51 microcontroller

Post a Comment