我自己做的最小系统板 自己写的代码 所以有得地方不会和其他电路板兼容但是ad0809是兼容的,你看一下#include
#include
#define uint unsigned intuchar table[16] = {0x81,0xB7,0xC2,0x92,0xB4,0x98,0x88,0xB3,0x80,0x90,0xA0,0x8C,0xCE,0x86,0xC8,0xE8};sbit CLK = P3^2; // 时钟输入端,最大为500KHz
sbit OE = P3^3; // 输出允许端 等于1时有效
sbit EOC = P3^4; // 转化完成标志 高电平表示转化结束.
sbit ST = P3^5; // 地址锁存信号.// 控制每位数码管显示
sbit L0 = P0^0;
sbit L1 = P0^1;
sbit L2 = P0^2;
sbit L3 = P0^3;
sbit L4 = P0^4;
sbit L5 = P0^5;
sbit K1 = P0^6;uchar a;
bit flag; // 输出方式的标志位void Delay(uint m)
{
uint i,j;
for (i=0; i
}//初始化串口,设置成工作方式0
void InitPort(void)
{
//; 不用设置,初始即为工作方式0
}// 发送一个数据
void SendByte(uchar dat)
{
SBUF = dat;
while (!TI);
TI = 0;
}void InitLed(void)
{
L0 = 0;
L1 = 0;
L2 = 0;
L3 = 0;
L4 = 0;
L5 = 0;
}void DisplayLed(void)
{
uint value; //unsigned long value;
//value = (a*500)/256; if (a < 132)
value = (a*500)/256;
else
{
value = (a*500)/256;
value = value + 256;
} if (!flag)
{
L0 = 0; L1 = 0; L2 = 1;
SendByte(table[value/100]&0x7F);
Delay(5);
L0 = 0; L1 = 1; L2 = 0;
SendByte(table[(value/10)%10]);
Delay(5);
L0 = 1; L1 = 0; L2 = 0;
SendByte(table[value%10]);
Delay(5);
}
else
{
L0 = 0; L1 = 0; L2 = 1;
SendByte(table[a/100]);
Delay(5);
L0 = 0; L1 = 1; L2 = 0;
SendByte(table[(a/10)%10]);
Delay(5);
L0 = 1; L1 = 0; L2 = 0;
SendByte(table[a%10]);
Delay(5);
}
}void ScanKey(void)
{
if (K1 == 0)
{
flag = !flag;
while (!K1);
K1 = 1;
}
}// 初始化AD0809
void InitAD0809(void)
{
ST = 0;
OE = 0;
}// 读AD0809中的数据
uchar ReadAD0809(void)
{
//EOC = 0;
OE = 0;
ST = 0;
//_nop_();
ST = 1; // 上升沿AD0809内部的寄存器清零
//_nop_();
ST = 0; // 产生一个至少100ns的脉冲,在转换期间ST为低 while (!EOC)
{
DisplayLed();
ScanKey();
}
OE = 1;
return P1;
}main()
{
//uint i;
TMOD = 0x01;
EA = 1;
TR0 = 1;
ET0 = 1;
flag = 0;
K1 = 1; InitLed();
InitPort();
InitAD0809(); /*for (i=0; i<16; i++)
{
SendByte(table[i]);
Delay(100);
}*/
while (1)
{
a = ReadAD0809();
}
}
void timer0(void) interrupt 1 using 1
{
TH0 = 0xFF;
TL0 = 0x80; CLK = !CLK;
}
CLOCK BIT P2.0
ST BIT P2.1
EOC BIT P2.2
OE BIT P2.3;子程序如下:AD_CONTER:
CLR ST
SETB ST
CLR ST ;启动转换
JNB EOC,$
SETB OE
MOV ADC_Result,P1 ;读取AD转换结果
CLR OE
MOV A,ADC_Result
RET另外时钟信号可以通过定时器来设定~~;-------------------提供ADC0809时钟--------------------------
INT_T0:
MOV TH0,#245
MOV TL0,#0
CPL P2.0 RETI