Introduction to STM32 OLED and keil debugging

  1. Commonly used program debugging methods

•Serial port debugging: send debugging information to the computer through serial port communication, and the computer uses the serial port assistant to display the debugging information

•Display debugging: directly connect the display to the microcontroller, and print the debugging information on the display

• Keil debugging mode: With the help of Keil software debugging mode, you can use functions such as single-step operation, setting breakpoints, viewing registers and variables, etc.

2. Introduction to OLED

• OLED: Organic Light Emitting Diode

• OLED display screen: a new type of display screen with excellent performance, featuring low power consumption, fast response speed, wide viewing angle, thinness and flexibility, etc.

• 0.96-inch OLED module: small and exquisite, occupying less interface, easy to use, it is a very common display module in electronic design

•Power supply: 3~5.5V, communication protocol: I2C/SPI, resolution: 128*64

3. Hardware circuit

  • I2C communication

  • SPI communication

4. OLED driving function

4.1 Screen Coordinate Map

4.2 OLED driving function

5. Hardware connection

The VCC and GND power supply ports can be connected to the PB6 and PB7 pins of the stm32, or can directly output a low level to the PB6 port, and a high level to the PB7 port, and use the GPIO port to directly supply power to the OLED.

6. Programming

6.1 Design ideas

This design adopts modular programming, which is divided into four parts: OLED.c, OLED.h, OLED_Font.h, mian.c

OLED.c: function body code, including pin configuration, pin i initialization, basic timing of I2C communication, oled user call code, etc.

OLED.h: Declaration of external callable functions

OLED_Font.h: OLED font data

mian.c: call the function to realize the function

6.2 Program display

  • OLED.c

#include "stm32f10x.h"
#include "OLED_Font.h"

/*pin configuration*/
//SCL and SDA are respectively connected to GPIOB, GPIO_Pin_8 GPIOB, GPIO_Pin_9
#define OLED_W_SCL(x)        GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction)(x))
#define OLED_W_SDA(x)        GPIO_WriteBit(GPIOB, GPIO_Pin_9, (BitAction)(x))

/*Pin initialization*/
void OLED_I2C_Init(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    
    GPIO_InitTypeDef GPIO_InitStructure;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;//Initialized as an open-drain output
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
     GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
     GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    OLED_W_SCL(1);
    OLED_W_SDA(1);
}

/**
  * @brief  I2C start
  * @param  none
  * @retval none
  */
void OLED_I2C_Start(void)
{
    OLED_W_SDA(1);
    OLED_W_SCL(1);
    OLED_W_SDA(0);
    OLED_W_SCL(0);
}

/**
  * @brief  I2C stop
  * @param  none
  * @retval none
  */
void OLED_I2C_Stop(void)
{
    OLED_W_SDA(0);
    OLED_W_SCL(1);
    OLED_W_SDA(1);
}

/**
  * @brief  I2C send a byte
  * @param  Byte a byte to send
  * @retval none
  */
void OLED_I2C_SendByte(uint8_t Byte)
{
    uint8_t i;
    for (i = 0; i < 8; i++)
    {
        OLED_W_SDA(Byte & (0x80 >> i));
        OLED_W_SCL(1);
        OLED_W_SCL(0);
    }
    OLED_W_SCL(1);    //One additional clock, does not process the acknowledge signal
    OLED_W_SCL(0);
}

/**
  * @brief  OLED write command
  * @param  Command command to write
  * @retval none
  */
void OLED_WriteCommand(uint8_t Command)
{
    OLED_I2C_Start();
    OLED_I2C_SendByte(0x78);        //slave address
    OLED_I2C_SendByte(0x00);        //write command
    OLED_I2C_SendByte(Command); 
    OLED_I2C_Stop();
}

/**
  * @brief  OLED write data
  * @param  Data data to write
  * @retval none
  */
void OLED_WriteData(uint8_t Data)
{
    OLED_I2C_Start();
    OLED_I2C_SendByte(0x78);        //slave address
    OLED_I2C_SendByte(0x40);        //write data
    OLED_I2C_SendByte(Data);
    OLED_I2C_Stop();
}

