3039 views|1 replies

1452

Posts

1

Resources
The OP
 

[National Technology N32G457 Review] OLED screen display driver and RTC electronic clock [Copy link]

 This post was last edited by jinglixixi on 2022-2-10 09:57

There are many types of OLED screens. According to the interface mode, they can be divided into I2C interface and SPI interface mode. According to the color, they can be divided into single color, dual color and full color. In addition, according to the geometric size, there are specifications such as 0.91 inches and 0.96 inches.

Here we introduce a 0.96-inch dual-color display screen that drives the I2C interface. Since there are two ways to implement it, hardware and software, only the software method is used here.

The connection relationship between the display screen and the development board is:

CLK---PE2

DIN---PE4

The statements defined to achieve high and low level output are:

#define OLED_SCLK_Clr() GPIOE->PBC = GPIO_PIN_2

#define OLED_SCLK_Set() GPIOE->PBSC = GPIO_PIN_2

#define OLED_SDIN_Clr() GPIOE->PBC = GPIO_PIN_4

#define OLED_SDIN_Set() GPIOE->PBSC = GPIO_PIN_4

The function to set the relevant pin as output function is:

void OLEDInit(void)
{
 GPIO_InitType GPIO_InitStructure;
 RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOE, ENABLE);
 GPIO_InitStructure.Pin = GPIO_PIN_2|GPIO_PIN_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitPeripheral(GPIOE, &GPIO_InitStructure);
}

The function to implement I2C start and stop is:

void IIC_Start()
{
 OLED_SCLK_Set();
 Delayus(2);
 OLED_SDIN_Set();
 Delayus(2);
 OLED_SDIN_Clr();
 Delayus(2);
 OLED_SCLK_Clr();
 Delayus(2);
}

void IIC_Stop()
{
  OLED_SCLK_Set();
 Delayus(2);
 OLED_SDIN_Clr();
 Delayus(2);
 OLED_SDIN_Set();
 Delayus(2);
}

The initialization function of the display is:

void OLED_Init(void)
{
 OLED_SCLK_Set();
 OLED_SDIN_Set();
 Delayms(800);
 OLED_WR_Byte(0xAE,OLED_CMD);
 OLED_WR_Byte(0x02,OLED_CMD);
 OLED_WR_Byte(0x10,OLED_CMD);
 OLED_WR_Byte(0x40,OLED_CMD);
 OLED_WR_Byte(0x81,OLED_CMD);
 OLED_WR_Byte(0xff,OLED_CMD);
 OLED_WR_Byte(0xA1,OLED_CMD);
 OLED_WR_Byte(0xC8,OLED_CMD);
 OLED_WR_Byte(0xA6,OLED_CMD);
 OLED_WR_Byte(0xA8,OLED_CMD);
 OLED_WR_Byte(0x3f,OLED_CMD);
 OLED_WR_Byte(0xD3,OLED_CMD);
 OLED_WR_Byte(0x00,OLED_CMD);
 OLED_WR_Byte(0xd5,OLED_CMD);
 OLED_WR_Byte(0x80,OLED_CMD);
 OLED_WR_Byte(0xD9,OLED_CMD);
 OLED_WR_Byte(0xF1,OLED_CMD);
 OLED_WR_Byte(0xDA,OLED_CMD);
 OLED_WR_Byte(0x12,OLED_CMD);
 OLED_WR_Byte(0xDB,OLED_CMD);
 OLED_WR_Byte(0x40,OLED_CMD);
 OLED_WR_Byte(0x20,OLED_CMD);
 OLED_WR_Byte(0x02,OLED_CMD);
 OLED_WR_Byte(0x8D,OLED_CMD);
 OLED_WR_Byte(0x14,OLED_CMD);
 OLED_WR_Byte(0xA4,OLED_CMD)
 OLED_WR_Byte(0xA6,OLED_CMD);
 OLED_WR_Byte(0xAF,OLED_CMD);
 OLED_WR_Byte(0xAF,OLED_CMD);
}

The function that implements string display is:

void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size)
{
 unsigned char j=0;
 while (chr[j]!='\0')
 { 
            OLED_ShowChar(x,y,chr[j],Char_Size);
 x+=8;
 if(x>120)
 {
 x=0;
 y+=2;
 }
 j++;
 }
}

The main program to achieve the graphic effect is:

int main(void)
{
 LedInit(PORT_GROUP2, LED3_PIN);
 OLEDInit();
 OLED_Init();
 OLED_Clear();
 OLED_ShowString(20,0,"N32G457 ",16);
 OLED_ShowString(20,2,"OLED TEST",16);
 while (1)
 {

  LedBlink(PORT_GROUP2, LED3_PIN);
 Delay(0x28FFFF);
 }
}

After compilation and downloading, the display effect is shown in Figure 1.

Figure 1 OLED screen display effect

