#include<reg52.h>
#include<intrins.h>
#define uint unsgined int
#define uchar unsigned char
sbit beep=P2^3;
sbit dula=P2^6;
sbit wela=P2^7;
sbit s1=P3^6;
sbit s2=P3^7;
sbit lcdrs=P3^5;
sbit lcden=P3^4;
uchar code dis1[]={" STOPWATCH 0 "};
uchar code dis2[]={" HU SI JIAN "};
uchar code dis3[]={"
tiME "};
uchar code dis4[]={" BEGIN COUNT 1 "};
uchar code dis5[]={" PAUSE COUNT 2 "};
uchar code dis6[]={" BEGIN COUNT 3 "};
uchar code dis7[]={" PAUSE COUNT 4 "};
uchar display[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar display1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uchar count;
void delay1()
{_nop_();_nop_();_nop_();}
void delay(uint z)
{
uint x;
while(z--)
for(x=110;x>0;x--);
}
void di()
{
beep=0;
delay(200);
beep=1;
}
/*************************************
* *
* 1602显示屏函数 *
* *
*************************************/
void write_com(uchar com)
{
lcden=0;
lcdrs=0;
P0=com;
delay1();
lcden=1;
delay1();
lcden=0;
}
void write_date(uchar date)
{
lcden=0;
lcdrs=1;
P0=date;
delay1();
lcden=1;
delay1();
lcden=0;
}
void lcd_pos(uchar pos)
{
write_com(pos|0x80); //位置指针=0x80+地址变量
}
/*************************************
* *
* 显示函数部分 *
* *
*************************************/
void play()
{
uchar i;
for(i=0;i<6;i++)
{
display1
=display+0x30;
}
display1[7]=display[6]/10+0x30;
display1[6]=display[6]%10+0x30;
lcd_pos(0x45);
write_date(display1[7]);
write_date(display1[6]);
write_date(0x3a);
write_date(display1[5]);
write_date(display1[4]);
write_date(0x3a);
write_date(display1[3]);
write_date(display1[2]);
write_date(0x3a);
write_date(display1[1]);
write_date(display1[0]);
}
/*************************************
* *
* 初始化函数部分 *
* *
*************************************/
void init()
{
wela=0;
dula=0;
lcden=0;
TMOD=0X01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
write_com(0x01);
write_com(0x38);
write_com(0x0c);
write_com(0x06);
}
/*************************************
* *
* 主函数函数部分 *
* *
*************************************/
void main()
{
uchar num;
init();
for(num=0;num<16;num++)
{
write_date(dis1[num]);
delay(10);
}
lcd_pos(0x40);
for(num=0;num<16;num++)
{
write_date(dis2[num]);
delay(10);
}
delay(2000);
lcd_pos(0x40);
for(num=0;num<16;num++)
{
write_date(dis3[num]);
delay(10);
}
delay(20);
while(1)
{
if(s1==0)
{
delay(5);
if(s1==0)
{
count++;
}
while(!s1);
di();
}
if(s2==0)
{
delay(5);
if(s2==0)
{
count=0;
TR0=0;
for(num=0;num<6;num++)
{
display[num]=0x00;
}
lcd_pos(0x00);
for(num=0;num<16;num++)
{
write_date(dis1[num]);
}
}
while(!s2);
di();
}
switch(count)
{
case 1:
TR0=1;
lcd_pos(0x00);
for(num=0;num<16;num++)
{
write_date(dis4[num]);
}
break;
case 2:
TR0=0;
lcd_pos(0x00);
for(num=0;num<16;num++)
{
write_date(dis5[num]);
}
break;
case 3:
TR0=1;
lcd_pos(0x00);
for(num=0;num<16;num++)
{
write_date(dis6[num]);
}
break;
case 4:
TR0=0;
lcd_pos(0x00);
for(num=0;num<16;num++)
{
write_date(dis7[num]);
}
break;
default:
TR0=0;
break;
}
play();
}
}
/*************************************
* *
* 定时器中断函数部分 *
* *
*************************************/
void time0() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
display[0]++;
if(display[0]==10)
{
display[0]=0;
display[1]++;
}
if(display[1]==10)
{
display[1]=0;
display[2]++; //秒个位
}
if(display[2]==10)
{
display[2]=0;
display[3]++; //秒十位
}
if(display[3]==6)
{
display[3]=0;
display[4]++; //分个位
}
if(display[4]==10)
{
display[4]=0;
display[5]++; //分十位
}
if(display[5]==6)
{
display[5]=0;
display[6]++; //时
}
if(display[6]==24)
display[6]=0;
}
一周热门 更多>