px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_lcd_st7567_jhd12864.c
1/* =============================================================================
2 _____ _____ _____ ____ _ _ ____ __ __ _____ __ __
3 | __ \ |_ _| / ____| / __ \ | \ | | / __ \ | \/ | |_ _| \ \ / /
4 | |__) | | | | | | | | | | \| | | | | | | \ / | | | \ V /
5 | ___/ | | | | | | | | | . ` | | | | | | |\/| | | | > <
6 | | _| |_ | |____ | |__| | | |\ | | |__| | | | | | _| |_ / . \
7 |_| |_____| \_____| \____/ |_| \_| \____/ |_| |_| |_____| /_/ \_\
8
9 Copyright (c) 2018 Pieter Conradie <https://piconomix.com>
10
11 License: MIT
12 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
13
14 Title: px_lcd_st7567_jhd12864.h : JHD JHD12864-G176BSW 128x64 monochrome LCD wtih Sitronix ST7567 driver
15 Author(s): Pieter Conradie
16 Creation Date: 2018-09-10
17
18============================================================================= */
19
20/* _____STANDARD INCLUDES____________________________________________________ */
21
22/* _____PROJECT INCLUDES_____________________________________________________ */
23#include "px_lcd_st7567_jhd12864.h"
24#include "px_log.h"
25
26/* _____LOCAL DEFINITIONS____________________________________________________ */
27PX_LOG_NAME("lcd");
28
29/// @name ST7567 commands (Table 8, page 21)
30/// @{
31#define PX_LCD_CMD_DISP_ON_OFF 0xae ///< (1) Display ON/OFF
32#define PX_LCD_CMD_SET_START_LINE 0x40 ///< (2) Set display start line
33#define PX_LCD_CMD_SET_PAGE_ADR 0xb0 ///< (3) Set page address
34#define PX_LCD_CMD_SET_COL_ADR_HI 0x10 ///< (4) Set column address (MSB)
35#define PX_LCD_CMD_SET_COL_ADR_LO 0x00 ///< (4) Set column address (LSB)
36#define PX_LCD_CMD_SEG_DIR 0xa0 ///< (8) SEG Direction
37#define PX_LCD_CMD_INVERSE_DISPLAY 0xa6 ///< (9) Display normal/reverse
38#define PX_LCD_CMD_ALL_PIXEL_ON 0xa4 ///< (10) Set all pixel ON or normal display
39#define PX_LCD_CMD_BIAS_SELECT 0xa2 ///< (11) Select bias setting
40#define PX_LCD_CMD_RESET 0xe2 ///< (14) Software reset
41#define PX_LCD_CMD_COM_DIRECTION 0xc0 ///< (15) Set output direction of COM
42#define PX_LCD_CMD_POWER_CONTROL 0x28 ///< (16) Control built-in power circuit
43#define PX_LCD_CMD_REG_RATIO 0x20 ///< (17) Select regulation resistor ratio
44#define PX_LCD_CMD_SET_EV 0x81 ///< (18) Set electronic volume (EV) command
45#define PX_LCD_CMD_SET_BOOSTER 0xf8 ///< (19) Set booster level command
46/// @}
47
48#define PX_LCD_ST7567_MAX_NR_OF_COLS 132
49#define PX_LCD_ST7567_MAX_NR_OF_ROWS 65
50
51/* _____MACROS_______________________________________________________________ */
52
53/* _____GLOBAL VARIABLES_____________________________________________________ */
54
55/* _____LOCAL VARIABLES______________________________________________________ */
56/// SPI handle to communicate with LCD
57static px_spi_handle_t * px_lcd_spi_handle;
58
59/* _____LOCAL FUNCTION DECLARATIONS__________________________________________ */
60
61/* _____LOCAL FUNCTIONS______________________________________________________ */
62static void px_lcd_wr_control_data(uint8_t data)
63{
64 //PX_LOG_INFO("LCD Cmd 0x%02X", data);
66 px_spi_wr(px_lcd_spi_handle, &data, 1, PX_SPI_FLAG_START_AND_STOP);
68}
69
70/* _____GLOBAL FUNCTIONS_____________________________________________________ */
72{
73 // Save handle
74 px_lcd_spi_handle = handle;
75
76 // Perform hardware reset
82
83 // Select 1/9 bias (1/65 duty)
84 px_lcd_wr_control_data(PX_LCD_CMD_BIAS_SELECT | 0);
85
86#if !PX_LCD_CFG_ROT_180_DEG
87 // Normal SEG output direction
88 px_lcd_wr_control_data(PX_LCD_CMD_SEG_DIR | 0);
89 // Select normal COM output scan direction
90 px_lcd_wr_control_data(PX_LCD_CMD_COM_DIRECTION | 0x00);
91#else
92 // Reverse SEG output direction, because LCD is rotated by 180 deg
93 px_lcd_wr_control_data(PX_LCD_CMD_SEG_DIR | 1);
94#endif
95
96 // Select normal COM output scan direction
97 px_lcd_wr_control_data(PX_LCD_CMD_COM_DIRECTION | 0x00);
98
99 // Set regulation ratio to 5.0 (VO = 9.01)
100 px_lcd_wr_control_data(PX_LCD_CMD_REG_RATIO | 0x04);
101
102 // Set electronic volume (EV) to 40
103 px_lcd_wr_control_data(PX_LCD_CMD_SET_EV);
104 px_lcd_wr_control_data(40);
105
106 // Enable voltage booster
107 px_lcd_wr_control_data(PX_LCD_CMD_POWER_CONTROL | 0x04);
109 // Enable voltage booster + regulator
110 px_lcd_wr_control_data(PX_LCD_CMD_POWER_CONTROL | 0x06);
112 // Enable voltage booster + regulator + follower
113 px_lcd_wr_control_data(PX_LCD_CMD_POWER_CONTROL | 0x07);
115
116 // Set booster level
117 px_lcd_wr_control_data(PX_LCD_CMD_SET_BOOSTER);
118 px_lcd_wr_control_data(0xaf);
119
120 // Set display line adr to 0
121 px_lcd_wr_control_data(PX_LCD_CMD_SET_START_LINE | 0);
122 // Set normal display
123 px_lcd_wr_control_data(PX_LCD_CMD_ALL_PIXEL_ON | 0);
124 // Set reverse display OFF
125 px_lcd_wr_control_data(PX_LCD_CMD_INVERSE_DISPLAY | 0);
126 // Clear RAM buffer
127 px_lcd_clr();
128 // Turn the display ON
129 px_lcd_wr_control_data(PX_LCD_CMD_DISP_ON_OFF | 1);
130}
131
133{
134 // Turn the display OFF
135 px_lcd_wr_control_data(PX_LCD_CMD_DISP_ON_OFF | 0);
136 // Turn all pixels ON
137 px_lcd_wr_control_data(PX_LCD_CMD_ALL_PIXEL_ON | 1);
138}
139
141{
142 // Cancel all pixels ON
143 px_lcd_wr_control_data(PX_LCD_CMD_ALL_PIXEL_ON | 0);
144 // Turn the display ON
145 px_lcd_wr_control_data(PX_LCD_CMD_DISP_ON_OFF | 1);
146
147}
148
149void px_lcd_clr(void)
150{
151 uint8_t y;
152 uint8_t data[PX_LCD_NR_OF_COLS];
153
154 // Set data for whole column to zero
155 memset(data, 0, PX_LCD_NR_OF_COLS);
156
157 // Repeat for each page
158 for(y = 0; y < PX_LCD_NR_OF_PAGES; y++)
159 {
160 // Select page
162 // Start at column 0
164 // Clear whole column
166 }
167}
168
169void px_lcd_sel_col(uint8_t col)
170{
171#if PX_LCD_CFG_ROT_180_DEG
172 col = (PX_LCD_ST7567_MAX_NR_OF_COLS - PX_LCD_NR_OF_COLS) + col;
173#endif
174
175 // Column most significant nibble
176 px_lcd_wr_control_data(PX_LCD_CMD_SET_COL_ADR_HI | ((col & 0xf0) >> 4));
177 // Column least significant nibble
178 px_lcd_wr_control_data(PX_LCD_CMD_SET_COL_ADR_LO | (col & 0x0f));
179}
180
181void px_lcd_sel_page(uint8_t page)
182{
183#if !PX_LCD_CFG_ROT_180_DEG
184 page = (PX_LCD_NR_OF_PAGES - 1) - page;
185#endif
186
187 px_lcd_wr_control_data(PX_LCD_CMD_SET_PAGE_ADR | page);
188}
189
190void px_lcd_wr_disp_u8(uint8_t data)
191{
192 px_spi_wr(px_lcd_spi_handle, &data, 1, PX_SPI_FLAG_START_AND_STOP);
193}
194
195void px_lcd_wr_disp_data(uint8_t * data, size_t nr_of_bytes)
196{
197 px_spi_wr(px_lcd_spi_handle, data, nr_of_bytes, PX_SPI_FLAG_START_AND_STOP);
198}
void px_board_delay_ms(uint16_t delay_ms)
Blocking delay for specified number of milliseconds.
Definition: px_board.c:234
#define PX_LCD_NR_OF_COLS
Number of columns.
void px_lcd_wr_disp_data(uint8_t *data, size_t nr_of_bytes)
Write data to display.
void px_lcd_init(px_spi_handle_t *handle)
Initialise LCD driver.
#define PX_LCD_CFG_RS_LO()
Macro to set RS pin low.
#define PX_LCD_NR_OF_PAGES
Number of pages.
void px_lcd_sel_page(uint8_t page)
Select LCD page (y) for display data.
#define PX_LCD_CFG_RST_LO()
Macro to set LCD reset pin low.
void px_lcd_wr_disp_u8(uint8_t data)
Write one byte of display data.
#define PX_LCD_CFG_RST_HI()
Macro to set LCD reset pin high.
void px_lcd_clr(void)
Clear LCD display.
#define PX_LCD_CFG_RS_HI()
Macro to set RS pin high.
void px_lcd_sel_col(uint8_t col)
Select LCD starting column (x) for display data.
void px_lcd_power_save_on(void)
Turn power save on.
void px_lcd_power_save_off(void)
Turn power save off.
#define PX_LOG_NAME(name)
Macro to declare a log name string once for each file to reduce code size.
Definition: px_log.h:349
#define PX_SPI_FLAG_START_AND_STOP
Begin and finish SPI transaction.
Definition: px_spi.h:121
void px_spi_wr(px_spi_handle_t *handle, const void *data, size_t nr_of_bytes, uint8_t flags)
Perform an SPI write transaction with an SPI slave.
Definition: px_spi.c:396
Define SPI handle.
Definition: px_spi.h:126