#defineCS5530_GLOBALS#includeVincludes.h/**----------------------------------------------------------------------------------------------------------------------------------------*函数原型:voidSPI_CtrlPin_Init(void)*函数功能:配置IO口*输入参数:无*返回值:无*----------------------------------------------------------------------------------------------------------------------------------------*/voidSPI_Init(void){MCU_CSCLK_CS5530=0;//SPI_SCK_DAT(0);MCU_CS_CS5530=1;//SPI_CS_DAT(1);//取消片选MCU_SDI_CS5530=0;//SPI_MOSI_DAT(0);}/**----------------------------------------------------------------------------------------------------------------------------------------*函数原型:voidSPI_WriteOneByte(INT8Udat)*函数功能:向SPI从设备发送一个字节的数据*输入参数:dat:将要发送给从设备的单字节数据*返回值:无*----------------------------------------------------------------------------------------------------------------------------------------*/voidSPI_WriteOneByte(INT8Udat){INT8Ui;MCU_CSCLK_CS5530=0;for(i=0;i8;i++)//aa{if(dat&0x80){MCU_SDI_CS5530=1;//SPI_MOSI_DAT(1);}else{MCU_SDI_CS5530=0;//SPI_MOSI_DAT(0);}_nop_();_nop_();MCU_CSCLK_CS5530=1;//SPI_SCK_DAT(1);_nop_();_nop_();MCU_CSCLK_CS5530=0;//SPI_SCK_DAT(0);dat=dat1;}//MCU_SDI_CS5530=0;//SPI_MOSI_DAT(0);//SPI_CS_DAT(1);}/**----------------------------------------------------------------------------------------------------------------------------------------*函数原型:INT8USPI_ReadOneByte(void)*函数功能:从从设备读取一个字节的数据*输入参数:无*返回值:返回从从设备读取的数据*----------------------------------------------------------------------------------------------------------------------------------------*/INT8USPI_ReadOneByte(void){INT8Uk,i,dat=0;MCU_CS_CS5530=0;//SPI_CS_DAT(0);;MCU_SDI_CS5530=0;for(i=0;i8;i++){MCU_CSCLK_CS5530=1;//SPI_SCK_DAT(1);_nop_();_nop_();k=MCU_SDO_CS5530;if(k)//if(SPI_MISO_READ()){dat|=(0x80i);}else{}MCU_CSCLK_CS5530=0;//SPI_SCK_DAT(0);_nop_();_nop_();}returndat;//SPI_CS_DAT(1);}/**----------------------------------------------------------------------------------------------------------------------------------------*函数原型:voidreset_CS5530(void)*函数功能:初始化串口*输入参数:无*返回值:无*----------------------------------------------------------------------------------------------------------------------------------------*/voidReset_CS5530(void){INT8Ui;INT32Utemp;FlashWatchDog();CS5530StartADbit=0;MCU_CS_CS5530=1;MiniDelay(10000);MCU_CS_CS5530=0;FlashWatchDog();MiniDelay(10000);MCU_SDI_CS5530=0;MCU_SDO_CS5530=1;FlashWatchDog();MiniDelay(10);MCU_CSCLK_CS5530=0;MCU_CS_CS5530=0;//SPI_CS_DAT(0);;for(i=0;i15;i++)//for(i=0;i15;i++){SPI_WriteOneByte(SYNC1);}SPI_WriteOneByte(SYNC0);//MCU_CS_CS5530=1;FlashWatchDog();MiniDelay(10000);Write_CS5530_Register(Write_CONFIG,SYSTEM_RESET);//Write_CS5530_Register(0x03,0x20,0x00,0x00,0x00);//写配置寄存器写入CS5530复位命令RS为1MiniDelay(5000);do{temp=Read_CS5530_Register(Read_CONFIG);//Read_CS5530_Register(0x0b);}while(temp&RESET_STATUS);//while(CS5530_buf[3]&0x10);//检测RV是否为0(复位成功后为0),如果不为0再继续读取配置寄存器FlashWatchDog();}/**----------------------------------------------------------------------------------------------------------------------------------------*函数原型Voidwrite_CS5530_register(INT8Ucommand,INT8Uone,INT8Utwo,INT8Uthree,INT8Ufour)*函数功能:向寄存器写入数据*输入参数:command:命令字节one,two,three,four分别为将要写入寄存器的四个字节,依次为低字节-高字节*返回值:无*----------------------------------------------------------------------------------------------------------------------------------------*/voidWrite_CS5530_Register(INT8Ucommand,INT32UsetData)//voidWrite_CS5530_Register(INT8Ucommand,INT8Ufour,INT8Uthree,INT8Utwo,INT8Uone){MCU_CS_CS5530=0;//SPI_CS_DAT(0);;SPI_WriteOneByte(command);SPI_WriteOneByte((INT8U)(setData24));SPI_WriteOneByte((INT8U)(setData16));SPI_WriteOneByte((INT8U)(setData8));SPI_WriteOneByte((INT8U)(setData0));//SPI_CS_DAT(1);//MCU_CS_CS5530=1;}/**----------------------------------------------------------------------------------------------------------------------------------------*函数原型:INT32read_CS5530_register(INT8Ucommand)*函数功能:从寄存器读出数据*输入参数:command:命令字节*返回值:dat*----------------------------------------------------------------------------------------------------------------------------------------*/INT32URead_CS5530_Register(INT8Ucommand){//Dualtemp;INT32Utemp=0x00;MCU_CS_CS5530=0;//SPI_CS_DAT(0);;SPI_WriteOneByte(command);temp=SPI_ReadOneByte();//CS5530_buf[3]=SPI_ReadOneByte();temp=(temp8)+SPI_ReadOneByte();//CS5530_buf[2]=SPI_ReadOneByte();temp=(temp8)+SPI_ReadOneByte();//CS5530_buf[1]=SPI_ReadOneByte();temp=(temp8)+SPI_ReadOneByte();//CS5530_buf[0]=SPI_ReadOneByte();//MCU_CS_CS5530=1;/*temp.auc[3]=CS5530_buf[3];temp.auc[2]=CS5530_buf[2];temp.auc[1]=CS5530_buf[1];temp.auc[0]=CS5530_buf[0];return(temp.ans);*/returntemp;}/**----------------------------------------------------------------------------------------------------------------------------------------*函数原型:voidCS5530_init(void)*函数功能:系统复位初始化内部逻辑,并且设置配置寄存器,通道设置寄存器,校准,并且开始转换数据*输入参数:无*返回值:无*--------------------------------------------------------------------------------------------------------------------------