[求助]有哪位DX帮我看看这个程序?
[求助]谁能帮我看看这个程序?
小弟是一新手,第一次用c51编写程序,下面是我编写的程序,用数码管显示,AD7715是一个16bit串行AD。在给AD7715输入0.89V电压后,四个数码管应该显示5BC0,可现在只显示EEEE.请教各位高手了!
#include
#define uchar unsigned char
#define uint unsigned int
/************************/
uchar store[2];
uchar *datapointer_r;/*pointer of the data array*/
/*************************/
sbit led_4=P1^4;
sbit led_3=P1^5;
sbit led_2=P1^6;
sbit led_1=P1^7;
sbit ctrl_d=P1^3;
sbit ctrl_c=P1^2;
sbit ctrl_b=P1^1;
sbit ctrl_a=P1^0;
sbit doutin=P3^4;
sbit drdy=P3^3;
sbit sclk=P3^2;
sbit switch_a1=P3^1;
sbit switch_a0=P3^0;
sbit acc7=ACC^7;
sbit acc6=ACC^6;
sbit acc5=ACC^5;
sbit acc4=ACC^4;
sbit acc3=ACC^3;
sbit acc2=ACC^2;
sbit acc1=ACC^1;
sbit acc0=ACC^0;
/***********************************/
/*Write to reg. of AD7715*/
void writetoreg(uchar byteword)
{
uchar i;
sclk=1;
ACC=byteword;
for(i=0;i <8;i++)
{
sclk=0;
doutin=acc7;
sclk=1;
ACC=ACC < <1;
}
}
/***********************************/
/*Read data from AD7715 and save into the store array*/
void readdatareg()
{
uchar i;
sclk=1;
datapointer_r=store;
while (!drdy) /*wait for /drdy go to low this indicate that the data is ready*/
{
for (i=0;i <16;i++)
{
sclk=0;
acc0=doutin;
sclk=1;
ACC=ACC < <1;
if (i=7)
{
*datapointer_r=ACC; /*save high byte*/
datapointer_r++;
}
if (i=15)
{
*datapointer_r=ACC; /*save low byte*/
datapointer_r++;
}
}
}
}
/*****************************************/
/*delay*/
void delay()
{
uchar i;
for (i=0;i <500;i++);
}
/*****************************************/
/*show the data*/
void show()
{
ACC=store[0]; /*show the high byte*/
ctrl_a=acc4;
ctrl_b=acc5;
ctrl_c=acc6;
ctrl_d=acc7;
led_1=1;
delay();
led_1=0;
ACC=store[0];
ctrl_a=acc0;
ctrl_b=acc1;
ctrl_c=acc2;
ctrl_d=acc3;
led_2=1;
delay();
led_2=0;
ACC=store[1]; /*show the low byte*/
ctrl_a=acc4;
ctrl_b=acc5;
ctrl_c=acc6;
ctrl_d=acc7;
led_3=1;
delay();
led_3=0;
ACC=store[1];
ctrl_a=acc0;
ctrl_b=acc1;
ctrl_c=acc2;
ctrl_d=acc3;
led_4=1;
delay();
led_4=0;
}
/*******************************************/
/*main program*/
void main()
{
uchar j;
while(1)
{
writetoreg(0x10);/*set the gain to 1,standby off and set the next operation as
write to the setup register*/
writetoreg(0x54);/*set unbipolar mode,buffer off,no filter sync,confirm clock as 1MHz
set output rate to 100Hz and do a self calibration*/
while (!drdy) /*wait the drdy go to low this indication that the self-calibration
is complete*/
{
writetoreg(0x38);/*set the next operation for 16bit read form the data
register and set the same gain as first*/
readdatareg();
for (j=0;j <100;j++)
{
show();
}
}
}
}
发表时间:2003年7月11日11:44:58