/*program to access 2 switch .if switch1 is pressed to
increment the count. if switch2 is pressed
to decrementing the count */
#include<reg51.h>
#include"lcd.c"
sbit sw1=P3^2;
sbit sw2=P3^3;
#define led P1;
char flag1,flag2;
char count,count1;
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)
flag1=1;
}
void isr1(void) interrupt 2
{
if(sw2==0)
flag2=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\n");
while(1)
{
if(flag1==1)
{
flag1=0;
count+=1;
count1+=1;
}
if(flag2==1)
{
flag2=0;
count-=1;
count1+=1;
}
if(count1>=100)
break;
if(count>=0)
{
P1=count;
uart_tr(count+0x30);
cmd_lcd(0x01);
puts_lcd("
count:=");
puti_lcd(count);
delay_ms(100);
}
else
{ cmd_lcd(0x01);
puts_lcd(" LIST IS EMPTY ");
}
}//while
}
No comments:
Post a Comment