大家好:我使用AD tlc2543与89C52组成多通道采集电压,在仿真没问题,实际上当AD采集时显示老跳动,是动态显示的,请各位帮忙讲解。感觉是显示中断出现问题了,可是我是新手不知道如何去修改程序,。请帮忙讲解:程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit AD_SD1=P1^5;
sbit AD_SD0=P1^6;
sbit AD_CS=P1^7;
sbit AD_CLK=P1^4;
sbit start=P1^0;
uchar DAT_H,DAT_L;
sbit p00=P0^0;sbit p01=P0^1;sbit p02=P0^2;sbit p03=P0^3;sbit p04=P0^4;sbit p05=P0^5;sbit p06=P0^6;sbit p07=P0^7;
int time;
void delay(int t){ while(t--);}
uchar tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//共阳
void init(void)//定时器初始化
{
start=1;
EA=1;
TMOD=0x01;
ET0=1;
TH0=0x9e;
TL0=0x58;
TR0=1;
}
void dis_start()
{
P2=0xff;
P2=tab[5];
P3=0X02;
delay(300);
P2=0xff;
P2=0XCE ;
P3=0X04;
delay(300);
P2=0xff;
P2=0x88;
P3=0X08;
delay(300);
P2=0xff;
P2=0x8c;
P3=0X10;
delay(300);
P2=0xff;
P2=0XCE ;
P3=0X20;
delay(300);
}
void dis_err(char chan)
{
P2=0xff;
P2=tab[chan];
P3=0X02;
delay(300);
P2=0xff;
P2=0X86;
P3=0X08;
delay(300);
P2=0xff;
P2=0XCE;
P3=0X10;
delay(300);
P2=0xff;
P2=0XCE;
P3=0X20;
delay(300);
}
void display(char chan,int dat)
{
P2=0xff;
P2=tab[chan];
P3=0X02;
delay(300);
P2=0xff;
P2=tab[dat / 1000] ;
P3=0X04;
delay(300);
P2=0xff;
P2=tab[dat % 1000 /100];
P3=0X08;
delay(300);
P2=0xff;
P2=tab[dat % 100 /10] ;
P3=0X10;
delay(300);
P2=0xff;
P2=tab[dat % 10] ;
P3=0X20;
delay(300);
}
uint GET_AD(uchar port)
{
uint ad=0,i;
AD_CLK=0;
AD_CS=0;
port<<=4;
for(i=0;i<12;i++)
{
if(AD_SD0)
{
ad|=0x01;
}
AD_SD1=(bit)(port&0x80);
AD_CLK=1;
delay(3);
AD_CLK=0;
delay(3);
port<<=1;
ad<<=1;
}
AD_CS=1;
ad>>=1;
return(ad);
}
void main()
{
char chn=0;
uint AD,AD10=0,AD0;
char d[8];
init();
//while(start)dis_start();
P2=0xff;
P3=0X02;
delay(100);
while(1)
{
if(start==0)
{
AD0=GET_AD(0);//AD10=GET_AD(10);
d[1]=p00;d[2]=p01;d[3]=p02;d[4]=p03;d[5]=p04;d[6]=p05;d[7]=p06;d[8]=p07;
if(d[chn])chn++;
{
AD=GET_AD(chn);
if(AD-AD0>12 | AD-AD0>12)//if(AD-AD10>12 | AD-AD10>12)
{
if(AD>12)dis_err(chn);//显示错误ETT
}
else
{
display(chn,AD);
}
}
if(time>60)
{
chn++;
if(chn>8)chn=0;
time=0;
}
}
else dis_start(); //为1时候显示初始化
}
}
void timer0() interrupt 1 using 0
{
TH0=0x9e;
TL0=0x58;
time++;
} |