在线时间116 小时
UID3123257
注册时间2016-10-11
NXP金币0
TA的每日心情 | 奋斗 2017-1-18 20:00 |
---|
签到天数: 45 天 连续签到: 1 天 [LV.5]常住居民I
高级会员

- 积分
- 533
- 最后登录
- 2024-11-23
|
LPC824驱动中景园电子0-96寸OLED模块SSD1306在买SSD1331时同时买了一块SSD1306,现在也是用LPC824来驱动,SSD1306的引脚排列与SSD1331的排列一致:
1:GND
2:VCC(3.3V、5V均可)
3:SCL(时钟)
4:SDA(数据)
5:RES(RST复位)
6:DC(数据/命令)
7:CS(片选)
SSD1306支持3线SPI驱动,4线SPI驱动,也支持IIC驱动,在论坛里看到的很多是IIC驱动,所以我这里使用4线SPI驱动,当然也有SPI驱动的,不过多多少少有一些差异,有的在Mbed平台实现,有的是OLED是六根线的。
同样,接下来分配引脚:
// GND 地
// VCC 5V或3.3V
// D0 P0_24(CLK)
// D1 P0_8MOSI
// RES P0_26
// DC P0_15
// CS P0_27
分配完引脚就是写程序了,其实这里的引脚驱动程序比较简单,如下:
- //-----------------OLED引脚定义----------------
- #define OLED_CS_Clr() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 27, 0) //0
- #define OLED_CS_Set() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 27, 1); //1
- #define OLED_RST_Clr() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 26, 0) //0
- #define OLED_RST_Set() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 26, 1) //1
- #define OLED_DC_Clr() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 15, 0) //0
- #define OLED_DC_Set() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 15, 1) //1
- #define OLED_SCLK_Clr() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 24, 0) //0
- #define OLED_SCLK_Set() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 24, 1) //1
- #define OLED_SDIN_Clr() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 8, 0) //0
- #define OLED_SDIN_Set() Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 8, 1) //1
复制代码- void OLED_PIN_Init(void)
- {
- Chip_GPIO_Init(LPC_GPIO_PORT);
- Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 24, 1); //ÉèÖÃΪÊä³ö
- Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 8, 1);
- Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 26, 1);
- Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 15, 1);
- Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 27, 1);
- }
复制代码 设置完引脚后其他程序参考官方给的例程基本就完成了,下面贴上源代码:
给出结果图:
|
|