Based on this display function, the electronic clock function can be realized by combining it with the RTC timer.

The function to realize date display is:

void RTC_DateShowP(void)
{
 RTC_DateType RTC_DateStructure;
 RTC_GetDate(RTC_FORMAT_BIN, &RTC_DateStructure);
  OLED_ShowNum(36,4,RTC_DateStructure.Year,2,16);
  OLED_ShowNum(60,4,RTC_DateStructure.Month,2,16);
  OLED_ShowNum(84,4,RTC_DateStructure.Date,2,16);
}

The function that realizes the design display is:

void RTC_TimeShowP(void)
{
 RTC_TimeType RTC_TimeStructure;
  RTC_GetTime(RTC_FORMAT_BIN, &RTC_TimeStructure);
 OLED_ShowNum(20,6,RTC_TimeStructure.Hours,2,16);
 OLED_ShowNum(44,6,RTC_TimeStructure.Minutes,2,16);
 OLED_ShowNum(68,6,RTC_TimeStructure.Seconds,2,16);
 (void)RTC->DATE;
}

The main program to implement the RTC electronic clock is:

int main(void)
{
 LEDInit(LED1_PORT,LED1_PIN);
 LEDOff(LED1_PORT,LED1_PIN);
 OLEDInit();
 OLED_Init();
 OLED_Clear();
 OLED_ShowString(20,0,"N32G457 ",16);
 OLED_ShowString(20,2,"OLED & RTC",16);
 OLED_ShowString(20,4,"20 - -",16);
 OLED_ShowString(20,6," : :",16);
 RTC_DateAndTimeDefaultVale();
 RTC_CLKSourceConfig(RTC_CLK_SRC_TYPE_LSE, true, true);
 RTC_PrescalerConfig();
 RTC_DateRegulate();
 RTC_TimeRegulate();
 RTC_ConfigCalibOutput(RTC_CALIB_OUTPUT_1HZ);
 RTC_ConfigOutputType(RTC_OUTPUT_PUSHPULL);
 RTC_EnableCalibOutput(ENABLE);
 EXTI_PB8_TimeStamp_Configuration();
 EXTI20_TimeStampIRQn_Configuration(EXTI_Trigger_Falling);
 RTC_ClrFlag(RTC_FLAG_TISF);
 RTC_ClrFlag(RTC_FLAG_TISOVF);
 RTC_EnableTimeStamp(RTC_TIMESTAMP_EDGE_FALLING, ENABLE);
 while (1)
 {
 if (RTC_GetFlagStatus(RTC_FLAG_TISF) != RESET)
 {
  RTC_DateShowP();
  RTC_TimeShowP();
   RTC_ClrFlag(RTC_FLAG_TISF);
 RTC_ClrFlag(RTC_FLAG_TISOVF);
 }
 LEDBlink(LED1_PORT,LED1_PIN);
  SysTick_Delay_Ms(1000);
 }
}

After compilation and downloading, when PC13 and PB8 are connected, the display effect of the RTC electronic clock is shown in Figure 2 and Figure 3.

Figure 2 Electronic clock timing effect 1

Figure 3 Electronic clock timing effect 2

This post is from Domestic Chip Exchange

Latest reply

demo  Details Published on 2023-4-3 09:04
 
 

110

Posts

0

Resources
2
 

demo


This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
MATLAB APP Designer serial port debugging tool writing

This post was last edited by lb8820265 on 2019-5-9 23:11 Previously, we introduced two ways to use VC6 to make serial ...

About the original picture and packaging

Does anyone have the original picture and package of STM32F103 series?

How to use CPLD to collect asynchronous signals

Scenario: Use CPLD to decode a serial data channel. The data has no accompanying clock and has a fixed frequency but a d ...

Measuring poles and zeros from a Bode plot

This post was last edited by Jack315 on 2021-1-25 00:52 The transfer function of a single zero is: 522846 The Bode plot ...

Encoder counting principle and motor speed measurement principle - multi-picture analysis

This post was last edited by DDZZ669 on 2021-2-14 23:30 Encoder is a sensor used to measure mechanical rotation or displ ...

35 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (Realizing Hello World)

The best way to learn ROS is to use it. The ROS official website has a Chinese version of the tutorial . After install ...

36 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (VSCode to Implement Hello World)

It is very convenient to run ROS projects in VSCode. In this section, we use ROS to write and run the "Hello world" pro ...

[The strongest open source] Hand-rubbed 120W switching power supply

I recently took the time to make a switching power supply 645265 645262 645263 645264 645261 645260

Record a blue screen pit

I mentioned a while ago that my company's computers would occasionally blue screen. Now I think about it, the blue scree ...

ESP8266 01+DHT11 acquisition

Could anyone give me some advice? When I collect DHT11 data through one of GPIO 0 and 2, the 8266 01 keeps restarting. O ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list