火浪汤B - tombtomb的BLOG http://tombtomb.52rd.net - 复制 - 收藏
驭刀降佛 发表于 2007-10-21 10:46:00

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

#include<reg52.h>
#include<absacc.h>
#include<intrins.h>
#include<math.h>
 
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 int T_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;
}

阅读全文(2731) | 评论(6)
评 论
6楼 52RD网友(游客) 发表于 2010-2-10 16:45:00
看到你的程序不错能不能把电路图和程序一块发给我,我看着这个片子感觉不错,我的邮箱446463788@163.com
5楼 52RD网友(游客) 发表于 2008-9-10 12:46:00
void AD7705_Start() { AD7705_Write_Reg(0x20); AD7705_Write_Reg(0x0c); AD7705_Write_Reg(0x10); AD7705_Write_Reg(0x44); } 请问这些是寄存器地址的锁存吗
4楼 tombtomb 发表于 2007-12-16 13:15:00
利用数组更好,程序这样才对,可能是网页显示问题。 while(T_Voltage){ ledd[i]=(T_Voltage%10); T_Voltage=T_Voltage/10; i++; if(i>5)i=0;} 以下是更直观的方法:设T_Voltage = 0xfefe;// 65278 temp0 = (T_Voltage/100000); //=0 temp1 = (T_Voltage%100000)/10000; //=6 temp2 = (T_Voltage%10000)/1000; /=5 temp3 = (T_Voltage%1000)/100; //=2 temp4 = (T_Voltage%100)/10; //=7 temp5 = (T_Voltage%10); //=8
3楼 缘(游客) 发表于 2007-12-14 10:19:00
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); 看看我这种方法有没有更好: while(T_Voltage) { ledd[i]=led0[T_Voltage%10]; T_Voltage=T_Voltage/10; i++; if(i>5) i=0; }
2楼 dfsd(游客) 发表于 2007-12-14 10:15:00
asfds
1楼 新纪元(游客) 发表于 2007-12-13 23:23:00
老大看到你的文章很好能否把完整的电路图都传一份给我呵我是一个初学者想做一个小东东来玩玩呵251272180@QQ.com再次感谢你呵
9 1 :
昵 称: 匿名
验证码: 2339
博 主
进入tombtomb的首页
博客名称:火浪汤B
日志总数:24
评论数量:92
访问次数:34062
建立时间:2007年10月16日
导 航
日 历
«Mar.2010»
123456
78910111213
14151617181920
21222324252627
28293031
公 告
欢迎光临!
日 志
评 论
链 接