您的位置 首页 元件

AD7705使用 C51源程序

源程序有很多不妥之处:1、程序中电压结果换算不好,没用%取余方法2、没有对最小精度进行换,方法是2.5/65535=38.14uV,然后用T_Voltage*38…

源程序有许多不当之处:1、程序中电压成果换算欠好,没用“%”取余办法 2、没有对最小精度进行换,办法是2.5/65535=38.14uV,然后用T_Voltage*38.14uV。还有问题请指出;期望大家能同享自己的原创,谢谢!游客说AD7710源程序与此差不多,不知是否能帮得上忙。

#include
#include
#include
#include

sbit Number_BIT0 = P2^7;
sbit Number_BIT1 = P2^6;
sbit Number_BIT2 = P2^5;
sbit Number_BIT3 = P2^4;
sbit BUZZER = P2^3;

sbit AD7705_DATA=P3^0; // AD7705 input & output data
sbit AD7705_CLK=P3^1; // AD7705 CLK

sbit AD7705_DRDY=P1^2; // AD7705 data ready
sbit AD7705_CS =P1^3; // AD7705 CS

unsigned char Counter,dis_index,dis_digit;
unsigned intT_Voltage;
unsigned char MSB_Data,LSB_Data,temp0,temp1,temp2,temp3,temp4,temp5;

unsigned char code Display_code[11]=
//{0xa0,0xF9,0xc4,0xd0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF,};
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};

void Delayms(unsigned char ms);
void AD7705_Start();
void AD7705_Read ();
void AD7705_Write_Reg(unsigned char Data_byte);
unsigned char AD7705_Read_Reg();

main()
{
TMOD = 0x11;
IT0 = 1;
PCON=0X00;
ET0 = 1;
TH1 = 0xFC;
TL1 = 0x17;
TR0 = 1;

EA = 1;
P0 = 0xff;P1 = 0xff;P2 = 0xf7;P3 = 0xff;
dis_digit = 0x77;
dis_index = 0;
Counter = 0;
AD7705_Start();

while(1)
{
while(AD7705_DRDY);
AD7705_Read();
Delayms(50);
}
}

void Delayms(unsigned char ms)
// relay ms
{unsigned char i;
while(ms–)
{
for(i = 0; i < 120; i++);
}
}

void AD7705_Start()
{
AD7705_Write_Reg(0x20);
AD7705_Write_Reg(0x0c);
AD7705_Write_Reg(0x10);
AD7705_Write_Reg(0x44);
}
void AD7705_Read()
{
AD7705_Write_Reg(0x38);
MSB_Data = AD7705_Read_Reg();
LSB_Data = AD7705_Read_Reg();
T_Voltage =(unsinged int)MSB_Data;
T_Voltage = T_Voltage<<8;
T_Voltage = T_Voltage| (unsigned int)LSB_Data;

temp0 = T_Voltage/100000;
temp1 = ((T_Voltage-temp0*100000)/10000);
temp2 = ((T_Voltage-temp0*100000-temp1*10000)/1000);
temp3 = ((T_Voltage-temp0*100000-temp1*10000-temp2*1000)/100);
temp4 = (T_Voltage-temp0*100000-temp1*10000-temp2*1000-temp3*100)/10;
temp5 = (T_Voltage-temp0*100000-temp1*10000-temp2*1000-temp3*100-temp4*10);

}

void AD7705_Write_Reg(unsigned char Data_byte)
{
unsigned char i;
AD7705_CS = 0;
AD7705_CLK = 1;
_nop_();
_nop_();
for(i = 0; i < 8; i++)
{
AD7705_DATA = (bit)(Data_byte & 0x80);
AD7705_CLK = 0;
_nop_();
_nop_();
_nop_();
AD7705_CLK = 1;

Data_byte <<= 1;
}
_nop_();
AD7705_CS = 1;
}
unsigned char AD7705_Read_Reg()
{
unsigned char i,Data_read;
AD7705_CS = 0;
AD7705_CLK = 1;
_nop_();
for(i = 0; i < 8; i++)
{
AD7705_CLK = 0;
_nop_();
_nop_();
Data_read <<= 1;
Data_read |= (unsigned char)AD7705_DATA;
_nop_();
_nop_();
AD7705_CLK = 1;
_nop_();
_nop_();
}
_nop_();
AD7705_CS = 1;
AD7705_DRDY = 1;
return(Data_read);
}

void time0(void) interrupt 1
{
TR0 = 0;
P2 = dis_digit; //P2.7 –DS8
P0 = Display_code[dis_index];

TH0 = 0xFC;
TL0 = 0x17;
Counter++;
if(Counter==1)
{
dis_digit = 0x77;
dis_index = temp5;
}else if(Counter==2)
{
dis_digit = 0xb7;
dis_index = temp4;
}else if(Counter==3)
{
dis_digit = 0xd7;
dis_index = temp3;
}else if(Counter==4)
{
dis_digit = 0xe7;
dis_index = temp2;
Counter = 0;
}

TR0 = 1;
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/xinpin/yuanjian/252437.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部