` 鉴于STM32F103 开发板没有配置显示屏,因此要显示一些信息除了借助串行通讯,就必须为其添加相应的显示器件了。在初步掌握GPIO口的基础上,最好是以OLED屏为显示器件。
OLED屏有多种类型,按色彩分有单色屏、双色屏及彩色屏;按接口方式分有并口屏、SPI接口屏及IIC接口屏。这里所选用的IIC接口的双色OLED屏,该显示屏在工作时只需占用2个GPIO口,所以该器件很有特色,图1是其显示效果。
图1 OLED屏显示效果
在STM32F103 开发板所配的光盘中,也有OLED屏显示例程但它是并口屏,并与OV7670摄像头共用同一接口,其接口的原理图如图2所示。
图2 接口原理图
在IIC接口的使用方式中,我们只用到PC0和PC1,以对应OLED屏的SCL和SDA。
为便于高低电平信号的输出,特作如下的定义:
#define OLED_SCLK PCout(0)
#define OLED_SDIN PCout(1)
#define OLED_SCLK_Clr() OLED_SCLK = 0;
#define OLED_SCLK_Set() OLED_SCLK = 1;
#define OLED_SDIN_Clr() OLED_SDIN = 0;
#define OLED_SDIN_Set() OLED_SDIN = 1;
对OLED屏进行初始化的程序如下:
- void OLED_Initi(void)
- {
- RCC->APB2ENR|=1<<4;
- GPIOC->CRL&=0XFFFFFF00;
- GPIOC->CRL|=0X00000033;
- GPIOC->ODR|=3<<0;
- OLED_SCLK_Set();
- OLED_SDIN_Set();
- delay_ms(800);
- OLED_WR_ByteI(0xAE,OLED_CMD);
- OLED_WR_ByteI(0x00,OLED_CMD);
- OLED_WR_ByteI(0x10,OLED_CMD);
- OLED_WR_ByteI(0x40,OLED_CMD);
- OLED_WR_ByteI(0xB0,OLED_CMD);
- OLED_WR_ByteI(0x81,OLED_CMD);
- OLED_WR_ByteI(0xFF,OLED_CMD);
- OLED_WR_ByteI(0xA1,OLED_CMD);
- OLED_WR_ByteI(0xA6,OLED_CMD);
- OLED_WR_ByteI(0xA8,OLED_CMD);
- OLED_WR_ByteI(0x3F,OLED_CMD);
- OLED_WR_ByteI(0xC8,OLED_CMD);
- OLED_WR_ByteI(0xD3,OLED_CMD);
- OLED_WR_ByteI(0x00,OLED_CMD);
- OLED_WR_ByteI(0xD5,OLED_CMD);
- OLED_WR_ByteI(0x80,OLED_CMD);
- OLED_WR_ByteI(0xD8,OLED_CMD);
- OLED_WR_ByteI(0x05,OLED_CMD);
- OLED_WR_ByteI(0xD9,OLED_CMD);
- OLED_WR_ByteI(0xF1,OLED_CMD);
- OLED_WR_ByteI(0xDA,OLED_CMD);
- OLED_WR_ByteI(0x12,OLED_CMD);
- OLED_WR_ByteI(0xDB,OLED_CMD);
- OLED_WR_ByteI(0x30,OLED_CMD);
- OLED_WR_ByteI(0x8D,OLED_CMD);
- OLED_WR_ByteI(0x14,OLED_CMD);
- OLED_WR_ByteI(0xAF,OLED_CMD);
- }
复制代码
实现OLED屏显示的主程序为:
- int main(void)
- {
- Stm32_Clock_Init(9);
- LED_Init();
- OLED_InitI();
- OLED_ClearI();
- OLED_ShowStringI(0,0,"ALIENTEK",16);
- OLED_ShowStringI(0,2,"0.96' OLED TEST",16);
- OLED_ShowStringI(0,4,"JLXX 2018/9/24",12);
- OLED_ShowStringI(0,5,"ASCII:",12);
- OLED_ShowStringI(64,5,"CODE:",12);
- OLED_ShowCharI(36,6,20,12);
- OLED_ShowNumI(94,6,20,3,12);
- while(1);
- }
复制代码
有了OLED屏的显示基础,我们就可进行RTC、A/D等方面的实验了,当然还可对TFT串口屏进行尝试以便来显示图像。
`
|