那位大佬可以帮我看看
单片机源程序如下:
#include <reg52.h>
typedef unsigned int u16;
typedef unsigned char u8;
#define LCD1602_DATAPINS P0
sbit LCD1602_E=P2^7;
sbit LCD1602_RW=P2^5;
sbit LCD1602_RS=P2^6;
u16 j,z,s,count,zhuan;
u8 display[]="speed= r/s ";
void Lcd1602_Delay1ms(u16 c) //yan shi
{
u16 a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
}
void LcdWriteCom(u8 com) //xie yi ge ming ling
{
LCD1602_E = 0;
LCD1602_RS = 0;
LCD1602_RW = 0;
LCD1602_DATAPINS = com;
Lcd1602_Delay1ms(1);
LCD1602_E = 1;
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
}
void LcdWriteData(u16 dat) //xie ru yi ge shu jv
{
LCD1602_E = 0;
LCD1602_RS = 1;
LCD1602_RW = 0;
LCD1602_DATAPINS = dat;
Lcd1602_Delay1ms(1);
LCD1602_E = 1;
Lcd1602_Delay1ms(5);
LCD1602_E = 0;
}
void LcdInit() //LCD chu shi hua
{
LcdWriteCom(0x38);
LcdWriteCom(0x0c);
LcdWriteCom(0x06);
LcdWriteCom(0x01);
LcdWriteCom(0x80);
}
void displaytolcd()
{
LcdWriteCom(0x80); //?LCD1602xie shu jv
for (j=0;j<16;j++)
{
LcdWriteData(display[j]);
}
}
void Jshu0Init()
{
TMOD=0x05;
TH0=0xff;
TL0=0xff;
TR0=1;
ET0=1;
EA=1;
}
void Timer0Init()
{
TMOD|=0X01;
TH0=0XFC; //ding shi 1ms
TL0=0X18;
ET0=1;
EA=1;
TR0=1;
}
void disp_count()
{
LcdWriteCom(0x80); //?LCD1602xie shu jv
display[7]=(zhuan/1000+'0');
display[8]=(zhuan/100%10+'0');
display[9]=(zhuan/10%10+'0');
display[10]=(zhuan%10+'0');
}
void main()
{
LcdInit();
Jshu0Init();
Timer0Init();
disp_count();
displaytolcd();
while(1);
}
void Jshu0() interrupt 0
{
TH0=0xff;
TL0=0xff;
s++;
}
void Timer0() interrupt 1
{
static u16 i;
static u16 s;
TH0=0XFC; //1ms
TL0=0X18;
i++;
if(i==1000)
{
displaytolcd();
zhuan=s;
disp_count();
ET0=0;
i=0;
TH0=0XFC; //1ms
TL0=0X18;
s=0;
}
ET0=1;
}
|