|
#include <reg52.h>
sbit e = P2^7;
sbit rs = P2^6;
sbit rw = P2^5;
sbit signal=P3^2;
sbit signall=P3^3;
#define uint unsigned int
#define uchar unsigned char
uchar code string1[16]={"Percent: %"};
uchar code string2[16]={"T: ms"};
uchar T[5];
uchar S[4];
void TIMER_init();
uchar flag = 1;
uint num1,num2;
void delay_ms(uchar t);
void write_com(uchar com);
void write_date(uchar dat);
void init_1602();
void INT_TIMER_init()
{
TMOD = 0X11;
EA = 1;
EX0 = 1;
EX1 = 1;
IT0 = 1;
IT1 = 1;
ET0=1;
ET1=1;
}
void delay_ms(uchar t)
{
uchar i = 110;
while(t--)
while(i--) continue;
}
void write_com(uchar com)
{
e = 0;
rs = 0;
rw = 0;
P0 = com;
delay_ms(1);
e = 1;
delay_ms(10);
e = 0;
}
void write_data(uchar dat)
{
e = 0;
rs = 1;
rw = 0;
P0 = dat;
delay_ms(1);
e = 1;
delay_ms(10);
e = 0;
}
void init_1602()
{
delay_ms(15);
write_com(0x38);
delay_ms(5);
write_com(0x38);
delay_ms(5);
write_com(0x38);
write_com(0x07);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
void main()
{
uchar i;
uint s;
init_1602();
INT_TIMER_init();
for(i=0;i<16;i++)
{
write_data(string1[i]);
}
write_com(0xc0);
for(i=0;i<16;i++)
{
write_data(string2[i]);
}
while(1)
{
T[0]='0'+num1%100000/10000;
T[1]='0'+num1%10000/1000;
T[2]='0'+num1%1000/100;
T[3]='0'+num1%100/10;
T[4]='0'+num1%10;
s = (uint)((num2*1.0/num1)*1000);
S[0] = '0'+s/100;
S[1] = '0'+s%10/10;
S[2] = '.';
S[3] = '0'+s%10;
for(i=0;i<4;i++)
{
if(S[i]=='0')
{
S[i]=' ';
}
else
{
break;
}
}
for(i=0;i<5;i++)
{
if(T[i]=='0')
{
T[i]=' ';
}
else
{
break;
}
}
write_com(0x8b);
for(i=0;i<6;i++)
{
write_data(S[i]);
}
write_com(0xc9);
for(i=0;i<5;i++)
{
write_data(T[i]);
}
}
}
void int0() interrupt 0
{
if(flag)
{
TR0=1;
TR1=1;
flag = 0;
}
else
{
TR0 = 0;
num1 = num1+TH0*256+TL0;
num2 = num2+TH1*256+TL1;
TH0 = 0;
TL0 = 0;
TH1 = 0;
TL1 = 0;
flag = 1;
}
}
void int1() interrupt 2
{
TR1 = 0;
}
void timer0() interrupt 1
{
num1=num1+65536;
}
void timer1() interrupt 3
{
num2=num2+65536;
}
|
-
1.png
(7.01 KB, 下载次数: 33)
|