標(biāo)題: PR-3000-TR-I20土壤溫濕度采集的設(shè)計(jì),stm32雙通道ad轉(zhuǎn)換 [打印本頁(yè)]

作者: 一直走    時(shí)間: 2018-7-12 19:50
標(biāo)題: PR-3000-TR-I20土壤溫濕度采集的設(shè)計(jì),stm32雙通道ad轉(zhuǎn)換
PR-3000-TR-I20土壤溫濕度傳感器是4-20mA電流輸出,焊了個(gè)200歐姆電阻轉(zhuǎn)變?yōu)殡妷盒盘?hào)
在進(jìn)行ad轉(zhuǎn)換,把數(shù)據(jù)發(fā)送到串口上。用的板子是stm32f103.


單片機(jī)源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "lcd.h"
  6. #include "usart.h"         
  7. #include "adc.h"



  8. int main(void)
  9. {         
  10.   u16 adc1,adc4;
  11.         float temp1,temp4;
  12.         float st;
  13.         float sh;


  14.         delay_init();                     //延時(shí)函數(shù)初始化          
  15.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置中斷優(yōu)先級(jí)分組為組2:2位搶占優(yōu)先級(jí),2位響應(yīng)優(yōu)先級(jí)
  16.         uart_init(115200);                 //串口初始化為115200
  17.         LED_Init();                             //LED端口初始化                        
  18.         Adc_Init();                                  //ADC初始化

  19.          
  20.         while(1)
  21.         {
  22.                 adc1=Get_Adc_Average1(ADC_Channel_1,10);
  23.                 adc4=Get_Adc_Average4(ADC_Channel_4,10);
  24.                
  25.                                
  26.                
  27.                 temp1=(float)adc1*(3.3/4096);
  28.                 st=((temp1/200)-0.004)*7500-40;


  29.                 printf("st=%f\n",st );
  30.                
  31.                
  32.                 temp4=(float)adc4*(3.3/4096);
  33.                 sh=(temp4/200-0.004)*6250;

  34.           printf("sh=%f\n",sh );
  35.                 LED0=!LED0;
  36.                 delay_ms(500);       
  37.         }
  38. }

復(fù)制代碼

所有資料51hei提供下載:
soilsensor.rar (328 KB, 下載次數(shù): 23)
土壤水分溫度傳感器4~20mA型使用說明書.doc (686 KB, 下載次數(shù): 18)



作者: staryooo    時(shí)間: 2020-5-4 19:39
大佬有沒有rs485輸出的例程!




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1