#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define DATE P0
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
sbit oe=P1^3;
sbit eoc=P1^4;
sbit clk=P1^5;
sbit st=P1^6;
uint getdata=0;
uint dot=0;
uint bai,shi,ge;
uchar code table1[]="0123456789.v";
void initdingshi(); //初始化定时器0
void adc0809(); //启动0809转换,并得到转换A/D
void initdingshi(); //初始化LCD1602
/********************延时函数*************************/
void delay_us(unsigned int n)
{
if(n==0)
return;
while(--n);
}
void delay_ms(uint i)
{
unsigned char a,b;
for(a=1;a<i;a++)
for(b=1;b;b++);
}
void delay(uint z)
{
uint x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
/**************************控制LCD1602的函数*******************/
void write_command(uchar come) //写指令
{
rs=0;
e=1;
DATE=come;
delay_us(5);
e=0;
rs=1;
}
void write_date(uchar date)
{
rs=1;
e=1;
DATE=date;
delay_us(5);
e=0;
rs=0;
}
/*****************液晶初始化****************/
void inityejing() //液晶初始化
{
rw=0;
e=0;
write_command(0x38);
delay_ms(5);
write_command(0x01);
delay_ms(5);
write_command(0x06);
delay_ms(5);
write_command(0x0c);
delay_ms(5);
}
void chufa()
{
bai=(getdata)/100;
shi=(getdata)%100/10;
ge=(getdata)%10;
write_command(0x80);
write_date(table1[bai]);
write_date(table1[10]);
write_date(table1[shi]);
write_date(table1[ge]);
write_date(table1[11]);
delay(100);
}
/********************ADC0809的使用*************************/
void adc0809()
{
st=0;
st=1;
st=0;
while(!eoc);
oe=1;
dot=P2;
oe=0;
getdata=dot*1.0/255*500;
}
/********************配置定时器产生时钟***********************/
void initdingshi() //初始化定时器0工作方式2 为0809提供时钟
{
TMOD=0X02;
TH0=0XFB; //500KHZ 2微秒
TL0=0XFB;
TR0=1;
ET0=1;
EA=1;
}
void main()
{
inityejing();
initdingshi();
while(1)
{
adc0809();
chufa();
}
}
void time0() interrupt 1
{
TH0=0XFB;
TL0=0XFB;
clk=~clk;
}
ADC0809程序.zip
(30.33 KB, 下载次数: 32)
|