51hei圖片_20250611165740.jpg (203.25 KB, 下載次數(shù): 0)
下載附件
2025-6-11 16:57 上傳
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "dht11.h"
#include "led.h"
//#include "lcd.h"
#include "soft_iic_oled.h"
#include "soft_iic.h"
#include "rtc.h"
//#include "usmart.h"
#include "stdio.h" //printf函數(shù)頭文件,將浮點(diǎn)數(shù)轉(zhuǎn)換為字符串
//#include "sdio_sdcard.h"
//#include "text.h"
//#include "exfuns.h"
extern const uint8_t BMP1[];
uint8_t temperature;
uint8_t humidity;
char temp[6]={0}; //讀出的溫度暫存寄存器
char humi[6]={0}; //讀出的濕度暫存寄存器
void dat_dis() //溫濕度數(shù)據(jù)處理轉(zhuǎn)為字符串
{
//humi[0]='R';
//humi[1]=':';
humi[0]=humidity/10+0x30;
humi[1]=humidity%10+0x30;
//humi[4]='%';
//humi[5]='\0'; //結(jié)束符,如果不要?jiǎng)t后面會(huì)繼續(xù)寫(xiě)數(shù)據(jù)
//temp[0]='T';
//temp[1]=':';
temp[0]=temperature/10+0x30;
temp[1]=temperature%10+0x30;
//temp[4]='C';
//temp[5]='\0';
}
int main(void)
{
uint8_t t;
/************************程序必備4項(xiàng)****************************/
HAL_Init(); /* 初始化HAL庫(kù) */
sys_stm32_clock_init(RCC_PLL_MUL9); /* 設(shè)置時(shí)鐘, 72Mhz */
delay_init(72); /* 延時(shí)初始化 */
usart_init(115200); /* 串口初始化為115200 */
/***********************所有外設(shè)初始化***************************/
led_init();
iic_init();
oled_init(); //OLED初始化
//lcd_init();
OLED_ShowPicture(0,0,128,64,BMP1,1);
oled_refresh_gram(); /*更新顯示到OLED,只有此語(yǔ)句才會(huì)有顯示*/
rtc_init(); //TRC初始化
//exfuns_init(); /* 為fatfs相關(guān)變量申請(qǐng)內(nèi)存,必須初始化否則無(wú)漢字顯示 */
//f_mount(fs[0], "0:", 1); /* 掛載SD卡 */
//f_mount(fs[1], "1:", 1); /* 掛載FLASH,必須掛載否則無(wú)漢字顯示 */
// while (fonts_init()) /* 檢查字庫(kù),必須初始化字庫(kù)否則無(wú)漢字顯示 */
// {
// lcd_clear(WHITE); /* 清屏 */
// }
rtc_set_alarm(2025, 6, 11, 12, 0, 0); /* 設(shè)置一次鬧鐘12;0;0 */
rtc_set_time(2025,6,11,11,50,42); /* 2025-06-11; 11-50-42 */
while (DHT11_Init()) /* DHT11初始化 */
{
oled_show_string(10, 16, "DHT11 Error",16);
delay_ms(200);
}
delay_ms(1000); //延時(shí)
OLED_ColorTurn(0); //0正常顯示,1 反色顯示
OLED_DisplayTurn(0); //0正常顯示 1 屏幕翻轉(zhuǎn)顯示
oled_clear(); //清屏
//OLCD顯示時(shí)間
/**************************************************/
OLED_ShowChinese(45,0,9,16); //年,16X16字體顯示
OLED_ShowChinese(70,0,10,16); //月
OLED_ShowChinese(96,0,2,16); //日
OLED_ShowChinese(0,48,11,16); //溫
OLED_ShowChinese(13,48,13,16); //度
OLED_ShowChinese(69,48,12,16); //濕
OLED_ShowChinese(82,48,13,16); //度
OLED_ShowChinese(48,48,14,16); //℃
OLED_ShowChinese(116,48,15,16); //%
oled_refresh_gram(); /*更新顯示到OLED,只有此語(yǔ)句才會(huì)有顯示*/
/**************************************************/
//TFTLCD顯示時(shí)間
/**************************************************/
// text_show_string(10+4*16, 30, 200, 24, "年", 24, 0, RED);//“年”字前面4個(gè)數(shù)字,若顯示24大小,則像素為12X24
// text_show_string(10+6*16+32, 30, 200, 24, "月", 24, 0, RED);
// text_show_string(10+8*16+64, 30, 200, 24, "日", 24, 0, RED);
//
// text_show_string(10+4*16, 80, 200, 24, "時(shí)", 24, 0, RED);
// text_show_string(10+6*16+32, 80, 200, 24, "分", 24, 0, RED);
// text_show_string(10+8*16+64, 80, 200, 24, "秒", 24, 0, RED);
//
// text_show_string(10, 120, 200, 24, "溫度: ℃", 24, 0, RED);
// text_show_string(10, 160, 200, 24, "濕度: %", 24, 0, RED);
/**************************************************/
while(1)
{
delay_ms(10);
DHT11_Read_Data(&temperature, &humidity); /*讀取溫濕度值 */
dat_dis();
//OLED顯示溫濕度
/**************************************************/
oled_show_string(32,51,temp,12);
oled_show_string(100,51,humi,12);
//oled_show_num(32,51,temp[0],1,12);
//oled_show_num(40,51,temp[1],1,12);
//oled_show_num(100,51,humi[0],1,12);
//oled_show_num(108,51,humi[1],1,12);
oled_refresh_gram(); /*更新顯示到OLED,只有此語(yǔ)句才會(huì)有顯示*/
/**************************************************/
//TFTLCD顯示溫濕度
/**************************************************/
// lcd_show_num(10+3*24,120,temperature,2,32,BLUE);
// lcd_show_num(10+3*24,160,humidity, 2,32,BLUE);
/**************************************************/
if(t!=calendar.sec)
{
t=calendar.sec;
rtc_get_time();
//OLED顯示時(shí)間
/******************************************************************/
oled_show_num(12,3,calendar.year,4,12); //輸出2025,小字體
oled_show_num(58,3,calendar.month,2,12); //輸出月份
oled_show_num(83,3,calendar.date,2,12); //輸出日期
OLED_DrawLine(10,16,117,16,1); //輸出上橫線(xiàn)
OLED_DrawLine(13,19,114,19,1);
OLED_DrawLine(10,16,10,48,1); //輸出左豎線(xiàn)
OLED_DrawLine(13,19,13,45,1);
OLED_DrawLine(117,16,117,48,1); //輸出右豎線(xiàn)℃
OLED_DrawLine(114,19,114,45,1);
OLED_DrawLine(10,48,117,48,1); //輸出下豎線(xiàn)
OLED_DrawLine(13,45,114,45,1);
oled_refresh_gram(); /*更新顯示到OLED,只有此語(yǔ)句才會(huì)有顯示*/
oled_show_num(27,20,calendar.hour,2,24); // 輸出時(shí)
oled_show_num(63,20,calendar.min, 2,24); // 輸出分
oled_show_num(91,29,calendar.sec, 2,12); // 輸出秒
oled_refresh_gram(); /*更新顯示到OLED,只有此語(yǔ)句才會(huì)有顯示*/
/*********************************************************************/
//TFTLCD顯示時(shí)間
/*********************************************************************/
// lcd_show_num(10, 30,calendar.year, 4,24,BLUE);
// lcd_show_num(10+4*24, 30,calendar.month,2,24,BLUE);
// lcd_show_num(10+6*24+12, 30,calendar.date, 2,24,BLUE);
//
// lcd_show_num(10+1*24, 80,calendar.hour, 2,24,BLUE);
// lcd_show_num(10+4*24, 80,calendar.min, 2,24,BLUE);
// lcd_show_num(10+6*24+12, 80,calendar.sec, 2,24,BLUE);
/**********************************************************************/
delay_ms(500); //延時(shí),避免刷新DHT11數(shù)據(jù)太快
}
}
}
原理圖: 無(wú)
仿真: 無(wú)
代碼:
Soft_IIC驅(qū)動(dòng)4線(xiàn)OLED顯示RTC時(shí)間.7z
(2.39 MB, 下載次數(shù): 0)
2025-6-11 17:55 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|