1、#include #include “intrins.h“sbit AD7798_CS=P22; / 1sbit AD7798_SCLK=P23; / 1sbit AD7798_RDY=P21; / 0sbit AD7798_DOUT=P21;sbit AD7798_DIN=P20; / 1void Init_Serial( void );/串口初始化void WaiteRDY( void );/等待 RDY 变为低电平unsigned char ReadByte_7798( void );/读一个字节void ReadData_7798( void );/ AD7798 采集到得数据void
2、 Serial_Receive(unsigned char Data);/发送一个字节数据void WriteByte_7798(unsigned char Data);/写一个字节 void Init_Ad7798(unsigned char ChannelNum);/AD7798 初始化unsigned char disp8 = 0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x04;unsigned char New_Data8 = 0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x04;unsigned char Next_Data8 =
3、 0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x04;unsigned char Two_Data8 = 0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x04;unsigned char hData,lData;long int new,old,yy;/=主函数void main( void )unsigned char i,j;/AD7798 读取的数据Init_Serial();P2 = 0x00;WriteByte_7798(0xff);/reset ad7798WriteByte_7798(0xff);WriteByte_7798(
4、0xff);WriteByte_7798(0xff);while(1)for(i=0;i65500) WriteByte_7798(0xff);/reset ad7798WriteByte_7798(0xff);WriteByte_7798(0xff);WriteByte_7798(0xff);Init_Ad7798(0);break;/=7798 的初始化void Init_Ad7798(unsigned char ChannelNum)WriteByte_7798(0xff);/reset ad7798WriteByte_7798(0xff);WriteByte_7798(0xff);Wr
5、iteByte_7798(0xff);WriteByte_7798(0x10);/写入通讯寄存器设置下一个操作,写信给配置寄存器WriteByte_7798(0x27);/增益为 128WriteByte_7798(0x30+ChannelNum);/* /写入模式注册启动 系统满量程较准WriteByte_7798(0x08);/写入通讯寄存器设置下一个操作,写信给模式寄存器WriteByte_7798(0xe0);WriteByte_7798(0x0a);WaiteRDY();/等待及由 RDY 销去低显示最终的校准周期/写入模式注册启动 系统失调较准WriteByte_7798(0x08
6、);/写入通讯寄存器设置下一个操作,写信给模式寄存器WriteByte_7798(0xc0);WriteByte_7798(0x0a);WaiteRDY();/等待及由 RDY 销去低显示最终的校准周期*/写入模式注册启动 内部零刻度校准WriteByte_7798(0x08);/写入通讯寄存器设置下一个操作,写信给模式寄存器WriteByte_7798(0x80);WriteByte_7798(0x0a);WaiteRDY();/等待及由 RDY 销去低显示最终的校准周期/写入模式注册启动 内部满刻度校准/ WriteByte_7798(0x08);/写入通讯寄存器设置下一个操作,写信给模式
7、寄存器/ WriteByte_7798(0xa0);/ WriteByte_7798(0x0a);/ WaiteRDY();/等待及由 RDY 销去低显示最终的校准周期WriteByte_7798(0x08);/写入通讯寄存器设置下一个操作,写信给模式寄存器WriteByte_7798(0x00);WriteByte_7798(0x0a);/=读 AD 的数据void ReadData_7798( void )int ConverData ;unsigned char ADSAT ;unsigned char ErrNUM;WaiteRDY();/RDY 为低电平时读取数据,读取完成后变为高电
8、平WriteByte_7798(0x40);ADSAT=ReadByte_7798();/出错或者读写异常/ Serial_Receive(ADSAT); while(ADSATWriteByte_7798(0xff);WriteByte_7798(0xff);WriteByte_7798(0xff);Init_Ad7798(0);WaiteRDY();WriteByte_7798(0x40);ADSAT=ReadByte_7798();ErrNUM+;if(ErrNUM5)break;WriteByte_7798(0x58);/写入通讯寄存器设置下一个操作是连续的读取数据寄存器WaiteRD
9、Y();/等待及由 RDY 销去低显示最终的校准周期if(!AD7798_RDY)ConverData=0 ;hData=ReadByte_7798(); ConverData=hData;ConverData=ConverData=Next_Datak)if(New_Datak =Two_Datak) if(Next_Datak=New_Datak) if(Next_Datak=Two_Datak) if(Two_Datak =New_Datak) if(Two_Datak =Next_Datak)for(k=1;k234) disp1=0;if(disp3234) disp3=0;if(disp5234) disp5=0;for(k=0;k8;k+)Serial_Receive(dispk); /发送数据 elseindex_a+; if(index_a=5)index_a=0;index_b=1;