Thursday, 29 December 2016

Keil program for glowing led when switch is on

Hello friends, today we will be giving you details on how to glow led bulb when switch is turned on.

The following steps will be followed after opening keil software:

1.project ->  μ vision project(mew vision),  create new project dialogue box appears and choose a      name to represent the program in the keil`
2.Now choose the microcontroller as "ATMEL",now choose the database as at89c51.
3.Now file -> new and start typing the following code.


CODE:

#include<reg51.h>
sbit SW=P1^5;
sbit LED=P2^5;
void main()
{
if(SW==0)
{
LED=1;
}
else
{
LED=0;
}
}

Explanation of the code:
i) #include<reg51.h> is a special header file to use keywords for 8051 microcontroller.
ii) sbit SW=P1^5 , in this statement a pin for switch is initialized which is connected to 5th pin in port 1.
iii) sbit LED=P2^5, in this statement a pin for LED is initialized which is connected to the 5th pin in port 2.
iv) The program is written in the main function where the logic is: if the switch is on,led is on and if the switch is off,led is off.


4.Save the file using .c(for eg:- group.c)
5.Source file -> add files to group source (right click) 
6. After adding the group source ,click target ->built target( it is used to create a complete project)
7 Target file(right click) -> options for target -> click output -> create hex file and then press ok to create the HEX file.
8.Now minimize the keil software and open  proteus to implement your project.



No comments:

Post a Comment