FDC2214的STM32和MSP430F5529串口读取数据程序
2020-07-18 来源:51hei
msp430单片机源程序如下:
#include 'bsp.h'
int main( void )
{
float cap,capfirst,capfirst1;
unsigned int Data_FDC;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
delay_ms(500);
bsp_Init();
_EINT();
delay_ms(500);
Data_FDC = ReadRegfdc2214(0x00);//读取第一通道的值
cap = 232021045.248/(Data_FDC);
capfirst = cap*cap;
delay_ms(500);
Data_FDC = ReadRegfdc2214(0x02);//读取第一通道的值
cap = 232021045.248/(Data_FDC);
capfirst1 = cap*cap;
delay_ms(500);
while(1)
{
Data_FDC = ReadRegfdc2214(0x00);//读取第一通道的值
cap = 232021045.248/(Data_FDC);
cap = capfirst -cap*cap;
printf('DataTEMP0:n');
printf('%dn',cap);
delay_ms(200);
Data_FDC = ReadRegfdc2214(0x02);//读取第一通道的值
cap = 232021045.248/(Data_FDC);
cap = capfirst1 -cap*cap;
printf('DataTEMP1:n');
printf('%dn',cap);
delay_ms(200);
}
}
stm32单片机源程序如下:
#include 'sys.h'
#include 'delay.h'
#include 'usart.h'
#include 'timer.h'
#include 'led.h'
#include 'oled.h'
#include 'fdc2214.h'
#include 'McuDataSend.h'
void Sys_Init(void);
float res0,res1,res2,res3;
float temp0,temp1,temp2,temp3;
int main(void)
{
Sys_Init();
while(1)
{
// Oled_Printf_Float(0,1,res0-temp0,0);
// Oled_Printf_Float(0,3,res1-temp1,0);
// Oled_Printf_Float(0,5,res2-temp2,0);
// Oled_Printf_Float(0,7,res3-temp3,0);
}
}
void Sys_Init(void)
{
delay_init(); //延时函数初始化
NVIC_Configuration();//设置NVIC中断分组2:2;2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
LED_Init();
// OLED_Init();
while(FDC2214_Init());
led=0;
delay_ms(100);
temp0 = Cap_Calculate(0);//读取初始值
temp1 = Cap_Calculate(1);
// temp2 = Cap_Calculate(2);
// temp3 = Cap_Calculate(3);
TIM3_Ctrl_Init(10000-1,7200-1);
}
//定时器5中断服务程序
void TIM3_IRQHandler(void) //TIM5中断
{
if(TIM3->SR&0X0001)//500ms定时中断
{
res0 = Cap_Calculate(0);//采集数据
res1 = Cap_Calculate(1);
// res2 = Cap_Calculate(2);
// res3 = Cap_Calculate(3);
// Data_Send_Status(res,0,0);
// printf('%5d : %5d : %5drn',res0,res1,res2);
led=~led;
printf('CH0;%3.3f CH1;%3.3f rn',res0-temp0,res1-temp1);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
}
TIM3->SR&=~(1<<0); //中断标志位清0,等待下一次中断
}
上一篇:最近搞了一个OLED的字库程序