#include "stm32f1xx.h" // Device header #include "oled.h" /*????*/ #define SCL_Type GPIOB #define SDA_Type GPIOB #define SCL_GPIO GPIO_PIN_6 #define SDA_GPIO GPIO_PIN_7 //?????????? #define SDA_OUT(X) if(X) \ HAL_GPIO_WritePin(SDA_Type, SDA_GPIO, GPIO_PIN_SET); \ else \ HAL_GPIO_WritePin(SDA_Type, SDA_GPIO, GPIO_PIN_RESET); #define SCL_OUT(X) if(X) \ HAL_GPIO_WritePin(SCL_Type, SCL_GPIO, GPIO_PIN_SET); \ else \ HAL_GPIO_WritePin(SCL_Type, SCL_GPIO, GPIO_PIN_RESET); #define SDA_IN HAL_GPIO_ReadPin(SDA_Type,SDA_GPIO) //?????????????? /*?????*/ /** * @brief I2C?? * @param ? * @retval ? */ const unsigned char 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 }; void OLED_I2C_Init(void) { __HAL_RCC_GPIOB_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStructure.Pin = SDA_GPIO | SCL_GPIO; GPIO_InitStructure.Pull = GPIO_PULLUP; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB,&GPIO_InitStructure); SCL_OUT(1); SDA_OUT(1); } void IIC_Start(void) { OLED_I2C_Init(); SDA_OUT(1); SCL_OUT(1) ; SDA_OUT(0); SCL_OUT(0) ; } //IIC???? void IIC_Stop(void) { SDA_OUT(0); SCL_OUT(1); SDA_OUT(1); } /** * @brief I2C?????? * @param Byte ???????? * @retval ? */ void IIC_Send_Byte(unsigned char d)//????8??????MSB ???? { unsigned char i = 0; for(i=0;i<8;i++) { SDA_OUT(d & (0x80 >> i)); SCL_OUT(1);//?????,????????? SCL_OUT(0);//?????,?????????,?????? } SCL_OUT(1); SCL_OUT(0); } /** * @brief OLED??? * @param Command ?????? * @retval ? */ void OLED_WriteCommand(unsigned char Command) { IIC_Start(); IIC_Send_Byte(0x78); //???? IIC_Send_Byte(0x00); //??? IIC_Send_Byte(Command); IIC_Stop(); } /** * @brief OLED??? * @param Data ?????? * @retval ? */ void OLED_WriteData(unsigned char Data) { IIC_Start(); IIC_Send_Byte(0x78); //???? IIC_Send_Byte(0x40); //??? IIC_Send_Byte(Data); IIC_Stop(); } /** * @brief OLED?????? * @param Y ???????,???????,??:0~7 * @param X ???????,???????,??:0~127 * @retval ? */ void OLED_SetCursor(unsigned char Y, unsigned char X) { OLED_WriteCommand(0xB0 | Y); //??Y?? OLED_WriteCommand(0x10 | ((X & 0xF0) >> 4)); //??X???4? OLED_WriteCommand(0x00 | (X & 0x0F)); //??X???4? } /** * @brief OLED?? * @param ? * @retval ? */ void OLED_Clear(void) { unsigned char i, j; for (j = 0; j < 8; j++) { OLED_SetCursor(j, 0); for(i = 0; i < 128; i++) { OLED_WriteData(0x00); } } } /** * @brief OLED?????? * @param Line ???,??:1~4 * @param Column ???,??:1~16 * @param Char ????????,??:ASCII???? * @retval ? */ void OLED_ShowChar(unsigned char Line, unsigned char Column, char Char) { unsigned char i; OLED_SetCursor((Line - 1) * 2, (Column - 1) * 8); //??????????? for (i = 0; i < 8; i++) { OLED_WriteData(OLED_F8x16[Char - ' '][i]); //???????? } OLED_SetCursor((Line - 1) * 2 + 1, (Column - 1) * 8); //??????????? for (i = 0; i < 8; i++) { OLED_WriteData(OLED_F8x16[Char - ' '][i + 8]); //???????? } } /** * @brief OLED????? * @param Line ?????,??:1~4 * @param Column ?????,??:1~16 * @param String ???????,??:ASCII???? * @retval ? */ void OLED_ShowString(unsigned char Line, unsigned char Column, char *String) { unsigned char i; for (i = 0; String[i] != '\0'; i++) { OLED_ShowChar(Line, Column + i, String[i]); } } /** * @brief OLED???? * @retval ?????X?Y?? */ uint32_t OLED_Pow(uint32_t X, uint32_t Y) { uint32_t Result = 1; while (Y--) { Result *= X; } return Result; } /** * @brief OLED????(???,??) * @param Line ?????,??:1~4 * @param Column ?????,??:1~16 * @param Number ??????,??:0~4294967295 * @param Length ????????,??:1~10 * @retval ? */ void OLED_ShowNum(unsigned char Line, unsigned char Column, uint32_t Number, unsigned char Length) { unsigned char i; for (i = 0; i < Length; i++) { OLED_ShowChar(Line, Column + i, Number / OLED_Pow(10, Length - i - 1) % 10 + '0'); } } /** * @brief OLED????(???,????) * @param Line ?????,??:1~4 * @param Column ?????,??:1~16 * @param Number ??????,??:-2147483648~2147483647 * @param Length ????????,??:1~10 * @retval ? */ void OLED_ShowSignedNum(unsigned char Line, unsigned char Column, int32_t Number, unsigned char Length) { unsigned char 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????(????,??) * @param Line ?????,??:1~4 * @param Column ?????,??:1~16 * @param Number ??????,??:0~0xFFFFFFFF * @param Length ????????,??:1~8 * @retval ? */ void OLED_ShowHexNum(unsigned char Line, unsigned char Column, uint32_t Number, unsigned char Length) { unsigned char 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????(???,??) * @param Line ?????,??:1~4 * @param Column ?????,??:1~16 * @param Number ??????,??:0~1111 1111 1111 1111 * @param Length ????????,??:1~16 * @retval ? */ void OLED_ShowBinNum(unsigned char Line, unsigned char Column, uint32_t Number, unsigned char Length) { unsigned char i; for (i = 0; i < Length; i++) { OLED_ShowChar(Line, Column + i, Number / OLED_Pow(2, Length - i - 1) % 2 + '0'); } } /** * @brief OLED??? * @param ? * @retval ? */ void OLED_Init(void) { uint32_t i, j; for (i = 0; i < 1000; i++) //???? { for (j = 0; j < 1000; j++); } OLED_I2C_Init(); //????? OLED_WriteCommand(0xAE); //???? OLED_WriteCommand(0xD5); //?????????/????? OLED_WriteCommand(0x80); OLED_WriteCommand(0xA8); //??????? OLED_WriteCommand(0x3F); OLED_WriteCommand(0xD3); //?????? OLED_WriteCommand(0x00); OLED_WriteCommand(0x40); //??????? OLED_WriteCommand(0xA1); //??????,0xA1?? 0xA0???? OLED_WriteCommand(0xC8); //??????,0xC8?? 0xC0???? OLED_WriteCommand(0xDA); //??COM?????? OLED_WriteCommand(0x12); OLED_WriteCommand(0x81); //??????? OLED_WriteCommand(0xCF); OLED_WriteCommand(0xD9); //??????? OLED_WriteCommand(0xF1); OLED_WriteCommand(0xDB); //??VCOMH?????? OLED_WriteCommand(0x30); OLED_WriteCommand(0xA4); //????????/?? OLED_WriteCommand(0xA6); //????/???? OLED_WriteCommand(0x8D); //????? OLED_WriteCommand(0x14); OLED_WriteCommand(0xAF); //???? OLED_Clear(); //OLED?? } 这个代码能够在OLED屏幕上显示定位信息吗
时间: 2025-06-02 19:32:06 浏览: 44
### 是否支持在OLED屏幕上显示特定的定位信息
要判断代码是否能够支持在OLED屏幕上显示特定的定位信息(例如坐标或位置数据),需要分析以下几个方面:
#### 1. 显存结构与刷新逻辑
代码中定义了一个二维数组 `g_oled_gram`,用于存储OLED屏幕的显存数据。该数组大小为 `[128][8]`,表示屏幕有128列和8页的数据[^1]。
每次调用 `oled_refresh_gram()` 函数时,程序会遍历整个显存并将其中的内容逐行写入到OLED显示屏上。
这意味着如果希望在某个具体的位置显示定位信息,则需要先将对应的字符或图形转换成二进制形式并填充到 `g_oled_gram` 的相应区域中。
#### 2. 字符绘制方法
引用[2] 提供了一种基于字模数组的方式,在指定位置 `(x, y)` 绘制单个字符的方法。以下是其核心实现:
```c
/*传入显示的数据*/
OLED_Set_Pos(x, y); // 设置字符显示的起始地址
for (i = 0; i < 8; i++) {
OLED_WR_Byte(F8X16[c * 16 + i], OLED_DATA);
}
OLED_Set_Pos(x, y + 1); // 向下移动一个地址页 page
for (i = 0; i < 8; i++) {
OLED_WR_Byte(F8X16[c * 16 + i + 8], OLED_DATA);
}
```
这里的关键在于 `OLED_Set_Pos(x, y)` 和 `OLED_WR_Byte(data, OLED_DATA)` 这两个函数分别负责设置绘图起点以及向OLED发送实际像素数据。因此,只要提供合适的参数组合即可完成任意位置上的字符渲染操作。
#### 3. 初始化过程的影响
由引用[3] 可知,初始化阶段通过 I2C 协议执行了一系列预设指令来配置硬件环境。这些基础设定决定了后续能否正常访问目标器件及其寄存器资源。如果没有正确完成这一步骤的话,即使其他部分功能完好也可能无法达到预期效果。
综上所述,当前给出的三段源码片段确实具备一定的能力去实现在给定坐标的区域内呈现文字或者图案的功能;但是还需要额外编写辅助工具以便于处理字符串拆分、字体加载等问题才能最终达成目的。
```python
def draw_character_on_screen(character_code, x_position, y_position):
"""模拟如何利用现有API在一个固定点描绘字母"""
global F8X16
# 假设F8X16已经包含了完整的ASCII编码映射关系表
byte_index_start = character_code * 16
OLED_Set_Pos(x_position, y_position)
for index in range(8):
OLED_WR_Byte(F8X16[byte_index_start + index], OLED_DATA)
OLED_Set_Pos(x_position, y_position + 1)
for index in range(8, 16):
OLED_WR_Byte(F8X16[byte_index_start + index], OLED_DATA)
```
阅读全文
相关推荐


















