久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1122|回復: 0
打印 上一主題 下一主題
收起左側

STH30系列官方示例程序 STM8單片機

[復制鏈接]
跳轉到指定樓層
樓主
ID:753786 發表于 2023-7-23 09:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
正在嘗試用STM08寫一個溫濕度的代碼,從官網下的,希望對大家有所幫助。

單片機源程序如下:
  1. #include "system.h"
  2. #include "sht3x.h"

  3. //-- Static function prototypes -----------------------------------------------
  4. static void EvalBoardPower_Init(void);
  5. static void Led_Init(void);
  6. static void UserButton_Init(void);
  7. static void LedBlueOn(void);
  8. static void LedBlueOff(void);
  9. static void LedGreenOn(void);
  10. static void LedGreenOff(void);
  11. static u8t ReadUserButton(void);

  12. //-----------------------------------------------------------------------------
  13. int main(void)
  14. {
  15.   etError   error;       // error code
  16.   u32t      serialNumber;// serial number
  17.   regStatus status;      // sensor status
  18.   ft        temperature; // temperature [癈]
  19.   ft        humidity;    // relative humidity [%RH]
  20.   bt        heater;      // heater, false: off, true: on
  21.   
  22.   SystemInit();
  23.   Led_Init();
  24.   UserButton_Init();
  25.   EvalBoardPower_Init();
  26.   
  27.   SHT3X_Init(0x45); // Address: 0x44 = Sensor on EvalBoard connector
  28.                     //          0x45 = Sensor on EvalBoard
  29.   
  30.   // wait 50ms after power on
  31.   DelayMicroSeconds(50000);   
  32.   
  33.   error = SHT3x_ReadSerialNumber(&serialNumber);
  34.   if(error != NO_ERROR){} // do error handling here
  35.   
  36.   // demonstrate a single shot measurement with clock-stretching
  37.   error = SHT3X_GetTempAndHumi(&temperature, &humidity, REPEATAB_HIGH, MODE_CLKSTRETCH, 50);
  38.   if(error != NO_ERROR){} // do error handling here
  39.   
  40.   // demonstrate a single shot measurement with polling and 50ms timeout
  41.   error = SHT3X_GetTempAndHumi(&temperature, &humidity, REPEATAB_HIGH, MODE_POLLING, 50);
  42.   if(error != NO_ERROR){} // do error handling here
  43.   
  44.   // loop forever
  45.   while(1)
  46.   {
  47.     error = NO_ERROR;
  48.    
  49.     // loop while no error
  50.     while(error == NO_ERROR)
  51.     {
  52.       // read status register
  53.       error |= SHT3X_ReadStatus(&status.u16);
  54.       if(error != NO_ERROR) break;
  55.       
  56.       // check if the reset bit is set after a reset or power-up
  57.       if(status.bit.ResetDetected)
  58.       {
  59.         //override default temperature and humidity alert limits (red LED)
  60.         error = SHT3X_SetAlertLimits( 70.0f,  50.0f,  // high set:   RH [%], T [癈]
  61.                                       68.0f,  48.0f,  // high clear: RH [%], T [癈]
  62.                                       32.0f,  -2.0f,  // low clear:  RH [%], T [癈]
  63.                                       30.0f,  -4.0f); // low set:    RH [%], T [癈]
  64.                     if(error != NO_ERROR) break;
  65.                
  66.         
  67.         // clear reset and alert flags
  68.         error = SHT3X_ClearAllAlertFlags();
  69.         if(error != NO_ERROR) break;
  70.         
  71.         //start periodic measurement, with high repeatability and 1 measurements per second
  72.         error = SHT3X_StartPeriodicMeasurment(REPEATAB_HIGH, FREQUENCY_1HZ);
  73.         if(error != NO_ERROR) break;
  74.         
  75.         //switch green LED on
  76.         LedGreenOn();
  77.       }
  78.         
  79.       // read measurment buffer
  80.       error = SHT3X_ReadMeasurementBuffer(&temperature, &humidity);
  81.       if(error == NO_ERROR)
  82.       {
  83.         // flash blue LED to signalise new temperature and humidity values
  84.         LedBlueOn();
  85.         DelayMicroSeconds(10000);
  86.         LedBlueOff();
  87.       }
  88.       else if (error == ACK_ERROR)
  89.       {
  90.         // there were no new values in the buffer -> ignore this error
  91.         error = NO_ERROR;
  92.       }
  93.       else break;
  94.       
  95.       // read heater status
  96.       heater = status.bit.HeaterStatus ? TRUE : FALSE;
  97.       
  98.       // if the user button is not pressed ...
  99.       if(ReadUserButton() == 0)
  100.       {
  101.          // ... and the heater is on
  102.          if(heater)
  103.          {
  104.            // switch off the sensor internal heater
  105.            error |= SHT3X_DisableHeater();
  106.            if(error != NO_ERROR) break;
  107.          }
  108.       }
  109.       else
  110.       // if the user button is pressed ...
  111.       {
  112.          // ... and the heater is off
  113.          if(!heater)
  114.          {
  115.            // switch on the sensor internal heater
  116.            error |= SHT3X_EnableHeater();
  117.            if(error != NO_ERROR) break;
  118.          }
  119.       }
  120.       
  121.       // wait 100ms
  122.       DelayMicroSeconds(100000);
  123.     }
  124.    
  125.     // in case of an error ...
  126.    
  127.     // ... switch green and blue LED off
  128.     LedGreenOff();
  129.     LedBlueOff();
  130.    
  131.     // ... try first a soft reset ...
  132.     error = SHT3X_SoftReset();
  133.    
  134.     // ... if the soft reset fails, do a hard reset
  135.     if(error != NO_ERROR)
  136.     {
  137.       SHT3X_HardReset();
  138.     }
  139.    
  140.     // flash green LED to signalise an error
  141.     LedGreenOn();
  142.     DelayMicroSeconds(10000);
  143.     LedGreenOff();
  144.   }
  145. }

  146. //-----------------------------------------------------------------------------
  147. static void EvalBoardPower_Init(void)    /* -- adapt this code for your platform -- */
  148. {
  149.   RCC->APB2ENR |= 0x00000008;  // I/O port B clock enabled
  150.   
  151.   GPIOB->CRH   &= 0x0FFF0FFF;  // set push-pull output for Vdd & GND pins
  152.   GPIOB->CRH   |= 0x10001000;  //
  153.   
  154.   GPIOB->BSRR = 0x08008000;    // set Vdd to High, set GND to Low
  155. }

  156. //-----------------------------------------------------------------------------
  157. static void Led_Init(void)               /* -- adapt this code for your platform -- */
  158. {
  159.   RCC->APB2ENR |= 0x00000010;  // I/O port C clock enabled
  160.   GPIOC->CRH   &= 0xFFFFFF00;  // set general purpose output mode for LEDs
  161.   GPIOC->CRH   |= 0x00000011;  //
  162.   GPIOC->BSRR   = 0x03000000;  // LEDs off
  163. }

  164. //-----------------------------------------------------------------------------
  165. static void UserButton_Init(void)        /* -- adapt this code for your platform -- */
  166. {
  167.   RCC->APB2ENR |= 0x00000004;  // I/O port A clock enabled
  168.   GPIOA->CRH   &= 0xFFFFFFF0;  // set general purpose input mode for User Button
  169.   GPIOA->CRH   |= 0x00000004;  //
  170. }

  171. //-----------------------------------------------------------------------------
  172. static void LedBlueOn(void)              /* -- adapt this code for your platform -- */
  173. {
  174.   GPIOC->BSRR = 0x00000100;
  175. }

  176. //-----------------------------------------------------------------------------
  177. static void LedBlueOff(void)             /* -- adapt this code for your platform -- */
  178. {
  179.   GPIOC->BSRR = 0x01000000;
  180. }

  181. //-----------------------------------------------------------------------------
  182. static void LedGreenOn(void)             /* -- adapt this code for your platform -- */
  183. {
  184.   GPIOC->BSRR = 0x00000200;
  185. }

  186. //-----------------------------------------------------------------------------
  187. static void LedGreenOff(void)            /* -- adapt this code for your platform -- */
  188. {
  189.   GPIOC->BSRR = 0x02000000;
  190. }

  191. //-----------------------------------------------------------------------------
  192. static u8t ReadUserButton(void)          /* -- adapt this code for your platform -- */
  193. {
  194.   return (GPIOA->IDR & 0x00000001);
  195. }
