#include "d:c51eg51.h"
#include "d:c51intrins.h"
sbit LCM_RS=P3^0;
sbit LCM_RW=P3^1;
sbit LCM_EN=P3^7;
#define BUSY 0x80 //常量定义
#define DATAPORT P1
#define uchar unsigned char
#define uint unsigned int
#define L50
uchar str0[16],str1[16],count;
uint speed;
unsignedlongtime;
void ddelay(uint);
void lcd_wait(void);
void display();
void initLCM();
void WriteCommandLCM(uchar WCLCM,uchar BusyC);
void STR();
void account();
/*********延时K*1ms,12.000mhz**********/
void int0_isr(void) interrupt 0 /*遥控使用外部中断0,接P3.2口*/
{
unsigned int temp;
time=count;
TR0=0;
temp=TH0;
temp=((temp << 8) | TL0);
TH0=0x3c;
TL0=0xaf;
count=0;
TR0=1;
time=time*50000+temp;
}
void time0_isr(void) interrupt 1 /*遥控使用定时计数器1 */
{
TH0 =0x3c;
TL0 =0xaf;
count++;
}
void main(void)
{
TMOD=0x01; /*TMOD T0选用方式1(16位定时) */
IP|=0x01; /*INT0 中断优先*/
TCON|=0x11; /*TCON EX0下降沿触发,启动T0*/
IE|=0x83;
TH0=0x3c;
TL0=0xaf;
initLCM();
WriteCommandLCM(0x01,1); //清显示屏
for(;;)
{
account();
display();
}
}
void account()
{
unsignedlonga;
if (time!=0)
{
a=L*360000000/time;
}
speed=a;
}
void STR()
{
str0[0]=S;
str0[1]=p;
str0[2]=e;
str0[3]=e;
str0[4]=d;
str0[5]= ;
str0[6]=(speed%100000)/10000+0x30;
str0[7]=(speed%10000)/1000+0x30;
str0[8]=(speed%1000)/100+0x30;
str0[9]=.;
str0[10]=(speed%100)/10+0x30;
str0[11]=speed%10+0x30;
str0[12]=k;
str0[13]=m;
str0[14]=/;
str0[15]=h;
}