/**
  * @brief  OLED set cursor position
  * @param  Y Taking the upper left corner as the origin, the coordinates in the downward direction, range: 0~7
  * @param  X Taking the upper left corner as the origin, the coordinates in the right direction, range: 0~127
  * @retval none
  */
void OLED_SetCursor(uint8_t Y, uint8_t X)
{
    OLED_WriteCommand(0xB0 | Y);                    //set Y position
    OLED_WriteCommand(0x10 | ((X & 0xF0) >> 4));    //Set the upper 4 bits of the X position
    OLED_WriteCommand(0x00 | (X & 0x0F));            //Set the lower 4 bits of the X position
}

/**
  * @brief  OLED clear screen
  * @param  none
  * @retval none
  */
void OLED_Clear(void)
{  
    uint8_t i, j;
    for (j = 0; j < 8; j++)
    {
        OLED_SetCursor(j, 0);
        for(i = 0; i < 128; i++)
        {
            OLED_WriteData(0x00);
        }
    }
}

/**
  * @brief  OLED show a character
  * @param  Line Row position, range: 1~4
  * @param  Column Column position, range: 1~16
  * @param  Char A character to display, range: ASCII visible characters
  * @retval none
  */
void OLED_ShowChar(uint8_t Line, uint8_t Column, char Char)
{          
    uint8_t i;
    OLED_SetCursor((Line - 1) * 2, (Column - 1) * 8);        //Set the cursor position in the upper half
    for (i = 0; i < 8; i++)
    {
        OLED_WriteData(OLED_F8x16[Char - ' '][i]);            //Show top half content
    }
    OLED_SetCursor((Line - 1) * 2 + 1, (Column - 1) * 8);    //Set the cursor position in the lower half
    for (i = 0; i < 8; i++)
    {
        OLED_WriteData(OLED_F8x16[Char - ' '][i + 8]);        //Show the bottom half of the content
    }
}

/**
  * @brief  OLED display string
  * @param  Line Starting line position, range: 1~4
  * @param  Column The starting column position, range: 1~16
  * @param  String String to display, range: ASCII visible characters
  * @retval none
  */
void OLED_ShowString(uint8_t Line, uint8_t Column, char *String)
{
    uint8_t i;
    for (i = 0; String[i] != '\0'; i++)
    {
        OLED_ShowChar(Line, Column + i, String[i]);
    }
}

/**
  * @brief  OLED power function
  * @retval The return value is equal to the Y power of X
  */
uint32_t OLED_Pow(uint32_t X, uint32_t Y)
{
    uint32_t Result = 1;
    while (Y--)
    {
        Result *= X;
    }
    return Result;
}

/**
  * @brief  OLED display number (decimal, positive)
  * @param  Line Starting line position, range: 1~4
  * @param  Column The starting column position, range: 1~16
  * @param  Number The number to be displayed, range: 0~4294967295
  * @param  Length The length of the number to be displayed, range: 1~10
  * @retval none
  */
void OLED_ShowNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length)
{
    uint8_t i;
    for (i = 0; i < Length; i++)                            
    {
        OLED_ShowChar(Line, Column + i, Number / OLED_Pow(10, Length - i - 1) % 10 + '0');
    }
}

/**
  * @brief  OLED Display numbers (decimal, signed)
  * @param  Line Starting line position, range: 1~4
  * @param  Column The starting column position, range: 1~16
  * @param  Number Number to be displayed, range: -2147483648~2147483647
  * @param  Length The length of the number to be displayed, range: 1~10
  * @retval none
  */
void OLED_ShowSignedNum(uint8_t Line, uint8_t Column, int32_t Number, uint8_t Length)
{
    uint8_t i;
    uint32_t Number1;
    if (Number >= 0)
    {
        OLED_ShowChar(Line, Column, '+');
        Number1 = Number;
    }
    else
    {
        OLED_ShowChar(Line, Column, '-');
        Number1 = -Number;
    }
    for (i = 0; i < Length; i++)                            
    {
        OLED_ShowChar(Line, Column + i + 1, Number1 / OLED_Pow(10, Length - i - 1) % 10 + '0');
    }
}

