C语言程序如下:
#include
//---------------------------------------------------
sbit ALE = P3^3;
sbit OE = P3^4;
sbit EOC = P3^5;
sbit STA = P3^6;
sbit CLK = P3^7;
//---------------------------------------------------
unsigned int num; //AD转换后的数字量
char ch; //通道号码
//---------------------------------------------------
void delay(unsigned int z) //延时函数
{
unsigned int x, y;
for(x = z; x 》 0; x--) for(y = 110; y 》 0; y--) CLK = ~CLK;
} //在延时函数中,给ADC0809送去CLK,也算是做而论道的一个独创吧 !
//---------------------------------------------------
void display(void)
{
char code table[] = { //共阴段码
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, //0~7
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; //8~F
P0 = 0; P2 = 0xf7; P0 = table[ch]; delay(2);//通道号码
P0 = 0; P2 = 0xfb; P0 = table[num / 100] + 128; delay(2);//百位加上小数点
P0 = 0; P2 = 0xfd; P0 = table[num % 100 / 10]; delay(2);//十位
P0 = 0; P2 = 0xfe; P0 = table[num % 10]; delay(2);//个位
P0 = 0; //关闭显示器
}
//---------------------------------------------------
void main(void)
{
while(1) { //无穷循环
ch = P2 / 32; //取来通道号码
P3 = ch + 0xf8; //送给ADC0809
ALE = 1; ALE = 0; //地址锁存
STA = 1; STA = 0; //开始转换,稍候,才可读EOC
display(); //显示,既做延时,又输出CLK
while(EOC == 0) display(); //等待转换结束
num = P1; //取出转换结果
num = num * 100 / 51; //比例变换:255 --》 500
}
}
//---------------------------------------------------