标题:
AD7705双通道显示程序
[打印本页]
作者:
给的功夫
时间:
2020-4-22 17:52
标题:
AD7705双通道显示程序
AD双通道
单片机源程序如下:
#ifndef __ADC7705_H__
#define __ADC7705_H__
sbit AdDrdy= P1^2;
sbit AdDin = P1^5;
sbit AdDout= P1^6;
sbit AdClk = P1^7;
unsigned int data4,data7;
float data2,data6,data3,data5;
//通讯寄存器地址定义
#define WR_Communic_REG 0x00 //选中写通信寄存器
#define WR_SETUP_REG 0x10 //选中写设置寄存器
#define RD_SETUP_REG 0x18 //选中设置寄存器
#define WR_CLOCK_REG 0x20 //选中写时钟寄存器
#define RD_DATA_REG1 0x38 //选中数据寄存器读 通道1
#define RD_DATA_REG2 0x39 //选中数据寄存器读 通道2
#define WR_OFFSET_REG 0x60 //选中写offset寄存器
#define RD_OFFSET_REG 0x68 //选中读offset寄存器
#define WR_FULL_REG 0x70 //选中写full scale寄存器
#define RD_FULL_REG 0x78 //选中读full scale寄存器
void delay(uint x) //延时Xms
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
///////////////以下是16位A/D7705驱动程序///////////////
void WriteByte7705(unsigned char x)
{
unsigned char a;
AdClk = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
for (a=0; a<8; a++)
{
AdClk=0;
if(x & 0x80)
AdDin=1;
else
AdDin=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
AdClk=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
x<<=1;
}
AdDin=1;
}
void InitADC7705()
{
int t;
AdClk=1;
AdDin=1;
for(t=0;t<40;t++)
{
AdClk=0;
_nop_();
_nop_();
AdClk=1;
_nop_();
_nop_();
}
delay(10);
WriteByte7705(0x20);
WriteByte7705(0x0c);
WriteByte7705(0x10);
WriteByte7705(0x44);
delay(10);
/*while (AdDrdy);
delay(10);
WriteByte7705(0x10);
WriteByte7705(0x80);
while (AdDrdy);
delay(10);*/
WriteByte7705(0x11);
WriteByte7705(0x44);
/*while (AdDrdy);
delay(10);
WriteByte7705(0x11);
WriteByte7705(0x80);
while (AdDrdy); */
delay(10);
}
void InitADC7705CH2()
{
int t;
AdClk=1;
AdDin=1;
for(t=0;t<40;t++)
{
AdClk=0;
_nop_();
_nop_();
AdClk=1;
_nop_();
_nop_();
}
delay(10);
WriteByte7705(0x21);
WriteByte7705(0x0c);
}
unsigned int Read_16Byte7705ch1()
{
unsigned int read16bit ;
unsigned char i;
WriteByte7705(0x10);
WriteByte7705(0x44);
delay(10);
WriteByte7705(0x38) ; // 设置读当前通道数据,通道1 如果是通道2,改成WriteByte7705(0x39)
delay(2);
while (AdDrdy) ; //等待数据准备好
AdClk= 1 ;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
read16bit=0x0000;
for (i = 0 ;i < 16 ;i++ )
{
read16bit <<= 1;
AdClk= 0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
if(AdDout)
{
read16bit++;
}
AdClk= 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
return (read16bit);
}
//unsigned int Read_16Byte7705ch2()
//{
// unsigned int read16bit ;
// unsigned char i;
// WriteByte7705(0x39) ; // 设置读当前通道数据,通道1 如果是通道2,改成WriteByte7705(0x39)
// delay(2);
// while (AdDrdy) ; \ //等待数据准备好
// AdClk= 1 ;
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// read16bit=0x0000;
// for (i = 0 ;i < 16 ;i++ )
// {
// read16bit <<= 1;
// AdClk= 0;
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// if(AdDout)
// {
// read16bit++;
// }
// AdClk= 1;
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// _nop_();
// }
// return (read16bit);
//}
//将AD7705独处的数字量转化为电压,扩大1000倍
unsigned int digital_to_voltagech1(float word1)
{
//unsigned int data3;
//float data2;
if(word1>65535)
word1=65535;
if(word1<0)
word1=0;
data2=word1*1.0/65535;
data3=data2*5000;
data4=data2*12125;
return (data3);
}
unsigned int Read_16Byte7705ch2()
{
unsigned int read16bitCH2 ;
unsigned char i;
WriteByte7705(0x11);
WriteByte7705(0x44);
delay(10);
WriteByte7705(0x39) ; // 设置读当前通道数据,通道1 如果是通道2,改成WriteByte7705(0x39)
delay(2);
while (AdDrdy) ; //等待数据准备好
AdClk= 1 ;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
read16bitCH2=0x0000;
for (i = 0 ;i < 16 ;i++ )
{
read16bitCH2 <<= 1;
AdClk= 0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
if(AdDout)
{
read16bitCH2++;
}
AdClk= 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
return (read16bitCH2);
}
unsigned int digital_to_voltagech2(float word2)
{
//unsigned int data3;
//float data2;
if(word2>65535)
word2=65535;
if(word2<0)
word2=0;
data5=word2*1.0/65535;
data6=data5*5000;
data7=data5*12125;
return (data6);
}
///////////////以上是16位A/D7705驱动程序///////////////
#endif
复制代码
所有资料51hei提供下载:
AD双通道显示成品.rar
(49.89 KB, 下载次数: 36)
2020-4-22 17:52 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
admin
时间:
2020-4-23 01:21
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1