内容发布更新时间 : 2024/12/23 20:49:10星期一 下面是文章的全部内容请认真阅读。
_nop_();
temp=Read_CS5530_Register(Read_GAIN); //读取增
// 益
寄存器 测试用 } /*
*-----------------------------------------------------------------------------------------
-----------------------------------------------
* 函数原型:void begin_convert() * 函数功能:开始转换
* 输入参数:command 0xc0执行连续转换 0x80执行完全稳定的单次转换 * 返 回 值:无
*-----------------------------------------------------------------------------------------
----------------------------------------------- */
void Begin_Convert(INT8U command) {
MiniDelay(500); SPI_WriteOneByte(command); CS5530StartADbit=1; } /*
*-----------------------------------------------------------------------------------------
-----------------------------------------------
* 函数原型:INT32U read5530adc(INT8U command)
* 函数功能:读取数据转换的结果
* 输入参数:command 0x00保持同样的设置进行连续转换,0xff为退出该转换模式 * 返 回 值:temp为转换读出的数据,数据寄存器的高3个字节,不包括低字节(标志位) *-----------------------------------------------------------------------------------------
-----------------------------------------------
*/
//读取转换数据时,要发送40个SCLK时钟。开始的8个SCLK是用来清除SDO标志位, //而且SDI要保持为低电平0。剩下的32个SCLK来读取转换结果数据
#define ADVALUE_ABNORMAL 0xff000000
INT32U ReadCS5530ADValue(INT8U command) //放在主循环,5ms左右跑一次 0xff000000 返回超范围 { // Dual temp; INT32U temp; //要加开始表示位 if(CS5530StartADbit==0) { return 0; } do{;} while(MCU_SDO_CS5530!=0); //while(SPI_MISO_READ()!=0);
//等待SDO变为0 MCU_SDI_CS5530=0; SPI_WriteOneByte(command); //清除串口标志 同时选择转
换模式(单次连续还是结束单次连续) temp=SPI_ReadOneByte(); // CS5530_buf[3]=SPI_ReadOneByte(); temp=(temp<<8)+SPI_ReadOneByte(); //CS5530_buf[2]=SPI_ReadOneByte(); temp=(temp<<8)+SPI_ReadOneByte(); //CS5530_buf[1]=SPI_ReadOneByte(); temp=(temp<<8)+SPI_ReadOneByte(); //CS5530_buf[0]=SPI_ReadOneByte(); if(temp&0x04) { //超范围 // TestPrint('A'); //return ADVALUE_ABNORMAL; } else { }
temp=temp>>8; return temp; } /*
*******************************************************************************************
**********************************************
*-----------------------------------------------------------------------------------------
-----------------------------------------------
*-----------------------------------------------------------------------------------------
-----------------------------------------------
*-----------------------------------------------------------------------------------------
-----------------------------------------------
测试函数
*-----------------------------------------------------------------------------------------
-----------------------------------------------
*-----------------------------------------------------------------------------------------
-----------------------------------------------
*-----------------------------------------------------------------------------------------
----------------------------------------------- */
void CS5530_TEST(void) {
// AD_value=0; // offset_adjust(); // gain_adjust(); #if 0 Write_CS5530_Register(Write_CONFIG,DATARATE_3200);
//write_CS5530_register(0x03,0x00,0x00,0x40,0x00); //Read_CS5530_Register(Read_CONFIG); // read_CS5530_register(0x0b); Begin_Convert(START_CONTINUOUS);
//
//while(1) //{ AD_value=ReadCS5530ADValue(0x00); //} #endif
//AD_value=ReadCS5530ADValue(0x00);
//CalWT(AD_value); }
void CalWT(INT32U AveADValue) {
//重量=(实时AD值/加载的AD值)*加载重量 NowWT=AveADValue*CSPWT/CSPAD; // 00 00 70 23 00 00 00 32 if(NowWT>=PeakWT) { PeakWT=NowWT; } } /*
43 00 00 78 BB 00 00 00 35 43 00 00 79 5C 00 00 00 36 43 00 00 79 BA 00 00 00 36 43 00 00 78 96 00 00 00 35 43 00 00 74 E3 00 00 00 34 43 00 00 73 54 00 00 00 33 43 00 00 73 07 00 00 00 33 43 00 00 74 2C 00 00 00 33 43 00 00 72 BF 00 00 00 33 43 00 00 72 A0 00 00 00 33 43 00 00 73 8C 00 00 00 33 43 00 00 74 E5 00 00 00 34 43 00 00 73 EA 00 00 00 33 43 00 00 71 F1 00 00 00 32
*/
void WTPreocess(void) { INT8U i; INT32U Temp; Temp=ReadCS5530ADValue(0x00); if(Temp!=ADVALUE_ABNORMAL) { for(i=(ADARRAY_NUM-1);i>0;i--) // { ADArray[i]=ADArray[i-1]; } ADArray[0]=ReadCS5530ADValue(0x00); AVE_AD_value=0; for(i=0;i
/*****************.h***************/