《ad7705双通道程序》由会员分享,可在线阅读,更多相关《ad7705双通道程序(4页珍藏版)》请在金锄头文库上搜索。
1、奉献给大家AD7705 的双通道应用程序 #include #define CH1 1 /*AD7705 输入通道 IN1*/ #define CH2 2 /*AD7705 输入通道 IN2*/ #define BIPOLAR 0 /*AD7705双极性输入*/ #define UNIPOLAR 1 /*AD7705 单极性输入*/ #define AD_CLK_WIDTH 1 /*AD7705 串口时钟脉冲宽度*/ sbit AdClk=P10; /*AD7705 时钟脉冲*/ sbit AdDin=P11; /*AD7705 数据输入脉冲*/ sbit AdDout=P12; /*AD77
2、05 数据输出的反相脉冲*/ sbit AdDrdy=P13; /*指定转换标志位*/ sbit AdReset=P14; /*复位 */ void Wait7705(unsigned int t);/* AD7705 软件延时 */ void WriteByte7705(unsigned char x);/* 向 AD7705 写入一个字节 */ unsigned int ReadWord7705(void);/* 从 AD7705 读一个字节 */ void Reset7705(void);/* AD7705通信端口复位 */ void Init7705_1(); void Init770
3、5_2(); unsigned int GetData7705_ch1();/* 读 AD7705 转换数据 输入通道 channel -1=IN1,2=IN2;*/ unsigned int GetData7705_ch2();/* 读 AD7705 转换数据 输入通道 channe2 -1=IN1,2=IN2;*/ void main() _nop_(); _nop_(); _nop_();AdClk=1; /AD7705 时钟脉冲 AdDin=1; /AD7705 数据输入脉冲 AdDout=1; /AD7705 数据输出的反相脉冲 AdReset=1; Wait7705(100);/软
4、件延时 AdReset=0; /复位 Wait7705(100); AdReset=1;Wait7705(100); while(1) get_ad(); void Wait7705(unsigned int t)/* AD7705 软件延时 */ for( ;t0 ;t- ); /* 向AD7705 写入一个字节 */ void WriteByte7705(unsigned char x) unsigned char i; for (i=0;i0;i-) WriteByte7705(0xff); /持续 DIN 高电平写操作,恢复AD7705 接口 Reset7705(); /* 防止串口失
5、步 */ WriteByte7705(0x20); /* 写 ch0 clock register */ WriteByte7705(0x00); /* 2.4576MHz 时钟,20Hz 数据更新速率 */ WriteByte7705(0x10); /*选择设置寄存器,使用chnanel 1*/ WriteByte7705(0x44); void Init7705_2() unsigned char i; for(i=10;i0;i-) WriteByte7705(0xff); /持续 DIN 高电平写操作,恢复 AD7705 接口 Reset7705(); /* 防止串口失步 */ Wri
6、teByte7705(0x21); /* 写ch1 clock register */ WriteByte7705(0x00); /* 2.4576MHz 时钟,20Hz 数据更新速率 */ WriteByte7705(0x11); /*选择设置寄存器,使用 chnanel 2*/ WriteByte7705(0x44); /* 读 AD7705 转换数据 输入通道 channel -1=IN1,2=IN2;*/ unsigned int GetData7705_ch1() unsigned int temp1=0; Init7705_1(); Wait7705(10); while(AdDrdy=1); /数据准备好 WriteByte7705(0x38); temp1=ReadWord7705();/读取 return temp1; /* 读 AD7705 转换数据 输入通道 channe2 -1=IN1,2=IN2;*/ unsigned int GetData7705_ch2() unsigned int temp2=0; Init7705_2(); Wait7705(10); while(AdDrdy=1) /数据准备好 WriteByte7705(0x39); temp2=ReadWord7705();/读取 return temp2;