用51单片机仿真计数器,用c语言写程序,LCD1602显示,具体要求:按键按下开始计时,按键再次按
1个回答
展开全部
#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;
}
}
}
///如有问题,可再咨询
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询