標題:
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 //選中數(shù)據(jù)寄存器讀 通道1
#define RD_DATA_REG2 0x39 //選中數(shù)據(jù)寄存器讀 通道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驅(qū)動程序///////////////
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) ; // 設置讀當前通道數(shù)據(jù),通道1 如果是通道2,改成WriteByte7705(0x39)
delay(2);
while (AdDrdy) ; //等待數(shù)據(jù)準備好
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) ; // 設置讀當前通道數(shù)據(jù),通道1 如果是通道2,改成WriteByte7705(0x39)
// delay(2);
// while (AdDrdy) ; \ //等待數(shù)據(jù)準備好
// 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獨處的數(shù)字量轉(zhuǎn)化為電壓,擴大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) ; // 設置讀當前通道數(shù)據(jù),通道1 如果是通道2,改成WriteByte7705(0x39)
delay(2);
while (AdDrdy) ; //等待數(shù)據(jù)準備好
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驅(qū)動程序///////////////
#endif
復制代碼
所有資料51hei提供下載:
AD雙通道顯示成品.rar
(49.89 KB, 下載次數(shù): 36)
2020-4-22 17:52 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時間:
2020-4-23 01:21
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1