復制代碼

代碼下載:
Sensirion_Humidity_Sensors_Software_SHT3x_Sample_Code.zip (410.11 KB, 下載次數: 5)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲品质自拍视频网站 | www.日韩av.com| 天天拍天天射 | 伊人爽 | 超碰日韩 | 亚洲午夜视频在线观看 | 亚洲男人网 | 美女黄18岁以下禁止观看 | 精品欧美久久 | 亚洲综合电影 | 免费视频一区二区 | 国产精品视频网 | 国产福利在线小视频 | 欧美黄页 | 欧美激情一区 | 成人国产精品久久久 | 国产欧美日韩视频 | 超碰在线播 | 欧美成人久久 | 日韩国产精品一区二区三区 | 亚洲综合在线播放 | 国产免费拔擦拔擦8x高清 | 99成人| 中文视频在线 | 欧美激情在线精品一区二区三区 | 91麻豆精品国产91久久久久久久久 | 久草网站| 日韩欧美网 | 亚洲成人精品久久久 | 成人在线精品视频 | 欧美一区二区三区久久精品 | 视频在线一区二区 | 中文字幕在线观看精品 | 久久精品亚洲欧美日韩久久 | 成人在线播放 | 午夜欧美 | 正在播放一区二区 | 国产精品久久片 | 亚洲精品一区二区三区中文字幕 | 在线中文视频 | 狠狠操网站|