zhiweiqiang33 发表于 2017-3-15 09:55:22

TLC549 AD采样程序解答?

#include "reg51.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit clock=P2^5;
sbit cs=P2^3;
sbit dat=P2^4;
uchar duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段选
sbit P1_0=P1^0;//位选
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
void delay(uint t)
{
while(t--);
}
uchar ADC0_Conver () //AD采样
{
    uchar i,temp;
cs=1;
clock=0;
cs=0;
_nop_();
_nop_();
for(i=0;i<8;i++)
{
temp<<=1;
temp|=dat;
clock=1;
_nop_();
clock=0;
}
cs=1;
for(i=17;i!=0;i--)_nop_();
return(temp);
}
void display(uint t)//数码管显示函数
{
P1_0=0;
P0=duan;
delay(10);
P0=0xff;
P1_0=1;

P1_1=0;
P0=duan;
delay(10);
P0=0xff;
P1_1=1;
P1_2=0;
P0=duan;
delay(10);
P0=0xff;
P1_2=1;
P1_3=0;
P0=duan;
delay(10);
P0=0xff;
P1_3=1;
}
void main()
{
    uchar value;
    uint voltage;
P1=0xff;
while(1)
{
    delay(100);
    value=ADC0_Conver();
    voltage=5.0/256*(int)value*1000;//将电压值扩大1000倍
    display(voltage);
}

}

为啥改变输入电压,数码管显示的电压值不更新,只显示4980呢?

谢谢!
页: [1]
查看完整版本: TLC549 AD采样程序解答?