8051 embedded c program

8051 embedded c program

 

Write a program for make led ON when  if switch is pressed, make it OFF when the switch is released (use push button ).

 

#include<reg51.h>

sbit c=P1^1;                   // assigning port p1 pin 1 for use switch

void main()

{

P1=0x0ff;                      // making p1 port is input

 P2=0x00;                       // making p2 port is output

  P1=0x00;                     // initially make it port 1 is OFF condition           

while(1)                            // infinite loop

{

 if(c==1)                         // when the input is HIGH (switch is pressed)

  {

P2=0x0ff;                       // p2 will go to high(led ON)

  }

 else

  {

   P2=0x00;         // p2 will go to low(led OFF)

  }

 }

 

Explanation:

 

Here we are going to make a lid on and off when the button is pressed. IN 8051 is having a 4 port, generally the 4 port inbuiled  GPIO pins. This pins are using as an either input or output pin. We assign the port pin as an input pin for the switch. In main function, we should assign which is the input and output port. Here we are using the port 1 for input and the port 2 is for output. Then made one while loop for continuous checking. When the input goes to high the LED will ON otherwise it will be OFF.

 

Leave a comment

We are the best Embedded Training Institutes in Bangalore with 100% job placement record. Our top most priority is to put more and more focus on practical aspects of the Training. We believe if the student is good with practical knowledge he can crack any interview he/she wants. We also promote the meritorious students and those who are in need but can't afford the expensive training in the other institutes are also welcomed at Professional Institute.

It is needless to say that there are many institute which provides Embedded Training in Bangalore but most of them focus on the quantity of the course but we focus majorly on the quality of the education. The reason is very simple, those institute have profit as their main motive but we are mostly concerned with the future of the students. That's why we charge very minimal fees from students.

PTInstitute © 2017 All rights reserved.