#include<reg52.h>
#include <stdio.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcdrs=P2^0;
sbit lcdrw=P2^1;
sbit lcden=P2^2;
sbit ST=P2^4;
sbit EOC=P2^5;
sbit OE=P2^6;
sbit CLOCK=P2^7;
uchar a,b,c,d,VOL;
unsigned char code table1[]={"VOL:"};
void delay1ms()
{ unsigned int x,y; for(x=0;x<10;x++) for(y=33;y>0;y--); }
void delay(unsigned int z)
{ unsigned char x; for(x=z;x>0;x--) delay1ms();}
void write_com(unsigned char com)
{
lcdrs=0;
P3=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(unsigned char dat)
{
lcdrs=1;
P3=dat;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init(void)
{
lcden=0;
lcdrw=0;
write_com(0x01);
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x80);
}
void display(void)
{
unsigned int i=0;
write_com(0x80);
{
while(table1[i]!=' ')
{
write_data(table1[i]);
i++;
}
}
}
void readtemp()
{
OE=0;ST=0;ST=1;ST=0;
while(!EOC); OE=1;
a=P1; OE=0; delay(10);
VOL=a*500/255;
b=VOL/100;c=VOL/10%10;d=VOL%10;
write_com(0x85); write_data(b+48);write_data(0x2e);write_data(c+48);
write_data(d+48);
write_data('V');
}
void main()
{
init();
TMOD=0x01;
TH0=(65536-1)/256;
TL0=(65536-1)%256;
TR0=1;
ET0=1;
EA=1;
CLOCK=0;
display();
while(1)
{
readtemp();
}
}
void t0(void) interrupt 1 using 0
{
TH0=(65536-1)/256;
TL0=(65536-1)%256;
CLOCK=!CLOCK;
} 这个例子应该很简单,但是不知道哪里有差错,就是数值不对,哪位大神有空帮忙看看
-
一周热门 更多>