有三个按键,首先按k0键,产生中断;如果再有k1键按下,十位加1,如果大于等于10,为0;如果再有k2键按下,个位加1,大于等于10,为0。在1602上显示,现在的问题是按按键没反应,求问题出在哪里了??
#include<reg51.h>
#define LCD_DB P1
#define uchar unsigned char
#define uint unsigned int
uchar aa[2];
uchar hh=0,ll=0;
uchar ah,al;
sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^2;
sbit k0=P3^2;
sbit k1=P2^4;
sbit k2=P2^5;
void LCD_init(void);//LCD初始化函数
void LCD_write_command(unsigned char command);
void LCD_write_data(uchar dat);
void LCD_disp(uchar x,uchar y,uchar *p,uchar count);
void delay_n40us(uint n);
void LCD_init(void)
{
LCD_write_command(0x38);
LCD_write_command(0x0c);
LCD_write_command(0x06);
LCD_write_command(0x01);
delay_n40us(100);
}
void LCD_write_command(uchar command)
{
LCD_DB=command;
LCD_RS=0;
LCD_RW=0;
LCD_E=1;
LCD_E=0;
delay_n40us(1);
}
void LCD_write_data(uchar dat)
{
LCD_DB=dat;
LCD_RS=1;
LCD_RW=0;
LCD_E=1;
LCD_E=0;
delay_n40us(1);
}
void LCD_disp(uchar x,uchar y,uchar *p,uchar count)
{
uchar i;
for(i=0;i<count;i++)
{
if(y==1)
x|=0x80;
else
x|=0xc0;
LCD_write_command(x);
LCD_write_data(*p);
x++;
p++;
}
}
void delay_n40us(uint n)
{
uint i;
uchar j;
for(i=n;i>0;i--)
{
for(j=0;j<2;j++);
}
}
void delayms(uint m)
{
uchar i,j;
for(i=0;i<m;i++)
{
for(j=0;j<140;j++);
}
}
void key() interrupt 0 using 0
{
EA=0;
if(k1==0)
{
delayms(10);
if(k1==0)
{
hh++;
while(!k1);
if(hh>=10)
{
hh=0;
}
ah=0x30+hh;
aa[0]=ah;
}
}
if(k2==0)
{
delayms(10);
if(k2==0)
{
ll++;
while(!k2);
if(ll>=10)
{
ll=0;
}
al=0x30+ll;
aa[1]=al;
}
}
EA=1;
}
void main()
{
P3=0x0f;
k1=1;
k2=1;
EX0=1;
IT0=0;
EA=1;
LCD_init();
LCD_disp(0,0," set temp",9);
LCD_disp(0,1,"true temp",9);
LCD_disp(10,0,"25",2);
while(1)
{
uchar i;
for(i=0;i<2;i++)
{
LCD_write_command(i|0xc9);
LCD_write_data(aa);
}
}
}
|