/**
  * @brief  OLED display number (hexadecimal, positive)
  * @param  Line Starting line position, range: 1~4
  * @param  Column The starting column position, range: 1~16
  * @param  Number Number to be displayed, range: 0~0xFFFFFFFF
  * @param  Length The length of the number to be displayed, range: 1~8
  * @retval none
  */
void OLED_ShowHexNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length)
{
    uint8_t i, SingleNumber;
    for (i = 0; i < Length; i++)                            
    {
        SingleNumber = Number / OLED_Pow(16, Length - i - 1) % 16;
        if (SingleNumber < 10)
        {
            OLED_ShowChar(Line, Column + i, SingleNumber + '0');
        }
        else
        {
            OLED_ShowChar(Line, Column + i, SingleNumber - 10 + 'A');
        }
    }
}

/**
  * @brief  OLED Display numbers (binary, positive)
  * @param  Line Starting line position, range: 1~4
  * @param  Column The starting column position, range: 1~16
  * @param  Number Number to be displayed, range: 0~1111 1111 1111 1111
  * @param  Length The length of the number to be displayed, range: 1~16
  * @retval none
  */
void OLED_ShowBinNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length)
{
    uint8_t i;
    for (i = 0; i < Length; i++)                            
    {
        OLED_ShowChar(Line, Column + i, Number / OLED_Pow(2, Length - i - 1) % 2 + '0');
    }
}

/**
  * @brief  OLED initialization
  * @param  none
  * @retval none
  */
void OLED_Init(void)
{
    uint32_t i, j;
    
    for (i = 0; i < 1000; i++)            //power on delay
    {
        for (j = 0; j < 1000; j++);
    }
    
    OLED_I2C_Init();            //port initialization
    
    OLED_WriteCommand(0xAE);    //turn off display
    
    OLED_WriteCommand(0xD5);    //Set Display Clock Divider Ratio/Oscillator Frequency
    OLED_WriteCommand(0x80);
    
    OLED_WriteCommand(0xA8);    //Set multiplexing rate
    OLED_WriteCommand(0x3F);
    
    OLED_WriteCommand(0xD3);    //set display offset
    OLED_WriteCommand(0x00);
    
    OLED_WriteCommand(0x40);    //Set display start line
    
    OLED_WriteCommand(0xA1);    //Set the left and right directions, 0xA1 is normal, 0xA0 is left and right reversed
    
    OLED_WriteCommand(0xC8);    //Set the up and down direction, 0xC8 is normal, 0xC0 is up and down

    OLED_WriteCommand(0xDA);    //Set COM pin hardware configuration
    OLED_WriteCommand(0x12);
    
    OLED_WriteCommand(0x81);    //Set Contrast Control
    OLED_WriteCommand(0xCF);

    OLED_WriteCommand(0xD9);    //Set the precharge cycle
    OLED_WriteCommand(0xF1);

    OLED_WriteCommand(0xDB);    //Set VCOMH deselection level
    OLED_WriteCommand(0x30);

    OLED_WriteCommand(0xA4);    //Set entire display on/off

    OLED_WriteCommand(0xA6);    //Set normal/reverse display

    OLED_WriteCommand(0x8D);    //Set up the charge pump
    OLED_WriteCommand(0x14);

    OLED_WriteCommand(0xAF);    //turn on display
        
    OLED_Clear();                //OLED clear screen
}
  • OLED.h

#ifndef __OLED_H
#define __OLED_H

void OLED_Init(void);
void OLED_Clear(void);
void OLED_ShowChar(uint8_t Line, uint8_t Column, char Char);
void OLED_ShowString(uint8_t Line, uint8_t Column, char *String);
void OLED_ShowNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length);
void OLED_ShowSignedNum(uint8_t Line, uint8_t Column, int32_t Number, uint8_t Length);
void OLED_ShowHexNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length);
void OLED_ShowBinNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length);

