目錄
- 聯盛德 HLK-W806 (一): Ubuntu20.04下的開發環境配置, 編譯和燒錄說明
- 聯盛德 HLK-W806 (二): Win10下的開發環境配置, 編譯和燒錄說明
- 聯盛德 HLK-W806 (三): 免按鍵自動下載和復位
- 聯盛德 HLK-W806 (四): 軟件SPI和硬件SPI驅動ST7735液晶LCD
- 聯盛德 HLK-W806 (五): W801開發板上手報告
- 聯盛德 HLK-W806 (六): I2C驅動SSD1306 128x64 OLED液晶屏
- 聯盛德 HLK-W806 (七): 兼容開發板 LuatOS Air103
- 聯盛德 HLK-W806 (八): 4線SPI驅動SSD1306/SSD1315 128x64 OLED液晶屏
- 聯盛德 HLK-W806 (九): 軟件SPI和硬件SPI驅動ST7789V液晶LCD
- 聯盛德 HLK-W806 (十): 在 CDK IDE開發環境中使用WM-SDK-W806
- 聯盛德 HLK-W806 (十一): 軟件SPI和硬件SPI驅動ST7567液晶LCD
- 聯盛德 HLK-W806 (十二): Makefile組織結構和編譯流程說明
- 聯盛德 HLK-W806 (十三): 運行FatFs讀寫FAT和exFat格式的SD卡/TF卡
ST7567介紹
ST7567是128x64分辨率單色LCD液晶顯示屏常用的芯片方案. ST7567是點陣LCD驅動集成電路, 可以使用8位並口或4線SPI串口(SPI-4)直接連接外部微控制器. 從MPU傳輸的數據存儲在內部65x132 bits的顯示數據內存(DDRAM). 在 DDRAM 中存儲的數據與LCD點陣直接關聯. ST7567 包含 132 段輸出, 64 位輸出和 1 個公共圖標輸出, 輸出不需要外部時鍾驅動.
特性
單片驅動 Single-chip LCD Controller & Driver, 片內顯示內存 On-chip Display Data RAM (DDRAM)
- 容量Capacity: 65x132=8580 bits
- 直接顯示模式 Directly display RAM pattern from DDRAM
可選的顯示占空比 Selectable Display Duty (by SEL2 & SEL1)
- 1/65 duty : 65 common x 132 segment
- 1/55 duty : 55 common x 132 segment
- 1/49 duty : 49 common x 132 segment
- 1/33 duty : 33 common x 132 segment
微控制器接口 Microprocessor Interface
- 雙向8位並口Bidirectional 8-bit parallel interface supports: 8080-series and 6800-series MPU
- SPI-4串口(只寫) Serial interface (SPI-4) is also supported (write only)
附加功能 Abundant Functions
- 顯示開關 Display ON/OFF,
- 正顯/反顯 Normal/Reverse Display Mode,
- 設置顯示開始位置 Set Display Start Line,
- 讀取IC狀態 Read IC Status,
- 顯示全部點陣 Set all Display Points ON,
- 設置LCD基准 Set LCD Bias,
- 電量控制 Electronic Volume Control,
- 寫入后保持起點 Read-modify-Write,
- 段驅動方向設置 Select Segment Driver Direction,
- 節電模式 Power Saving Mode,
- 位驅動方向設置 Select Common Driver Direction,
- 電壓調節電阻比值設置 Select Voltage Regulator Resistor Ratio (for V0).
外部硬件復位腳 External Hardware Reset Pin (RSTB)
內建振盪信號源 Built-in Oscillation Circuit
- 無需外部振盪源 No external component required
低功耗模擬電路 Low Power Consumption Analog Circuit
- Voltage Booster (4X, 5X)
- High-accuracy Voltage Regulator for LCD Vop: (Thermal Gradient: -0.05%/°C)
- Voltage Follower for LCD Bias Voltage
Wide Operation Voltage Range
- VDD1-VSS1=1.8V~3.3V
- VDD2-VSS2=2.4V~3.3V
- VDD3-VSS3=2.4V~3.3V
溫度范圍 Temperature Range: -30~85°C
封裝類型 Package Type: COG
指令表
命令模式和數據模式的切換
- A0低: 命令模式
- A0高: 數據模式
指令列表
- Display ON/OFF
AF:ON, AE:OFF - Set Start Line
0 0 0 1 S5 S4 S3 S2 S1 S0 Set display start line - Set Page Address
0 0 1 0 1 1 Y3 Y2 Y1 Y0 Set page address - Set Column Address
0 0 0 0 0 1 X7 X6 X5 X4 Set column address (MSB)
0 0 0 0 0 0 X3 X2 X1 X0 Set column address (LSB) - Read Status: Read IC Status
0 1 0 MX D RST 0 0 0 0 - Write Data: Write display data to RAM
1 0 D7 D6 D5 D4 D3 D2 D1 D0 - Read Data: Read display data from RAM
1 1 D7 D6 D5 D4 D3 D2 D1 D0 - SEG Direction: Set scan direction of SEG
0 0 1 0 1 0 0 0 0 MX
MX=1, reverse direction
MX=0, normal direction - Inverse Display: INV =1, inverse display, INV =0, normal display
0 0 1 0 1 0 0 1 1 INV - All Pixel ON: AP=1, set all pixel ON, AP=0, normal display
0 0 1 0 1 0 0 1 0 AP - Bias Select: Select bias setting, 0=1/9; 1=1/7 (at 1/65 duty)
0 0 1 0 1 0 0 0 1 BS - Read-modify-Write: Column address increment: Read:+0 , Write:+1
0 0 1 1 1 0 0 0 0 0 - END: Exit Read-modify-Write mode
0 0 1 1 1 0 1 1 1 0 - RESET: Software reset
0 0 1 1 1 0 0 0 1 0 - COM Direction: Set output direction of COM, MY=1, reverse direction, MY=0, normal direction
0 0 1 1 0 0 MY - - - - Power Control, Control built-in power circuit ON/OFF
0 0 0 0 1 0 1 VB VR VF - Regulation Ratio: Select regulation resistor ratio
0 0 0 0 1 0 0 RR2 RR1 RR0 - Set EV: Double command, Set EV0 electronic volume (EV) level
0 0 1 0 0 0 0 0 0 1
0 0 0 0 EV5 EV4 EV3 EV2 EV1 EV0 - Set Booster: Double command, Set booster level: BL=0: 4X, BL=1: 5X
0 0 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 BL - Power Save: Display OFF + All Pixel ON
0 0 + Compound Command - NOP: No operation
0 0 1 1 1 0 0 0 1 1 - Test: Do NOT use. Reserved for testing.
0 0 1 1 1 1 1 1 1 -
ST7567 128x64 LCD 模塊
模塊規格圖
PIN腳定義
- NC
- NC
- LED_A 背光正極, 加1~5K電阻后接VCC, 或連接GPIO以便程序控制背光
- LED_K 背光負極, 接地
- GND 接地
- CSB 片選, CS
- RESET 復位腳, 接GPIO
- AO 命令/數據切換
- SCLK SPI時鍾
- SDA SPI MOSI
- VDD 接VCC
- VSS 邏輯地, 接地
- VO: V0 is the LCD driving voltage for common circuits at negative frame.
- XVO: XV0 is the LCD driving voltage for common circuits at positive frame.
- VG: VG is the LCD driving voltage for segment circuits.
- GND 接地
- NC
- NC
接線
完整需要10根接線, 其中LED_A可以加電阻后直接接3.3V, RESET可以懸空, 這樣只需要接8根線.
3. LED_A 加1~5K電阻 -> PB16
4. LED_K -> GND
5. GND -> GND
6. CSB -> PB14
7. RESET -> PB10
8. AO -> PB11
9. SCLK -> PB15
10. SDA -> PB17
11. VDD -> 3.3V
12. VSS -> GND
演示代碼的使用
SPI驅動部分與SSD1306相同, 指令很少, 只有22個, 與SSD1306相比, 增加了背光控制, 增加了硬件復位.
本示例使用的代碼
指令定義
/* ST7567 commands definitions */
#define ST7567_DISPLAY_OFF 0xAE /* 0xae: Display OFF (sleep mode) */
#define ST7567_DISPLAY_ON 0xAF /* 0xaf: Display ON in normal mode */
#define ST7567_SET_START_LINE 0x40 /* 0x40-7f: Set display start line */
#define ST7567_SET_START_LINE_MASK 0x3f
#define ST7567_SET_PAGE_ADDRESS 0xB0 /* 0xb0-b7: Set page start address */
#define ST7567_SET_PAGE_ADDRESS_MASK 0x07
#define ST7567_SET_COLUMN_ADDRESS_MSB 0x10 /* 0x10-0x1f: Set higher column address */
#define ST7567_SET_COLUMN_ADDRESS_MSB_MASK 0x0f
#define ST7567_SET_COLUMN_ADDRESS_LSB 0x00 /* 0x00-0x0f: Set lower column address */
#define ST7567_SET_COLUMN_ADDRESS_LSB_MASK 0x0F
/**
* SEG: 0 - 131
*/
#define ST7567_SEG_DIRECTION_NORMAL 0xA0 /* 0xa0: Column address 0 is mapped to SEG0 */
#define ST7567_SEG_DIRECTION_REVERSE 0xA1 /* 0xa1: Column address 128 is mapped to SEG0 */
/**
* COM: 0 - 63
*/
#define ST7567_COM_DIRECTION_NORMAL 0xC0 /* 0xc0: Set COM output direction, normal mode */
#define ST7567_COM_DIRECTION_REVERSE 0xC8 /* 0xc8: Set COM output direction, reverse mode */
#define ST7567_INVERSE_DISPLAY_OFF 0xA6 /* 0xa6: Normal display */
#define ST7567_INVERSE_DISPLAY_ON 0xA7 /* 0xa7: Inverse display */
#define ST7567_ALL_PIXEL_ON 0xA5 /* 0xa5: Entire display ON */
#define ST7567_ALL_PIXEL_NORMAL 0xA4 /* 0xa4: Resume to RAM content display */
#define ST7567_BIAS_1_9 0xA2 /* 0xa2: Select BIAS setting 1/9 */
#define ST7567_BIAS_1_7 0xA3 /* 0xa3: Select BIAS setting 1/7 */
#define ST7567_READ_MODIFY_WRITE_START 0xE0 /* 0xe0: Enter the Read Modify Write mode */
#define ST7567_READ_MODIFY_WRITE_END 0xEE /* 0xee: Leave the Read Modify Write mode */
#define ST7567_RESET 0xE2 /* 0xe2: Software RESET */
/**
* This instruction controls the built-in power circuits.
* Typically, these 3 flags are turned ON at the same time.
*/
#define ST7567_POWER_CONTROL 0x28
#define ST7567_POWER_CONTROL_VF 0x01
#define ST7567_POWER_CONTROL_VR 0x02
#define ST7567_POWER_CONTROL_VB 0x04
/**
* The operation voltage (V0) calculation formula is shown below:
* (RR comes from Regulation Ratio, EV comes from EV[5:0])
* V0 = RR X [ 1 – (63 – EV) / 162 ] X 2.1, or
* V0 = RR X [ ( 99 + EV ) / 162 ] X 2.1
*/
#define ST7567_REGULATION_RATIO 0x20
#define ST7567_REGULATION_RATIO_3_0 0x00
#define ST7567_REGULATION_RATIO_3_5 0x01
#define ST7567_REGULATION_RATIO_4_0 0x02
#define ST7567_REGULATION_RATIO_4_5 0x03
#define ST7567_REGULATION_RATIO_5_0 0x04 /* Default */
#define ST7567_REGULATION_RATIO_5_5 0x05
#define ST7567_REGULATION_RATIO_6_0 0x06
#define ST7567_REGULATION_RATIO_6_5 0x07
/**
* This is double byte instruction. The first byte set ST7567 into EV
* adjust mode and the following instruction will change the EV setting.
* That means these 2 bytes must be used together. They control the electronic
* volume to adjust a suitable V0 voltage for the LCD.
*/
#define ST7567_SET_EV 0x81
#define ST7567_SET_EV_MASK 0x3F
#define ST7567_SET_BOOSTER 0xF8 /* Set booster level */
#define ST7567_SET_BOOSTER_4X 0x00
#define ST7567_SET_BOOSTER_5X 0x01
#define ST7567_NOP 0xE3
#define ST7567_TEST 0xFE
顯示內存和偏移量
ST7567的顯示與內存並非一一對應, 每一行為132byte, 這額外的4個byte並不會顯示在屏幕上, 但是會占位.
/**
* In datasheet, it says "the column address is increased (+1) after each display
* data access (read/write). This allows MPU accessing DDRAM content continuously.
* This feature stops at the end of each page (Column Address “83h”) because the
* Column Address and Page Address circuits are independent. For example, both Page
* Address and Column Address should be assigned for changing the DDRAM pointer
* from (Page-0, Column-83h) to (Page-1, Column-0)."
* In actual test the Page Address will grow automatically.
*/
/* ST7567 data buffer */
static uint8_t ST7567_Buffer_all[(ST7567_WIDTH + ST7567_SEG_EXPAND) * ST7567_HEIGHT / 8];
在行方向翻轉后, 需要在代碼中考慮這4個byte的偏移量, 否則顯示會不完整.
#if ST7567_X_ORIENT == ST7567_SEG_DIRECTION_REVERSE
#define ST7567_X_OFFSET ST7567_SEG_EXPAND
#else
#define ST7567_X_OFFSET 0
#endif
// 基礎方法: 在指定的位置繪制點
void ST7567_DrawPixel(uint16_t x, uint16_t y, uint8_t color)
{
if (x >= ST7567_WIDTH || y >= ST7567_HEIGHT)
{
/* Error */
return;
}
if (color == ST7567_COLOR_FRONT)
{
ST7567_Buffer_all[ST7567_X_OFFSET + x + (y / 8) * (ST7567_WIDTH + ST7567_SEG_EXPAND)] |= 1 << (y % 8);
}
else
{
ST7567_Buffer_all[ST7567_X_OFFSET + x + (y / 8) * (ST7567_WIDTH + ST7567_SEG_EXPAND)] &= ~(1 << (y % 8));
}
}
設置項
在 st7567.h 中, 對以下宏定義進行設置. 如果只是運行demo, 建議先用默認配置跑通. 如果對pin腳進行了修改, 對應的也要調整連線.
// 設置是否使用硬件SPI
#define ST7567_HARDWARE_SPI 1
// 設置PIN腳
// CS: B4, B14
#define ST7567_CS_PORT GPIOB
#define ST7567_CS_PIN GPIO_PIN_14
// SCK: B1, B2, B15, B24
#define ST7567_SCK_PORT GPIOB
#define ST7567_SCK_PIN GPIO_PIN_15
// MOSI: B5, B17, B26, PA7
#define ST7567_MOSI_PORT GPIOB
#define ST7567_MOSI_PIN GPIO_PIN_17
// MISO: B0, B3, B16, B25
#define ST7567_RES_PORT GPIOB
#define ST7567_RES_PIN GPIO_PIN_10
#define ST7567_DC_PORT GPIOB
#define ST7567_DC_PIN GPIO_PIN_11
#define ST7567_BL_PORT GPIOB
#define ST7567_BL_PIN GPIO_PIN_16
// 設置屏幕的寬
// X width
#define ST7567_WIDTH 128
// 設置屏幕的高
// Y height
#define ST7567_HEIGHT 64
// 設置每行的附加字節數, 默認為4
// Additional bytes in each row
#define ST7567_SEG_EXPAND 4
// 行方向
// X orientation
#define ST7567_X_ORIENT ST7567_SEG_DIRECTION_REVERSE
// 列方向
// Y orientation
#define ST7567_Y_ORIENT ST7567_COM_DIRECTION_NORMAL
st7567.c 中的LCD初始化方法, 這里的參數如果不適合你的LCD, 需要根據手冊調整.
有幾處修改后容易導致不顯示的選項, 需要謹慎修改
- ST7567_POWER_CONTROL 這個是升壓設置, 當前這塊屏幕, 只有三個位都置1時, 屏幕才有顯示, 其它選項都不行
- ST7567_SET_EV 這個是對比度電壓設置, 范圍為0 - 0x3F, 太低(< 0x10)會顯示全空白, 太高(> 0x32)會顯示為全黑
- ST7567_ALL_PIXEL_NORMAL 如果設置為 ST7567_ALL_PIXEL_ON 可能並非全黑, 而是全空白. 未跑通時建議用NORMAL
- ST7567_SET_PAGE_ADDRESS 和 ST7567_SET_COLUMN_ADDRESS_MSB, ST7567_SET_COLUMN_ADDRESS_LSB 用於設置顯示的開始行和列位置, 需要初始化到原點.
void ST7567_Init(void)
{
ST7567_Reset();
ST7567_BackLight_On();
ST7567_WriteCommand(ST7567_RESET);
ST7567_WriteCommand(ST7567_POWER_CONTROL
|ST7567_POWER_CONTROL_VB
|ST7567_POWER_CONTROL_VR
|ST7567_POWER_CONTROL_VF);
ST7567_WriteCommand(ST7567_SET_EV);
ST7567_WriteCommand(ST7567_SET_EV_MASK & 0x20);
ST7567_WriteCommand(ST7567_BIAS_1_9);
ST7567_WriteCommand(ST7567_X_ORIENT);
ST7567_WriteCommand(ST7567_Y_ORIENT);
ST7567_WriteCommand(ST7567_REGULATION_RATIO | ST7567_REGULATION_RATIO_5_0);
ST7567_WriteCommand(ST7567_INVERSE_DISPLAY_OFF);
ST7567_WriteCommand(ST7567_DISPLAY_ON);
ST7567_WriteCommand(ST7567_ALL_PIXEL_NORMAL);
ST7567_WriteCommand(ST7567_SET_START_LINE | (0x00 & ST7567_SET_START_LINE_MASK));
ST7567_WriteCommand(ST7567_SET_PAGE_ADDRESS | (0x00 & ST7567_SET_PAGE_ADDRESS_MASK));
ST7567_WriteCommand(ST7567_SET_COLUMN_ADDRESS_MSB);
ST7567_WriteCommand(ST7567_SET_COLUMN_ADDRESS_LSB);
}
圖形繪制
圖形繪制的方法與SSD1306一致, 可以繪制點, 線, 圈, 文字, 反顯, 調節對比度, 開關背光
int main(void)
{
//...
// 繪制直線
ST7567_DrawLine(0, 0, 127, 0, 1);
ST7567_DrawLine(0, 0, 0, 63, 1);
ST7567_DrawLine(127, 0, 127, 63, 1);
ST7567_DrawLine(0, 63, 127, 63, 1);
// 繪制文字
ST7567_Puts("LCD:ST7567", &Font_6x12, 1);
// 繪制后, 需要使用這個方法刷新LCD顯示
ST7567_UpdateScreen();
// 設置對比度
while (y1 <= 0x30)
{
ST7567_SetContrast(y1++);
HAL_Delay(100);
}
// 反顯
ST7567_ToggleInvert();
ST7567_UpdateScreen();
// 繪制圓
ST7567_DrawCircle(64, 32, 25, 0);
ST7567_UpdateScreen();
//...
}
實際演示展示
B站視頻: https://www.bilibili.com/video/BV1VZ4y1X7p7
LCD液晶屏的延遲很高, 如果變化太快, 每秒幀數在七八幀以上基本就看不清了. 這點不如OLED屏幕.