ADC0809数字电压表数码管显示出错,求解释!
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/10 13:12:30
设计图如下
源代码如下
//---------------------------------------
//---------------------------------------
#include "reg51.h"
sbit ST_ALE=P3^0;//START and ALE both connect to P3.0
sbit EOC=P3^1;//EOC connect to P3.1
sbit OE=P3^2;//OE conect to P3.2
sbit CLK=P3^3;//CLK connect to P3.3
unsigned char CHANNEL;//AD channel variable
unsigned char LED[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
//common cathode LED code
unsigned char CHECK[4]={0xFE,0xFD,0xFB,0xF7};//choose LED channel
void delay(unsigned char time)
{
unsigned char i,j;
for(i=time;i>0;i--)
for(j=250;j>0;j--)
;
}
void display()
{
unsigned long temp;
unsigned char DATA,digit[4];
unsigned int k,l;
DATA=P1;//save AD data
temp=DATA;//the temporary variable
temp=temp*1000/51;//AD formula:D=A*5/255
digit[0]=temp/1000;//the thousands place
digit[1]=temp%1000/100; //the hundreds place
digit[2]=temp%1000%100/10; //the tens place
digit[3]=temp%1000%100%10;//the ones place
DATA=P2; //save P2
for(k=0;k<1000;k++)
{
/*lighten each LED and equal the below for loop
P1=LED[digit[0]]+0x80;
P2_4=0;
P2_4=1;
P1=LED[digit[1]];
P2_5=0;
P2_5=1;
P1=LED[digit[2]];
P2_6=0;
P2_6=1;
P1=LED[digit[3]];
P2_7=0;
P2_7=1;
*/
for(l=0;l<4;l++)
{
P2=P2|0x0F;//avoid LED residual
P0=LED[digit[l]]+0x80*(l==0);//LED code
P2=DATA&CHECK[l];//choose LED channel
}
}
P2=DATA;//restore P2
}
void main()
{
ST_ALE=0;//START and ALE default
OE=0;//OE default
TMOD=0x02;//T0 operate in mode 2
EA=1;//all interrupt enable
ET0=1;//T0 interrupt enable
TR0=1;//T0 run
while(1)
{
ST_ALE=1;//lock the AD channel address
ST_ALE=0;//AD run
while(EOC==0);//wait until AD over
OE=1;//enable to transmit AD data
display();//view the AD result and diaplay LED
}
}
void T1_TIME() interrupt 1 using 0
{
CLK=~CLK;//CLK 500 kHz
}
设计已经硬件实现了,但是数码管显示和滑动变阻器的数着完全不符,求大神帮助啊!
在我的百度空间里面,有一个正确的电路,可供参考.
另外,你的电压表,没有接地.
这样一来,它显示的数值,并非是 ADC 的电压.