用的是stm32自帶的RTC時鐘。硬件連接很簡單,當然程序也是比較簡單的,只寫了溫度(DS18B20),stm32自帶RTC和OLED顯示,大家可自行刪改功能。
硬件連接:
SDA --》PB13
SCL --》PB12
DS18B20----》PA15
OLED和DS18B20直接5V供電就成,效果如下:
單片機源程序如下:
#include "sys.h" #include "usart.h" #include "delay.h" #include "led.h" #include "key.h" #include "oled.h" #include "beep.h" #include "rtc.h" #include "ds18b20.h" u8 year_buf[4]; u8 month_buf[2]; u8 day_buf[2]; u8 temp_buf[4]; int main(void) { u16 temp; delay_init(); //延時初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置中斷優(yōu)先級分組為組2:2位搶占優(yōu)先級,2位響應(yīng)優(yōu)先級 Gpio_IIC_Init(); RTC_Init(); //RTC初始化 DS18B20_Init(); OLED_Init(); delay_ms(200); OLED_CLS(); OLED_P16x16Ch(40,0,36);//第一行第三列顯示年 OLED_P16x16Ch(72,0,37); //顯示月 OLED_P16x16Ch(106,0,38); //顯示日 OLED_P16x16Ch(0,6,39);//星 OLED_P16x16Ch(16,6,41);//期 OLED_P16x16Ch(32,2,34); OLED_P16x16Ch(32,4,35);//: OLED_P16x16Ch(80,2,34); OLED_P16x16Ch(80,4,35);//: while(1) { sprintf((char *)year_buf,"%04d",calendar.w_year); OLED_P8x16Str(8,0,year_buf); sprintf((char *)month_buf,"%02d",calendar.w_month); OLED_P8x16Str(58,0,month_buf); sprintf((char *)day_buf,"%02d",calendar.w_date); OLED_P8x16Str(90,0,day_buf); OLED_P16x16Ch(0,2,calendar.hour/10*2); OLED_P16x16Ch(0,4,calendar.hour/10*2+1); // OLED_P16x16Ch(16,2,calendar.hour%10*2); OLED_P16x16Ch(16,4,calendar.hour%10*2+1);// OLED_P16x16Ch(48,2,calendar.min/10*2); OLED_P16x16Ch(48,4,calendar.min/10*2+1);// OLED_P16x16Ch(64,2,calendar.min%10*2); OLED_P16x16Ch(64,4,calendar.min%10*2+1);// OLED_P16x16Ch(95,2,calendar.sec/10*2); OLED_P16x16Ch(95,4,calendar.sec/10*2+1);// OLED_P16x16Ch(111,2,calendar.sec%10*2); OLED_P16x16Ch(111,4,calendar.sec%10*2+1);// OLED_P16x16Ch(32,6,calendar.week+20);// temp = DS18B20_Get_Temp(); OLED_P16x16str(64,6,11); OLED_P16x16str(80,6,12); OLED_P16x16str(96,6,temp%1000/100); OLED_P16x16str(112,6,temp%100/10); } }
-
OLED
+關(guān)注
關(guān)注
119文章
6272瀏覽量
227186 -
STM32
+關(guān)注
關(guān)注
2290文章
11017瀏覽量
362482 -
時鐘
+關(guān)注
關(guān)注
11文章
1884瀏覽量
132859 -
程序
+關(guān)注
關(guān)注
117文章
3824瀏覽量
82451 -
RTC
+關(guān)注
關(guān)注
2文章
610瀏覽量
68341
原文標題:STM32小項目-0.96寸OLED時鐘程序,萬年歷,大字體
文章出處:【微信號:單片機與嵌入式,微信公眾號:單片機與嵌入式】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
stm32f407vet6驅(qū)動0.96寸oled,顯示屏無法顯示怎么解決?
問題 0.96寸OLED
0.96寸OLED動態(tài)顯示
在STM32 HAL庫下實現(xiàn)硬件IIC+DMA控制0.96寸 OLED屏
STM32F103ZET6 IIC驅(qū)動0.96寸OLED的方法
基于stm32的0.96寸 OLED驅(qū)動架構(gòu)模塊代碼有何功能
自制0.96寸的OLED顯示模組
STM32之0.96寸 7針 OLED顯示屏(SPI協(xié)議)驅(qū)動代碼(程序穩(wěn)定,清晰明了)

stm32103模擬0.96寸OLED驅(qū)動

評論