#endif
  • OLED_Font.h

#ifndef __OLED_FONT_H
#define __OLED_FONT_H

/*OLED font library, width 8 pixels, height 16 pixels*/
const uint8_t OLED_F8x16[][16]=
{
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//  0
    
    0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
    
    0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
    
    0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,
    0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
    
    0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,
    0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
    
    0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,
    0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
    
    0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,
    0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
    
    0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
    
    0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,
    0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
    
    0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,
    0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
    
    0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,
    0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
    
    0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,
    0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
    
    0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,
    0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
    
    0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
    0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
    
    0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
    0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
    
    0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
    0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
    
    0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
    0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
    
    0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
    0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
    
    0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
    0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
    
    0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
    0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
    
    0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
    0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
    
    0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
    0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
    
    0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
    0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
    
    0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
    0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
    
    0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,
    0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
    
    0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,
    0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
    
    0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
    0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
    
    0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,
    0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
    
    0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,
    0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
    
    0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,
    0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
    
    0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,
    0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
    
    0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,
    0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
    
    0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,
    0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
    
    0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,
    0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
    
    0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
    0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
    
    0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,
    0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
    
    0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,
    0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
    
    0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
    0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
    
    0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,
    0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
    
    0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,
    0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
    
    0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,
    0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
    
    0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,
    0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
    
    0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,
    0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
    
    0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,
    0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
    
    0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
    0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
    
    0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,
    0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
    
    0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
    0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
    
    0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,
    0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
    
    0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,
    0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
    
    0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,
    0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
    
    0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,
    0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
    
    0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,
    0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
    
    0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,
    0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
    
    0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,
    0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
    
    0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,
    0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
    
    0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,
    0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
    
    0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,
    0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
    
    0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
    
    0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,
    0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
    
    0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
    
    0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
    
    0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
    0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
    
    0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,
    0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
    
    0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
    0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
    
    0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,
    0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
    
    0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
    0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
    
    0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,
    0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
    
    0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
    0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
    
    0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,
    0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
    
    0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,
    0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
    
    0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,
    0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
    
    0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,
    0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
    
    0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,
    0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
    
    0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
    0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
    
    0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,
    0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
    
    0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
    0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
    
    0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,
    0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
    
    0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,
    0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
    
    0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
    0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
    
    0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,
    0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
    
    0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,
    0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
    
    0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,
    0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
    
    0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
    0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
    
    0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,
    0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
    
    0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
    0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
    
    0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
    0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
    
    0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
    0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
    
    0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,
    0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
    
    0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
    
    0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,
    0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
    
    0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};

#endif
  • main.c

#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"

int main(void)
{
    OLED_Init();
    
    OLED_ShowChar(1, 1, 'A');// 1 line and 1 column display the character A, and the character is enclosed in single quotation marks
    OLED_ShowString(1, 3, "HelloWorld!");// 1 line and 3 columns display the string HelloWorld!, the string is enclosed in double quotes
    OLED_ShowNum(2, 1, 12345, 5);//2 rows and 1 column, displaying unsigned decimal numbers, 12345, length 5
    OLED_ShowSignedNum(2, 7, -66, 2);//2 rows and 7 columns, displaying the signed decimal number -66, with a length of 2
    OLED_ShowHexNum(3, 1, 0xAA55, 4);//3 rows and 1 column display the hexadecimal number OxAA55, the length is 4
    OLED_ShowBinNum(4, 1, 0xAA55, 16);//4 rows and 1 column display the binary number 0xAA55, the length is 16
    
    while (1)
    {
        
    }
}

7. keil debug mode

Discover how the program works step-by-step through the debug mode.

These four are

Single-step operation, skip the current line single-step operation, step out of the current function single-step operation, jump to the cursor-specified line single-step operation, through these we can explore how the program runs step by step.

over

Tags: Embedded system stm32 Single-Chip Microcomputer

Posted by champrock on Fri, 10 Mar 2023 02:27:23 +1030