/* Main.c file generated by New Project wizard
*
* Created: 周二 五月 23 2017
* Processor: AT89C51
* Compiler: Keil for 8051
*/
#include
#include
#define uchar unsigned char
uchar duan[4] = {0xc0,0xf9,0x54,0x40};*/
sbit rs = P3^0;
sbit rw = P3^1;
sbit e = P3^2;
sbit start = P3^3;
sbit eoc = P3^4;
sbit oe = P3^5;
sbit ale = P3^6;
void writecmd(uchar cmd)
{
uchar i;
rs = 0;
rw = 0;
e = 1;
for(i = 0;i<5;i++);
P1 = cmd;
for(i = 0;i<5;i++);
e = 0;
}
void writeDA(uchar DA)
{
uchar j;
rs = 1;
rw = 0;
e = 1;
for(j = 0;j<5;j++);
P1 = DA;
for(j = 0;j<5;j++);
e = 0;
}
void inti()
{
rw = 0;
e = 0;
writecmd(0x38);
writecmd(0x0c);
writecmd(0x06);
writecmd(0x01);
}
void main(void)
{
uchar k;
uchar uu=0;
inti();
while(1)
{
start = 0;
start = 1;
start = 0;
while(eoc == 0);
oe = 1;
for(k = 0;k<20;k++);
uu = P2;//获取P2口的数据,数据由IN0口的电压值决定
oe = 0;
writecmd(0x80);
writeDA('0'+uu/100);
writeDA('0'+(uu/10)%10);
writeDA('0'+uu/10);
}
}