Showing posts with label LED interfacing in 8051 microcontroller. Show all posts
Showing posts with label LED interfacing in 8051 microcontroller. Show all posts

Wednesday, April 30, 2014

LED flashing simulation in multisim

In real world Applications LED's play important role. They are mainly used as indicators. In embedded industry they are used to indicate the events. Embedded world mainly depends on the two things. One is embeddable processor and the software top run it. Every processor or micro controller needs little bit of power to operate and some circuit connections to make it useful.
In this post I will explain how we can use 8051 micro controller to control the behavior of LED. The simulation is done in multisim.
lf

We need to apply proper voltages to the controller so that it can operate. It needs one power source and sink. Any normal battery can be used as the power supply and the negative terminal of the same battery can be used as ground. Just connect the LED to the any port pin of the controller. But avoid to use port1 because for that port we need to supply external pull up resistors. Remaining all ports has inbuilt pull up resistors.
Now coming to the actual intention of the post we need to toggle the LED. For some time it will be on after that it is off for the same amount of time. It can be achieved by altering the output of the port pin. The software written in assembly or embedded C. The code snippet as fallows:
#include <reg52.h>
sbit pin = P1^5;
bit state;
void init(void);
void changeState(void);
void Wait(const unsigned int);
void main()
{
init();
while(1)
{
changeState();
Wait();
}
}
void init()
{
state = 0;
}
void changeState()
{
if (state == 1)
{
state = 0;
pin = 0;
}
else
{
state = 1;
pin = 1;
}
}
void Wait()
{
unsigned y;
{
for (y = 0; y <= 100; y++);
}
}
Before loading this code in the micro controller we need to convert this code into .hex file to dump in controller. We can use keil for the same. We need to include the header regx52.h it has all the ports and functions defined in it. Pin 5 is configured to operate and to control the LED.
Program has three functions. First one initializes the led state to zero. And the wait function creates the delay for some period of time. For that period LED remains in on/off state only. Change state function changes the global variable value so that in the next call to the wait function the status of the LED changes. As use val we have on main function to start and run the program.

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...