基于STM32的0.96寸OLED时钟程序

您所在的位置:网站首页 stm32驱动oled教程 基于STM32的0.96寸OLED时钟程序

基于STM32的0.96寸OLED时钟程序

2023-05-31 11:12| 来源: 网络整理| 查看: 265

用的是stm32自带的RTC时钟。硬件连接很简单,当然程序也是比较简单的,只写了温度(DS18B20),stm32自带RTC和OLED显示,大家可自行删改功能。

硬件连接:

SDA --》PB13

SCL --》PB12

DS18B20----》PA15

OLED和DS18B20直接5V供电就成,效果如下:

044af910-ed43-11ed-90ce-dac502259ad0.png

单片机源程序如下:

#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);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级

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);

        }

}



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3