用A/D转换芯片TLC2543CN测量电压并在LED数码管显示时LED数码管闪烁
时间:10-02
整理:3721RD
点击:
我想A/D转换芯片TLC2543CN测量电压并在LED数码管显示出来,在Proteus里面模拟的好好的,可实际做出来的电路板上数码管总是闪烁,请大师帮忙看看是哪里出了问题。
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit TCL2543_SDO=P0^0;
sbit TCL2543_SDI=P0^1;
sbit TCL2543_CS=P0^2;
sbit TCL2543_CLK=P0^3;
sbit TCL2543_EOC=P0^5;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayus(uchar u);
uint ReadADC_TLC2543(uchar ain);
void display(uchar L1,uchar L2,uchar L3);
uchar ECO,u,L1,L2,L3;
unsigned long num;
void main()
{
TCL2543_CS=1;
TCL2543_CLK=0;
while(1)
{
num=ReadADC_TLC2543(0);
L1=num/1000;
L2=num%1000/100;
L3=num%100/10;
display(L1,L2,L3);
}
}
void delayus(unsigned char u)
{
while(--u);
}
uint ReadADC_TLC2543(uchar ain)
{
uchar temp;
uint adc_value = 0;
ain <<= 4;
TCL2543_CS = 0;
for(temp = 0;temp < 12;temp ++)
{
adc_value <<= 1;
ain <<= 1;
TCL2543_SDI = CY;
if(TCL2543_SDO) adc_value += 1;
TCL2543_CLK = 1;
delayus(1);
TCL2543_CLK = 0;
}
TCL2543_CS = 1;
return adc_value;
}
void display(uchar L1,uchar L2,uchar L3)
{
P1=table[L1];
P2=table[L2];
P3=table[L3];
}
Proteus模拟正常