該程序是在stm32開發板上實現功能的,DS18B20獲取溫度通過屏幕顯示和串口打印出來,通過K_UP按鍵選擇修改時間的哪個參數各自對應D1~D7指示燈亮,通過K_LEFT和K_DOWM改變數字的加減。
實物圖:
微信圖片_20180812100017.jpg (168.81 KB, 下載次數: 68)
下載附件
2018-8-12 10:11 上傳
stm32單片機源程序如下:
- #include "system.h"
- #include "SysTick.h"
- #include "led.h"
- #include "usart.h"
- #include "rtc.h"
- #include "tftlcd.h"
- #include "key.h"
- #include "exti.h"
- #include "DS18B20.h"
- /*******************************************************************************
- * 函 數 名 : main
- * 函數功能 : 主函數
- * 輸 入 : 無
- * 輸 出 : 無
- *******************************************************************************/
- int main()
- {
- u8 i=0;
- float temper;
- u8 temper_buf[6];
- int temper1;
-
- SysTick_Init(72);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中斷優先級分組 分2組
- LED_Init();
- USART1_Init(9600);
- RTC_Init();
- TFTLCD_Init();
- LED_Init();
- KEY_Init();
- My_EXTI_Init();
- DS18B20_Init();
-
- FRONT_COLOR=YELLOW;
-
- LCD_ShowFontHZ(10,120,"當前溫度為");
- LCD_ShowFontHZ(80,150,"℃");
-
- while(1)
- {
- i++;
- if(i%5==0)
- {
- temper=DS18B20_GetTemperture();
- temper1=temper*100;
- temper_buf[0]=temper1/10000+0x30;
- temper_buf[1]=temper1%10000/1000+0x30;
- temper_buf[2]=temper1%1000/100+0x30;
- temper_buf[3]='.';
- temper_buf[4]=temper1%100/10+0x30;
- temper_buf[5]=temper1%10+0x30;
- LCD_ShowString(10,150,tftlcd_data.width,tftlcd_data.height,24,(u8 *)temper_buf);
- }
- if(i%20==0)
- {
- led1=!led1;
- }
- delay_ms(10);
- }
- }
復制代碼
所有資料51hei提供下載:
可調時鐘加溫度顯示.rar
(327.7 KB, 下載次數: 45)
2018-8-12 14:28 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|