#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit k1=P3^0;
sbit k3=P3^2;
sbit k4=P3^3;
sbit LCD_RS = P2^6;
sbit LCD_RW = P2^5;
sbit LCD_EN = P2^7;
sbit maibo = P3^1;
sbit Buzz = P1^5;
uchar code dis1[] = {" Welcome!!! "};
uchar code dis2[] = {"Maibo Ceshi"};
uchar code dis3[] = {" Start Tes
ting? "};
uchar code dis4[] = {" (1)Yes (2)No "};
uchar code dis5[] = {"Please Wait!!"};
uchar code dis6[] = {"xintiao: "};
uchar code disk7[]={"maibo normal"};
uchar code disk8[]={"maibo abnormal"};
uchar test_jieguo[16] = {" "};
uint xintiao;
uint time;
uchar tt;
void delay(uint z)
{
uchar x,y;
for(x=0;x<z;x++)
for(y=0;y<110;y++);
}
bit LCD_busy()
{
uint jg;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
delay(10);
jg=(uint)(P0&0x80);
LCD_EN = 0;
return jg;
}
void write_mingling(uchar cmd)
{
while(LCD_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
delay(10);
P0=cmd;
delay(10);
LCD_EN = 1;
delay(10);
LCD_EN = 0;
delay(100);
}
void write_data(uchar dat)
{
while(LCD_busy());
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
delay(10);
P0=dat;
delay(10);
LCD_EN = 1;
delay(10);
LCD_EN = 0;
delay(100);
}
void LCD_init()
{
write_mingling(0x38);
write_mingling(0x38);
write_mingling(0x0c);
write_mingling(0x0c);
write_mingling(0x06);
write_mingling(0x01);
write_mingling(0x80);
}
void LCD_dingwei(uint hang,uint lie)
{
uchar wei;
wei=0x80|(uchar)(0x40*(hang-1)+(lie-1));
write_mingling(wei);
}
void LCD_xianshi(uchar dis[])
{
uchar i,arra;
for(i=0;i<16;i++)
{
arra=dis[i];
if(arra==' ')
break;
else
write_data(arra);
}
}
void Jmian_init()
{
maibo=1;
EA = 1;
TMOD=0X01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
ET0 = 1;
TR0 = 0; PT0 = 1;
/* TMOD=0x07; // 使用计数器T0的模式3
ET1=1;
TR1=0;
TH0=0;
TL0=0;
*/
LCD_init();
time=0;
xintiao=0;
LCD_dingwei(1,2);
LCD_xianshi(dis1);
LCD_dingwei(2,2);
LCD_xianshi(dis2);
}
void LCD_data()
{
test_jieguo[0]='0'+(uint)(time/10);
test_jieguo[1]='0'+(uint)(time%10);
test_jieguo[7]='0'+(uint)(xintiao/100);
test_jieguo[8]='0'+(uint)((xintiao%100)/10);
test_jieguo[9]='0'+(uint)(xintiao%10);
LCD_dingwei(2,3);
LCD_xianshi(test_jieguo);
}
void xintiao_compare()
{
uchar warning=0;
if(k1==0)
delay(5);
if(k1==0)
{ delay(5);
while(k1);
LCD_dingwei(1,2);
LCD_xianshi(dis6);
if(xintiao>=60 && xintiao<=90)
{
LCD_dingwei(1,2);
LCD_xianshi(disk7);
}
else
{
LCD_dingwei(2,2);
LCD_xianshi(disk8);
warning=1;
}
}
if(warning)
{
Buzz=0;
delay(1000);
Buzz=1;
delay(100);
Buzz=0;
delay(1000);
Buzz=1;
}
else
delay(3000);
}
void main()
{
uint m,tt;
m=1;
tt=0;
Jmian_init();
if(!k1)
delay(5);
if(!k1)
{ delay(5);
while(k1);
write_mingling(0x01);
LCD_dingwei(1,2);
LCD_xianshi(dis3);
LCD_dingwei(2,1);
LCD_xianshi(dis4);
while(m)
{
if(!k3)
delay(5);
if(!k3)
{
delay(5);
while(k3);
write_mingling(0x01);
LCD_dingwei(2,2);
LCD_xianshi(dis5);
TR0=1;
LCD_data();
break;
}
if(!k4)
delay(5);
if(!k4)
{
delay(5);
while(k4);
write_mingling(0x01);
LCD_dingwei(1,2);
LCD_xianshi(dis2);
break;
}
m=0;
}
}
while(1)
{
if(TF0==1)
{
TF0=0;
tt++;
if(tt==20)
{
tt=0;
time++;//时间加1秒
LCD_data();
}
if(maibo==0)
{
delay(5);
while(~maibo);
if(TR0==0)
TR0=1; //启动定时器0
xintiao++;
}
if(time==60)
{
EX0=0; //禁止中断
TR0=0;
write_mingling(0x01);
LCD_dingwei(1,3);
LCD_xianshi(dis6);
LCD_data();
xintiao_compare();
delay(3000);
}
}
}
}
void exter0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
tt++;
}
一周热门 更多>