### Yatli automotive MCU-AT32A403A development board evaluation 05 0.96 inch OLED module display IIC interface## 1. Software and hardware platform 1. AT32A403A Board development board 2. MDK-ARM Keil 3. 0.96 inch IIC interface OLED display module [attach] 785920 [/ attach] ## 2. OLED display function support 1. OLED display characters, strings and Chinese characters ``` c void OLED_ShowChar_06x08(uint8_t X, uint8_t Y, uint8_t Char); //Display character function void OLED_ShowString_06x08(uint8_t X, uint8_t Y, uint8_t *String); //Display string function void OLED_ShowCHinese(uint8_t X,uint8_t Y,uint8_t Chinese); //Display Chinese character function void OLED_ShowChar_08x16(uint8_t X, uint8_t Y, uint8_t Char);//Display character function void OLED_ShowString_16x16(uint8_t X, uint8_t Y, uint8_t *String);//Display string function ``` 2. OLED displays integer numbers/floating point numbers/binary numbers/hexadecimal numbers```c void OLED_ShowNumber_SignedInteger_06x08(uint8_t X, uint8_t Y, int16_t IntegerNumber, uint8_t Count);//Display signed integer number function void OLED_ShowNumber_UnsignedInteger_06x08(uint8_t X, uint8_t Y, uint16_t IntegerNumber, uint8_t Count); //Display unsigned integer function void OLED_ShowNumber_Float_06x08(uint8_t X, uint8_t Y, float FloatNumber, uint8_t Count1, uint8_t Count2); //Display floating point function void OLED_ShowNumber_Binary_06x08(uint8_t X, uint8_t Y, unsigned long BinaryNumber, uint8_t Count); //Display array function void OLED_ShowNumber_Hex_06x08(uint8_t X, uint8_t Y, unsigned long BinaryNumber, uint8_t Count); //Display hexadecimal number function ``` 3. OLED basic drawing function ```c // OLED draws a straight line void OLED_DrawLine(uint8_t X, uint8_t Y, uint8_t PointData); // OLED draws image void OLED_RollDisplay(void); //Set horizontal left and right shift void Draw_BMP(uint8_t x0,uint8_t y0,uint8_t x1,uint8_t y1,uint8_t BMP[]); //Draw dot function void OLED_DrawDot(uint8_t X,uint8_t Y,uint8_t T); //Draw straight line function void LCD_DrawLine(uint32_t X1, uint32_t Y1, uint32_t X2,uint32_t Y2); //dot == 1 means bright display void OLED_Fill_Draw_circle(uint8_t X0,uint8_t Y0,uint8_t r,uint8_t dot); //ucFilled == 1 means fill //Draw straight circle function void OLED_DrawCircle( uint16_t usX_Center, uint16_t usY_Center, uint16_t usRadius, uint8_t ucFilled ); //Draw rectangle function void LCD_DrawRectangle(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2); ``` ### 3. Simulate IIC to transplant OLED screen driver 1. Create a project template and add related driver files. Add files to the previous project template. At the same time, refer to the Liangshanpai GD32F4 development board data for the OLED part of the code. olde_drive.c olde_drive.h // oled low-level driver file, including software iic implementation, oled pin configuration, oled initialization. olde_draw.c olde_draw.h // oled application layer file, mainly drawing api implementation (can be ported to other development boards, no need to change, just configure the driver file
2. Configure the pin selection pin, enter the project and start writing the screen pin initialization code. In order to facilitate subsequent porting, I have macro-defined each pin in **oled_drive.h**, and you can modify it as needed later. ```c #define OLED_GPIO_PORT GPIOA #define OLED_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK #define SCL_GPIO_PORT GPIOA #define SCL_GPIO_PIN GPIO_PINS_5 #define SCL_GPIO_CLK_ENABLE() CRM_GPIOA_PERIPH_CLOCK #define SDA_GPIO_PORT GPIOA #define SDA_GPIO_PIN GPIO_PINS_6 #define SDA_GPIO_CLK_ENABLE() CRM_GPIO_PERIPH_CLOCK ```` 3. Screen GPIO port initialization configuration```c void OLED_GPIO_Configuare(void) { gpio_init_type gpio_init_struct; /* enable the gpioa clock */ crm_periph_clock _enable(OLED_GPIO_CLOCK, TRUE); /* set default parameter */ gpio_default_para_init(&gpio_init_struct); /* configure the gpio */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; gpio_init_struct.gpio_pins = SDA_GPIO_PIN |SCL_GPIO_PIN; gpio_init_struct.gpio _pull = GPIO_PULL_NONE; gpio_init(OLED_GPIO_PORT, &gpio_init_struct); } ```` 4. IIC interface macro definition settings`` `C //-----------------OLED IIC port definition---------------- #define OLED_SCLK_Clr() gpio_bits_reset(SCL_GPIO_PORT, SCL_GPIO_PIN)//Clock signal of SCL IIC interface #define OLED_SCLK_Set() gpio_bits_set(SCL_GPIO_PORT,SCL_GPIO_PIN) #define OLED_SDIN_Clr() gpio_bits_reset(SDA_GPIO_PORT,SDA_GPIO_PIN) //SDA IIC interface data signal #define OLED_SDIN_Set() gpio_bits_set(SDA_GPIO_PORT,SDA_GPIO_PIN) ``` 5. Software IIC code implementation ```c / /================================================= ===================================================/ / Function: IIC peripheral driver function part // Function tag: IIC_Start // Function description: None//-------------------------------------------- -------------------------------------------------- --- // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //================== ================================================== ============================== void IIC_Start() { OLED_SCLK_Set() ; OLED_SDIN_Set(); OLED_SDIN_Clr(); OLED_SCLK_Clr(); } //================================================ ================================================== // Function: IIC peripheral driver function part // Function tag: IIC_Stop // Function description: None //--------------------- -------------------------------------------------- ---------------------- // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //================================================ ================================================== void IIC_Stop() { OLED_SCLK_Set() ; OLED_SDIN_Clr(); OLED_SDIN_Set(); } //============================== ================================================== =================== // Function: IIC peripheral driver function part // Function tag: IIC_Stop // Function description: None //------------------------------ -------------------------------------------------- ----------------- // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //===== ================================================== =============================================== void IIC_Wait_Ack() { OLED_SCLK_Set( ) ; OLED_SCLK_Clr(); } //================================================ ================================================== // Function: IIC peripheral driver function part // Function tag: Write_IIC_Byte // Function description:none//----------------------------------------------- -------------------------------------------------- // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //====================== ================================================== ========================== void Write_IIC_Byte(uint8_t IIC_Byte) { uint8_t i; uint8_t m,da; da=IIC_Byte; OLED_SCLK_Clr(); for (i=0;i<8;i++) { m=da; // OLED_SCLK_Clr(); m=m&0x80; if(m==0x80) { OLED_SDIN_Set(); } else OLED_SDIN_Clr(); da=da<<1; OLED_SCLK_Set(); OLED_SCLK_Clr(); } } //============= ================================================== ===================================== // Function: IIC peripheral driver function part // Function tag : Write_IIC_Command // Function description: None//---------------------------------------- -------------------------------------------------- ------- // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //================================================ ================================================== void Write_IIC_Command(uint8_t IIC_Command) { IIC_Start(); Write_IIC_Byte(0x78); //Slave address,SA0=0 IIC_Wait_Ack(); Write_IIC_Byte(0x00); //write command IIC_Wait_Ack(); Write_IIC_Byte(IIC_Command); IIC_Wait_Ack(); IIC_Stop(); } //================================================ ================================================== // Function: IIC peripheral driver function part // Function tag: Write_IIC_Data // Function description: None //------------------------- -------------------------------------------------- ---------------------- // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //================================================ ================================================== void Write_IIC_Data(uint8_t IIC_Data) { IIC_Start(); Write_IIC_Byte(0x78); //D/C#=0; R/W#=0 IIC_Wait_Ack(); Write_IIC_Byte(0x40); //write data IIC_Wait_Ack(); Write_IIC_Byte(IIC_Data ); IIC_Wait_Ack(); IIC_Stop(); } ``` 6. OLED initialization function```c //================================================ ================================================== // Function: OLED peripheral driver function part // Function tag: OLED_Init // Function description: Initialization function configuration //----------------------- -------------------------------------------------- ------------------------ // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //================================================ ================================================== void OLED_Init(void) { OLED_GPIO_Configuare(); OLED_WR_Byte(0xAE,OLED_CMD);//--display off OLED_WR_Byte(0x00,OLED_CMD);//---set low column address OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
OLED_WR_Byte(0x81,OLED_CMD); // contract control
OLED_WR_Byte(0xFF,OLED_CMD);//--128
OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
OLED_WR_Byte(0x00,OLED_CMD);//
OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
OLED_WR_Byte(0x80,OLED_CMD);//
OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
OLED_WR_Byte(0x05,OLED_CMD);//
OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
OLED_WR_Byte(0xF1,OLED_CMD);//
OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
OLED_WR_Byte(0x12,OLED_CMD);//
OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
OLED_WR_Byte(0x30,OLED_CMD);//
OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
OLED_WR_Byte(0x14,OLED_CMD);//
OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
OLED_Clear();
OLED_Set_Pos(0,0);
}
```
×ÛÉÏËùÊö£¬Èí¼þÄ£ÄâIIC Çý¶¯OLEDÎļþÍê³É£¬½ÓÏÂÀ´¾ÍÊÇÓ¦ÓòãÎļþ,¾ßÌå²Î¿¼²Ö¿â´úÂë¡£
Ä£ÄâIIC Çý¶¯OLED [Ä£ÄâIIC Çý¶¯OLED](https://gitee.com/End-ING/embedded-arterytek32-board/tree/master/note/code/at32a403_mdk_oled_iic_template/at32a403_mdk_oled_softiic_template "Ä£ÄâIIC Çý¶¯OLED")
### 4.Ó²¼þIICÒÆÖ² OLEDÆÁÄ»Çý¶¯
```c
i2c_handle_type hi2cx;
```
1. ½¨Á¢¹¤³ÌÄ£°å£¬ÔÚÈí¼þÄ£Ä⹤³ÌIIC»ù´¡ÉϽøÐÐÐ޸ģ¬Ìí¼Óºê¶¨Òå½øÐвÙ×÷
olde_drive.c olde_drive.h // oledµ×²ãÇý¶¯Îļþ£¬°üÀ¨Ó²¼þiic³õʼ»¯
olde_draw.c olde_draw.h // oledÓ¦ÓòãÎļþ£¬Ö÷ÒªÊÇ»æͼapiʵÏÖ
2. ÅäÖÃÒý½Å
Ñ¡ÔñÒý½Å£¬½øÈ빤³Ì¿ªÊ¼±àдÆÁÄ»Òý½Å³õʼ»¯´úÂë¡£
ΪÁË·½±ãºóÐøÒÆÖ²£¬ÎÒÔÚ**oled_drive.h**´¦ºê¶¨ÒåÁËÿһ¸öÒý½Å£¬ºóÐø¸ù¾ÝÐèÒª½øÐÐÐ޸ļ´¿É¡£
```c
#define I2C_TIMEOUT 0xFFFFFFFF
#define I2Cx_ADDRESS 0x78
#define I2Cx_PORT I2C1
#define I2Cx_CLK CRM_I2C1_PERIPH_CLOCK
#define I2Cx_DMA DMA1
#define I2Cx_DMA_CLK CRM_DMA1_PERIPH_CLOCK
#define I2Cx_SCL_GPIO_CLK CRM_GPIOB_PERIPH_CLOCK
#define I2Cx_SCL_GPIO_PIN GPIO_PINS_6
#define I2Cx_SCL_GPIO_PinsSource GPIO_PINS_SOURCE6
#define I2Cx_SCL_GPIO_PORT GPIOB
#define I2Cx_SCL_GPIO_MUX GPIO_MUX_4
#define I2Cx_SDA_GPIO_CLK CRM_GPIOB_PERIPH_CLOCK
#define I2Cx_SDA_GPIO_PIN GPIO_PINS_7
#define I2Cx_SDA_GPIO_PinsSource GPIO_PINS_SOURCE7
#define I2Cx_SDA_GPIO_PORT GPIOB
#define I2Cx_SDA_GPIO_MUX GPIO_MUX_4
#define I2Cx_CLKCTRL 0x10F03C6A //200K
```
3.IIC1³õʼ»¯ÅäÖÃ
```c
void I2C_Init(i2c_handle_type* hi2c)
{
/* reset i2c peripheral */
i2c_reset(hi2c->i2cx);
/* i2c peripheral initialization */
if(hi2c->i2cx == I2C1)
{
gpio_init_type gpio_init_struct;
crm_periph_clock_enable(CRM_I2C1_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
gpio_default_para_init(&gpio_init_struct);
/* configure the SCL pin */
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_pins = I2Cx_SCL_GPIO_PIN;
gpio_init(GPIOB, &gpio_init_struct);
/* configure the SDA pin */
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_pins = I2Cx_SDA_GPIO_PIN;
gpio_init(GPIOB, &gpio_init_struct);
i2c_init(I2C1, I2C_FSMODE_DUTY_2_1, 100000);
i2c_own_address1_set(I2C1, I2C_ADDRESS_MODE_7BIT, 0x00);
i2c_ack_enable(I2C1, TRUE);
i2c_clock_stretch_enable(I2C1, TRUE);
i2c_general_call_enable(I2C1, FALSE);
i2c_enable(I2C1, TRUE);
}
}
```
4. i2c_config_init
```c
static void i2c_config_init(void)
{
hi2cx.i2cx = I2C1;
I2C_Init(&hi2cx);
}
```
5. ÐÞ¸ÄWrite_IIC_Byte£¬Write_IIC_Data£¬Write_IIC_Commandº¯Êý
IIC_Config Çл»ÈíÓ²¼þIIC
```c
#defineIIC_Config0 //IIC_Config=0 ʹÓÃÓ²¼þIICIIC_Config=1 ʹÓÃÈí¼þIIC
```
```c
//==================================================================================================
//º¯Êý¹¦ÄÜ: IICÍâÉèÇý¶¯º¯Êý²¿·Ö
//º¯Êý±ê¼Ç: Write_IIC_Byte
//º¯Êý˵Ã÷: ÎÞ
//-------------------------------------------------------------------------------------------------
//| - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//==================================================================================================
void Write_IIC_Byte(uint8_t IIC_Byte)
{
i2c_status_type i2c_status;
#if IIC_Config
uint8_t i;
uint8_t m,da; da=IIC_Byte; OLED_SCLK_Clr(); for(i=0;i<8;i++) { m=da; // OLED_SCLK_Clr(); m=m&0x80; if(m==0x80) { OLED_SDIN_Set(); } else OLED_SDIN_Clr(); da=da<<1; delay_us(3); OLED_SCLK_Set(); delay_us(3); OLED_SCLK_Clr(); delay_us(3); } #else uint8_t buff[2] = {0}; buff[ 0] = IIC_Byte; i2c_status = i2c_master_transmit(&hi2cx, I2Cx_ADDRESS, buff, 1, 1000); if(i2c_status != I2C_OK) { printf("erro send %d",i2c_status); } #endif } //===================================== ================================================== =========== // Function function: IIC peripheral driver function part // Function tag: Write_IIC_Command // Function description: None //-------------- -------------------------------------------------- --------------------------------- // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //================================================ ================================================== void Write_IIC_Command(uint8_t IIC_Command) { i2c_status_type i2c_status; #if IIC_Config IIC_Start(); Write_IIC_Byte(0x78); //Slave address,SA0=0 IIC_Wait_Ack(); Write_IIC_Byte(0x00); //write command IIC_Wait_Ack(); te(IIC_Command ); IIC_Wait_Ack(); IIC_Stop(); #else uint8_t buff[2] = {0}; buff[0] = 0x00; buff[1] = IIC_Command; i2c_status = i2c_master_transmit(&hi2cx, I2Cx_ADDRESS, buff, 2, 1000); if(i2c_status != I2C_OK) { printf(" erro send %d",i2c_status); } #endif } //=================================== ================================================== ============== // Function: IIC peripheral driver function part // Function tag: Write_IIC_Data // Function description: None //---------------------------------------- -------------------------------------------------- ------ // | - | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 //================ ================================================== ================================ void Write_IIC_Data(uint8_t IIC_Data) { i2c_status_type i2c_status; #if IIC_Config IIC_Start(); Write_IIC_Byte (0x78); //D/C#=0; R/W#=0 IIC_Wait_Ack(); Write_IIC_Byte(0x40); //write data IIC_Wait_Ack(); Write_IIC_Byte(IIC_Data); IIC_Wait_Ack(); IIC_Stop(); #else uint8_t buff[2] = {0}; buff[0] = 0x40; buff[1] = IIC_Data; i2c_status = i2c_master_transmit(&hi2cx, I2Cx_ADDRESS, buff, 2,1000); if(i2c_status != I2C_OK) { printf("erro send %d",i2c_status); } #endif } ``` 6. OLED initialization```c void OLED_Init(void) { #if IIC_Config OLED_GPIO_Configuare(); //Software IIC use#else i2c_config_init(); //Hardware IIC use#endif OLED_WR_Byte(0xAE,OLED_CMD);//--display off ....initialization code omitted} ``` [Hardware IIC drive OLED](https://gitee.com/End-ING/embedded-arterytek32-board/tree/master/note/code/at32a403_mdk_oled_iic_template/at32a403_mdk_oled_hardiic_template "Hardware IIC drive OLED") ### 5. Case test 1. Main function ```c #include "main.h" /** @addtogroup AT32A403A_periph_examples * @{ */ /** @addtogroup 403A_USART_printf USART_printf * @{ */ //__IO uint32_t time_cnt = 0; void oled_example(void) { OLED_ShowChar_08x16(0,0,'A '); OLED_ShowString_08x16(16,0,"AT32A403A-OLED"); // OLED_ShowNumber_SignedInteger_06x08(16,2,1234,5); // OLED_ShowNumber_UnsignedInteger_06x08(64,2,1234,4); OLED_ShowString_08x16(0,2,"Time:2024.02.13"); OLED_ShowNumber_Float_06x08(32,4,123.456,3,3); OLED_ShowString_06x08(32,5,"By:CoderEnd"); OLED_ShowCHinese(0,6,13); OLED_ShowCHinese (16,6,14); OLED_ShowCHinese(32,6,15); OLED_ShowCHinese(48,6,16); OLED_ShowCHinese(64,6,17); #if IIC_Config OLED_ShowString_06x08(80,6,"soft-iic"); #else OLED_ShowString_06x08(80,6,"hard- iic"); #endif } /** * @brief main function. * @param none * @retval none */ int main(void) { // unsigned char count_num; system_clock_config(); at32_board_init(); uart_print_init(115200); module_smg_gpio_iint(); OLED_Init(); /* output a message on hyperterminal using printf function */ //printf("usart printf example: retarget the c library printf function to the usart\r\n"); printf("Hardware_Init [ok] \r\n"); printf("at_start_a403a board testing 2024-02-12\r\n"); printf("at_start_a403a board module hardiic oled \r\n"); OLED_Clear(); printf("oled_example_test [ok] \r\n"); oled_example(); while(1) { } } ``` 2. Test results Software IIC
Hardware IIC
com/End-ING/embedded-arterytek32-board/tree/master/note/code/at32a403_mdk_oled_iic_template/at32a403_mdk_oled_hardiic_template "Ó²¼þIIC Çý¶¯OLED")
### 5.°¸Àý²âÊÔ
1. Ö÷º¯Êý
```c
#include "main.h"
/** @addtogroup AT32A403A_periph_examples
* @{
*/
/** @addtogroup 403A_USART_printf USART_printf
* @{
*/
//__IO uint32_t time_cnt = 0;
void oled_example(void)
{
OLED_ShowChar_08x16(0,0,'A');
OLED_ShowString_08x16(16,0,"AT32A403A-OLED");
// OLED_ShowNumber_SignedInteger_06x08(16,2,1234,5);
// OLED_ShowNumber_UnsignedInteger_06x08(64,2,1234,4);
OLED_ShowString_08x16(0,2,"Time:2024.02.13");
OLED_ShowNumber_Float_06x08(32,4,123.456,3,3);
OLED_ShowString_06x08(32,5,"By:CoderEnd");
OLED_ShowCHinese(0,6,13);
OLED_ShowCHinese(16,6,14);
OLED_ShowCHinese(32,6,15);
OLED_ShowCHinese(48,6,16);
OLED_ShowCHinese(64,6,17);
#if IIC_Config
OLED_ShowString_06x08(80,6,"soft-iic");
#else
OLED_ShowString_06x08(80,6,"hard-iic");
#endif
}
/**
* @briefmain function.
* @paramnone
* @retval none
*/
int main(void)
{
//unsigned char count_num;
system_clock_config();
at32_board_init();
uart_print_init(115200);
module_smg_gpio_iint();
OLED_Init();
/* output a message on hyperterminal using printf function */
//printf("usart printf example: retarget the c library printf function to the usart\r\n");
printf("Hardware_Init [ok] \r\n");
printf("at_start_a403a board testing 2024-02-12\r\n");
printf("at_start_a403a board module hardiic oled \r\n");
OLED_Clear();
printf("oled_example_test [ok] \r\n");
oled_example();
while(1)
{
}
}
```
2. ²âÊÔЧ¹û
Èí¼þIIC
Ó²¼þIIC
com/End-ING/embedded-arterytek32-board/tree/master/note/code/at32a403_mdk_oled_iic_template/at32a403_mdk_oled_hardiic_template "Ó²¼þIIC Çý¶¯OLED")
### 5.°¸Àý²âÊÔ
1. Ö÷º¯Êý
```c
#include "main.h"
/** @addtogroup AT32A403A_periph_examples
* @{
*/
/** @addtogroup 403A_USART_printf USART_printf
* @{
*/
//__IO uint32_t time_cnt = 0;
void oled_example(void)
{
OLED_ShowChar_08x16(0,0,'A');
OLED_ShowString_08x16(16,0,"AT32A403A-OLED");
// OLED_ShowNumber_SignedInteger_06x08(16,2,1234,5);
// OLED_ShowNumber_UnsignedInteger_06x08(64,2,1234,4);
OLED_ShowString_08x16(0,2,"Time:2024.02.13");
OLED_ShowNumber_Float_06x08(32,4,123.456,3,3);
OLED_ShowString_06x08(32,5,"By:CoderEnd");
OLED_ShowCHinese(0,6,13);
OLED_ShowCHinese(16,6,14);
OLED_ShowCHinese(32,6,15);
OLED_ShowCHinese(48,6,16);
OLED_ShowCHinese(64,6,17);
#if IIC_Config
OLED_ShowString_06x08(80,6,"soft-iic");
#else
OLED_ShowString_06x08(80,6,"hard-iic");
#endif
}
/**
* @briefmain function.
* @paramnone
* @retval none
*/
int main(void)
{
//unsigned char count_num;
system_clock_config();
at32_board_init();
uart_print_init(115200);
module_smg_gpio_iint();
OLED_Init();
/* output a message on hyperterminal using printf function */
//printf("usart printf example: retarget the c library printf function to the usart\r\n");
printf("Hardware_Init [ok] \r\n");
printf("at_start_a403a board testing 2024-02-12\r\n");
printf("at_start_a403a board module hardiic oled \r\n");
OLED_Clear();
printf("oled_example_test [ok] \r\n");
oled_example();
while(1)
{
}
}
```
2. ²âÊÔЧ¹û
Èí¼þIIC
Ó²¼þIIC
* @paramnone
* @retval none
*/
int main(void)
{
//unsigned char count_num;
system_clock_config();
at32_board_init();
uart_print_init(115200);
module_smg_gpio_iint();
OLED_Init();
/* output a message on hyperterminal using printf function */
//printf("usart printf example: retarget the c library printf function to the usart\r\n");
printf("Hardware_Init [ok] \r\n");
printf("at_start_a403a board testing 2024-02-12\r\n");
printf("at_start_a403a board module hardiic oled \r\n");
OLED_Clear();
printf("oled_example_test [ok] \r\n");
oled_example();
while(1)
{
}
}
```
2. ²âÊÔЧ¹û
Èí¼þIIC
Ó²¼þIIC
* @paramnone
* @retval none
*/
int main(void)
{
//unsigned char count_num;
system_clock_config();
at32_board_init();
uart_print_init(115200);
module_smg_gpio_iint();
OLED_Init();
/* output a message on hyperterminal using printf function */
//printf("usart printf example: retarget the c library printf function to the usart\r\n");
printf("Hardware_Init [ok] \r\n");
printf("at_start_a403a board testing 2024-02-12\r\n");
printf("at_start_a403a board module hardiic oled \r\n");
OLED_Clear();
printf("oled_example_test [ok] \r\n");
oled_example();
while(1)
{
}
}
```
2. ²âÊÔЧ¹û
Èí¼þIIC
Ó²¼þIIC