用protues建立如上的
仿真模型,程序如下,按下K1一直没效果,请高手指教下
#include<reg51.h>
#include<lcd.h>
sbit K1=P1^0;
unsigned char count =0;
//--定义全局变量--//
unsigned char PuZh[]="Press K1";
unsigned char Buffer1[]="--------hz";
//延时函数
void Delay(unsigned char ms)
{
unsigned char i;
while (ms--) for (i=0;i<120;i++);
}
//T0中断子程序
void INT_T0() interrupt 1
{
unsigned int Tmp,i ;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if (++count==20)
{
LcdInit();
TR1=TR0=0;
count=0;
Tmp=TH1*256+TL1;
Buffer1[0]=Tmp/10000+'0';
Buffer1[1]=Tmp/1000%10+'0';
Buffer1[2]=Tmp/100%10+'0';
Buffer1[3]=Tmp%100/10+'0';
Buffer1[4]=Tmp%10+'0';
TH1=TL1=0;
}
}
void main(void)
{
unsigned char i;
LcdInit();
for(i=0;i<8;i++)
{
LcdWriteData(PuZh
);
}
IE=0x8A; //允许 T0,T1中断
TMOD=0x51; //T1为16位计数器,T0为16位定时器
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
Delay(15);
while(1)
{
if (K1==0) //如果K1按下则启动定时器与计数器
{
Delay(10);
if (K1==0)
{
TR1=TR0=1;
}
}
LcdInit();
for(i=0;i<10;)
{
LcdWriteData(Buffer1);
i++;
}
}
}
一周热门 更多>