#include<reg52.h>
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_E_ = P2^2;
sbit KEY1 = P2^3;
void Delay_ms(unsigned char time)
{
unsigned char i;
while(time--)
{
for(i=0;i<125;i++);
}
}
void LCD1602_WriteByte(unsigned char value,bit dataTypedef)
{
LCD_RS = dataTypedef;
LCD_RW = 0;
P0 = value;
LCD_E_ = 1;
Delay_ms(5);
LCD_E_ = 0;
}
void LCD1602_Init()
{
LCD1602_WriteByte(0x38,0);
Delay_ms(10);
LCD1602_WriteByte(0x01,0);
Delay_ms(10);
LCD1602_WriteByte(0x06,0);
Delay_ms(10);
LCD1602_WriteByte(0x0c,0);
Delay_ms(10);
}
bit Pause;
void KEY_Testing()
{
static bit sw;
static unsigned char qd;
KEY1 = 1;
if(!KEY1)
{
if(!sw)qd++;
if(qd>10)
{
qd = 0;
sw = 1;
if(!KEY1)Pause=~Pause;
}
}
else
sw = qd = 0;
}
unsigned char CountNumber;
void main()
{
LCD1602_Init();
TMOD = 0x01;
TR0 = 1;
ET0 = 1;
EA = 1;
while(1)
{
LCD1602_WriteByte(0x85,0);
LCD1602_WriteByte((CountNumber/100)+48,1);
LCD1602_WriteByte((CountNumber/10%10)+48,1);
LCD1602_WriteByte((CountNumber%10)+48,1);
}
}
void Timer0_Routine()interrupt 1
{
static unsigned int count;
TH0 = 0xfc;//12MHZ
TL0 = 0x18;
KEY_Testing();
if(!Pause)
{
count++;
if(count>=1000)
{
count=0;
}
}
}
///å¦æé®é¢ï¼å¯åå¨è¯¢
温馨提示:内容为网友见解,仅供参考