|
是基于32的一款源程序代碼,根據(jù)不同顯示屏自己調(diào)節(jié)顯示
單片機(jī)源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "usmart.h"
- #include "24cxx.h"
- #include "myiic.h"
- #include "FDC2X2X_CMD.h"
- #include "FDC2214.h"
-
-
- //**特別注意:使用時SDA、SCL要接4.7K上拉電阻**//
- //**寄存器值的讀取及電容的計算具體在 FDC2214_read_CHx() 中**//
- //要寫入到24c02的字符串?dāng)?shù)組
- const u8 TEXT_Buffer[]={"WarShipSTM32 IIC TEST"};
- #define SIZE sizeof(TEXT_Buffer)
- int main(void)
- {
- delay_init(); //延時函數(shù)初始化
- NVIC_Configuration(); //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應(yīng)優(yōu)先級
- uart_init(9600); //串口初始化為9600
- KEY_Init();
- LED_Init(); //LED端口初始化
- LCD_Init();
- usmart_dev.init(72); //初始化USMART
- AT24CXX_Init(); //IIC初始化
- FDC2214_Init();
- while(1)
- {
- // FDC2214_read_CHx(0);
- printf("%f pf\r\n",FDC2214_read_CHx(0));
- delay_ms(1000);
- }
- }
復(fù)制代碼
- #include "FDC2214.h"
- #include "myiic.h"
- #include "delay.h"
- #include "FDC2X2X_CMD.h"
- #include "usart.h"
- u32 data_Fdc2214_H;
- u32 data_Fdc2214_L;
- float FDC2214_read_CHx(u8 CHx) //讀Channel x Conversion Result
- {
- u8 reg_addr1 = 0; //MSB地址
- u8 reg_addr = 0; //LSB地址
- u32 data_H = 0; //接收到的數(shù)據(jù)
- u32 data1_L = 0;
- float conver = 0; //最終的轉(zhuǎn)換的結(jié)果
- // static u32 data_H_last = 0;
- switch(CHx)
- {
- case 0:
- {
- reg_addr1 = LDC13xx16xx_CMD_DATA_MSB_CH0;
- reg_addr = LDC13xx16xx_CMD_DATA_LSB_CH0; //不知道LSB寄存器有什么用,手冊也沒見有
- }break;
- case 1:
- {
- reg_addr1 = LDC13xx16xx_CMD_DATA_MSB_CH1;
- reg_addr = LDC13xx16xx_CMD_DATA_LSB_CH1;
- }break;
- case 2:
- {
- reg_addr1 = LDC13xx16xx_CMD_DATA_MSB_CH2;
- reg_addr = LDC13xx16xx_CMD_DATA_LSB_CH2;
- }break;
- case 3:
- {
- reg_addr1 = LDC13xx16xx_CMD_DATA_MSB_CH3;
- reg_addr = LDC13xx16xx_CMD_DATA_LSB_CH3;
- }break;
- default: return 0; //輸入錯誤
-
- }
-
- //printf("%d \r\n",LCD_read_16bit(reg_addr1));
- //printf("%d \r\n",LCD_read_16bit(reg_addr));
- data_H = FDC_read_16bit(reg_addr1); //讀取寄存器值 讀高位
- data1_L = FDC_read_16bit(reg_addr); //讀取寄存器值 讀低位
- // printf("%X \r\n",data_H);
- // printf("%X \r\n",data1_L);
-
- //**加入此判斷大電容無法使用**//
- // if(data_H>400)
- // {
- // data_H_last = data_H;
- // conver = ( ((data_H & 0x0FFF)<<16)|(data1_L) ); //融合結(jié)果
-
- // }
- // else
- // {
- // conver = ( ((data_H_last & 0x0FFF)<<16)|(data1_L) ); //融合結(jié)果
- //
- // }
-
- conver = ( ((data_H & 0x0FFF)<<16)|(data1_L) ); //融合結(jié)果
-
- data_Fdc2214_H = data_H;
- data_Fdc2214_L = data1_L;
-
- //***注意Init中各通道寄存器0x10-0x17的時鐘分頻***//
- //*******以下四步計算根據(jù)datasheet P19公式*******//
- conver = (conver * 40000000.0F)/268435456.0F;//得到F(sensorx)
-
- conver = conver * 2.0F *3.1515926F;
- conver = 1.0F/((conver * conver) * 0.000018F);
- conver = conver - 0.000000000033F;
-
-
- conver = conver * 1000000000000.0F;//F轉(zhuǎn)換pF;
-
-
- return conver;
-
- }
- void FDC2214_Init(void) //初始化LDC1314和I2C
- {
- IIC_Init(); //IIC初始化
- LDC_ADDR = 0; //LDC的7bit地址為0X2A,注意是7bit 即 0101 010_ 最低位為讀寫位
- LDC_SD = 0; //退出Shutdown Mode
- delay_ms(500); //延時500ms
-
- //根據(jù)時間要求(100 SPS)計算的參考計數(shù)分辨率要求
- FDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH0,0Xffff);
- FDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH1,0Xffff);
- FDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH2,0Xffff);
- FDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH3,0Xffff);
-
- FDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH0,0X0400);
- FDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH1,0X0400);
- FDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH2,0X0400);
- FDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH3,0X0400);
-
- FDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH0,0X1001);
- FDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH1,0X1001);
- FDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH2,0X1001);
- FDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH3,0X1001);
-
- FDC_write_16bit(LDC13xx16xx_CMD_ERROR_CONFIG,0X0001);
-
- FDC_write_16bit(LDC13xx16xx_CMD_MUX_CONFIG,0x820D);
-
- FDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH0,0x8c40);
- FDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH1,0x8c40);
- FDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH2,0x8c40);
- FDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH3,0x8c40);
- FDC_write_16bit(LDC13xx16xx_CMD_CONFIG,0x1e01); //bit13 清零 退出睡眠模式
-
- }
復(fù)制代碼
所有資料51hei提供下載:
FDC2214.7z
(243.82 KB, 下載次數(shù): 31)
2019-6-25 17:13 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|
|