|
/*********************程序說(shuō)明*****************/
//程序可實(shí)現(xiàn)將stm32f103的ADC采樣值和將其轉(zhuǎn)化的電壓值發(fā)送給手機(jī)
//ADC---PA0
//串口 PA9 PA10
#include "stm32f10x.h"
#include "valuepack.h"
#include "delay.h"
#include "adc.h"
// 首先需要有 發(fā)送數(shù)據(jù)包 和 接收數(shù)據(jù)包 數(shù)據(jù)包中有不同類(lèi)型變量的數(shù)組,
//可以在valuepack.h中定義數(shù)據(jù)包的結(jié)構(gòu)
TxPack txpack;
RxPack rxpack;
float f;
u16 adcx;
int main(void)
{
initValuePack(9600); // 初始化串口 設(shè)置波特率`
delay_init();
Adc_Init(); //ADC初始化
while(1)
{
adcx=Get_Adc_Average(ADC_Channel_1,10);
f=(float)adcx*(3.3/4096); //電壓轉(zhuǎn)化
delay_ms(250);// 延時(shí)一段時(shí)間
txpack.integers[0] =adcx; //發(fā)送整形數(shù)據(jù)adcx給手機(jī)
txpack.floats[0] =f; //發(fā)送浮點(diǎn)數(shù)據(jù)f給手機(jī)
sendValuePack(&txpack);
///////////////////////////////////////////////////////////////////////////////////////////////////////
/// 數(shù)據(jù)收發(fā)部分
// if(readValuePack(&rxpack))
// {
//
// 在此將讀取到的手機(jī)傳來(lái)的數(shù)據(jù),賦值給發(fā)送數(shù)據(jù),實(shí)現(xiàn)將接收的數(shù)據(jù)原樣回傳
// txpack.bools[0] = rxpack.bools[0]; //布爾型
// txpack.bytes[0] = rxpack.bytes[0];
// txpack.shorts[0] = rxpack.shorts[0];
// txpack.integers[0] = rxpack.integers[0];
// txpack.floats[0]= rxpack.floats[0];
// 你也可以把 sendValuePack放在這,這樣就只有當(dāng)接收到手機(jī)傳來(lái)的數(shù)據(jù)包后才回傳數(shù)據(jù)
//
// }
}
}
|
評(píng)分
-
查看全部評(píng)分
|