Tuesday 5 March 2013

program to access a switch .if switch is pressed to increment the count in 8051


/*program to access a switch .if switch is pressed to increment the count */

#include<reg51.h>
#include"lcd.c"
sbit sw1=P3^2;
#define led P1;

char flag;
char count;
void uart_init(void);
void uart_tr(char);
void uart_init()
{
 SCON=0x50;
 TMOD=0x20;
 TH1=253;
 TR1=1;
 }
void uart_str(char *str)
{
 while(*str)
 {
  uart_tr(*str++);
 }
}

 void isr(void) interrupt 0
 {

 if(sw1==0)
                flag=1;
}


void uart_tr(char s)
{
 SBUF=s;
 while(TI==0);
 TI=0;
}

void main()
{

 EA=EX0=IT0=1;
 EX1=IT1=1;
 uart_init();
 init_lcd();
 uart_str("start count\n");


 while(1)
 {
 
  
                 if(flag==1)
                  {
                                flag=0;
                   count+=1;
                   //count1+=1;
                  }
                if(count>=0)
                {
                  P1=count;
                  uart_tr(count+0x30);
                cmd_lcd(0x01);
                puts_lcd(" count:=");
                puti_lcd(count);
                delay_ms(100);
                }
 }//while

}

No comments:

Post a Comment