|
#include <reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit key=P3^4;
sbit key1=P3^5;
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P2^5;
sbit BEEP=P2^3;
unsigned char i,a,b,c,d,f,g,h,i;
unsigned char x,y,m,n,z;
float p,j;
int q,w,e,r,o;
void delayms(unsigned int xms)
{
unsigned i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void Read_Busy()
{
uchar busy;
P0 = 0xff;
RS = 0;
RW = 1;
do
{
EN = 1;
busy = P0;
EN = 0;
}while(busy & 0x80);
}
//?LCD1602??????
void Write_Cmd(uchar cmd)
{
Read_Busy();//???
RS = 0;
RW = 0;
P0 = cmd;
EN = 1;
EN = 0;
}
//???????
void Write_Dat(uchar dat)
{
Read_Busy();
RS = 1;
RW = 0;
P0 = dat;
EN = 1;
EN = 0;
}
void charter(unsigned char x,unsigned char y,unsigned char dat)
{
if(y==0)
{
Write_Cmd(0x80+x);
}
else
{
Write_Cmd(0xc0+x);
}
Write_Dat( dat);
}
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
Write_Cmd(0x80 + x);
}
else
{
Write_Cmd(0xC0 + x);
}
while (*s)
{
Write_Dat( *s);
s ++;
}
}
void lcdinit()
{
Write_Cmd(0x38);
Write_Cmd(0x08); /*????*/
Write_Cmd(0x01); /*????*/
Write_Cmd(0x06); /*????????*/
Write_Cmd(0x0C); /*????????*/
}
void Timer0Init(void) //50??@11.0592MHz
{
TMOD = 0x01; //???????
TH0=0xdc; //10ms??
TL0=0x00;
ET0=1;
EA=1;
TR0 = 0; //???0????
}
void beep()
{
unsigned char y;
for (y=0;y<180;y++)
{
BEEP=!BEEP; //BEEP??
delayms(70);
}
BEEP=1; //?????
}
void main()
{
unsigned char num,num1,u;
lcdinit();
Timer0Init();
LCD_Write_String(0,1,"time:");
LCD_Write_String(0,0,"speed:00:00cm/s");
LCD_Write_String(5,1,"00:00:00:00");
while(1)
{
if(key==0)
{
delayms(50);
if(key==0)
num=num+1;
while(!key);
}
switch(num)
{
case 1:TR0=1;
//LCD_Write_String(0,0,"begin count 1");
delayms(5);
break;
case 2:TR0=0;
//LCD_Write_String(0,0,"pause count 2");
delayms(5);
break;
case 3:TR0=1;
//LCD_Write_String(0,0,"begin count 3");
delayms(5);
break;
case 4:TR0=0;
//LCD_Write_String(0,0,"pause count 4");
delayms(5);
break;
}
if(key1==0)
{
LCD_Write_String(5,1,"00:00:00:00");
}
}
}
void timer() interrupt 1
{
TH0=0xdc;
TL0=0x00;
a++;
o=3546;
charter(15,1,'0'+a);
if(a==10)
{
a=0;
b++;
x=b%10;
charter(14,1,'0'+x);
}
if(b==10)
{
b=0;
c++;
y=c%10;
charter(12,1,'0'+y);
}
if(c==10)
{
c=0;
d++;
z=d%10;
charter(11,1,'0'+z);
}
if(d==6)
{
d=0;
charter(11,1,'0'+0);
e++;
m=e%10;
charter(9,1,'0'+m);
}
if(e==10)
{
e=0;
f++;
n=f%10;
charter(8,1,'0'+n);
}
p=a*0.01+b*0.1+c*1+d*10;
j=3/p;
o=j*100;
q=o/1000;
w=o%1000/100;
e=o%1000%100/10;
r=o%1000%100%10;
charter(6,0,'0'+q);
charter(7,0,'0'+w);
charter(9,0,'0'+e);
charter(10,0,'0'+r);
}
|
|