To develop skills to code and interface key and LED to microcontrollers in embedded systems. Visit Website

To develop skills to code and interface key and LED to microcontrollers in embedded systems.

 


Exp 09:  Aim: To develop skills to code and interface key and LED to microcontrollers in embedded systems.

Flowchart: 



Algorithm: 

  1. Initialize port pin P0.0 as input.
  2. Initialize port pin P2.0 as output.
  3. Read the status of key.
  4. If key is closed then turn ON the LED.
  5. Add some delay
  6. Turn OFF the LED.
  7. Repeat from step3.

Diagram:

 


 

Program:

Step 3: ‘C’ Language Program

 

#include<reg51.h>

 

sbit LED_pin=P2^0;

sbit KEY_pin=P0^0;

 

void delay_ms(unsigned int);

 

void main (void)

 {

 KEY_pin=1;

 LED_pin=0;

 LED_pin=1;

 

while(1)

 {

   if(KEY_pin == 0 )

    {

     LED_pin = 0;

     delay_ms(200);

     LED_pin = 1;   

    }

  }

}

void delay_ms(unsigned int k)

 {

  unsigned int i, j;

  for(i=0;i<k;i++)

  {

    for(j=0;j<1275;j++);

  }

 }

Comments

 

/* Special function register declarations */

/* for the intended 8051 derivative */

//Define LED PIN

//Define key PIN

 

//Function prototype declaration

 

 

 

//Make key pin input

//Make LED pin output

//Make LED off initially

 

 

//Iinfinite loop

 

//If key pressed

 

//LED ON

//Delay

//LED OFF

 

 

 

 

//Delay function

 

 

Conclusion: We learnt how to code for the interfacing of key and LED to the microcontroller in the embedded system.

 





Post a Comment

Visit Website
Visit Website