#include"reg52.h"
#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit adwr=P3^6;
sbit adrd=P3^7;
sbit lcden=P3^0;
sbit lcdrs=P3^1;
int adval;
char num;
uchar code table[]="0123456789";
uchar code table1[]="A/D:";
void delay(int n) //延时函数
{
int i,j;a
for(i=0;i<=n;i++)
for(j=0;j<110;j++);
}
//**********************************写命令
void write_com(uchar com)
{
lcdrs=0;
P2=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
//**************************写数据
void write_data(uchar date)
{
lcdrs=1;
P2=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
//******************************显示函数
void display(adval)
{
char bai,shi,ge;
adval=adval*100/51;
bai=adval/100;
shi=adval%100/10;
ge=adval%10;
write_com(0x80+4);
write_data(table[bai]);
delay(5);
write_com(0x80+6);
write_data(table[shi]);
delay(5);
write_com(0x80+7);
write_data(table[ge]);
delay(5);
}
//**************************LCD 初始化+++小数显示
void fzm()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<4;num++)
{
write_data(table1[num]);
delay(5);
}
write_com(0x80+5);
write_data('.');
}
/***********************主程序***********/
void main()
{
char a;
fzm();
while(1)
{
adwr=1;
//_nop_();
adwr=0;
//_nop_();
adwr=1;
for(a=10;a>0;a--)
{}
P1=0xff;
adrd=1;
// _nop_();
adrd=0;
// _nop_();
adval=P1;
adrd=1;
display(adval);
}
}
|