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_st7565p_tse2g0330e.c
1/* =============================================================================
2 _____ _____ _____ ____ _ _ ____ __ __ _____ __ __
3 | __ \ |_ _| / ____| / __ \ | \ | | / __ \ | \/ | |_ _| \ \ / /
4 | |__) | | | | | | | | | | \| | | | | | | \ / | | | \ V /
5 | ___/ | | | | | | | | | . ` | | | | | | |\/| | | | > <
6 | | _| |_ | |____ | |__| | | |\ | | |__| | | | | | _| |_ / . \
7 |_| |_____| \_____| \____/ |_| \_| \____/ |_| |_| |_____| /_/ \_\
8
9 Copyright (c) 2013 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_st7565p_tse2g0330e.h : Truly TSE2G0330-E 128x64 monochrome LCD wtih Sitronix ST7565P driver
15 Author(s): Pieter Conradie
16 Creation Date: 2013-12-05
17
18============================================================================= */
19
20/* _____STANDARD INCLUDES____________________________________________________ */
21
22/* _____PROJECT INCLUDES_____________________________________________________ */
23#include "px_lcd_st7565p_tse2g0330e.h"
24#include "px_board.h"
25#include "px_log.h"
26
27/* _____LOCAL DEFINITIONS____________________________________________________ */
28PX_LOG_NAME("lcd");
29
30/// @name ST7565P commands (Table 16, page 51)
31/// @{
32#define PX_LCD_CMD_DISP_ON_OFF 0xae ///< (1) Display ON/OFF
33#define PX_LCD_CMD_DISP_START_LINE_SET 0x40 ///< (2) Display start line set
34#define PX_LCD_CMD_PAGE_ADR_SET 0xb0 ///< (3) Page address set
35#define PX_LCD_CMD_COL_ADR_SET_HI 0x10 ///< (4) Column address set upper bit
36#define PX_LCD_CMD_COL_ADR_SET_LO 0x00 ///< (4) Column address set lower bit
37#define PX_LCD_CMD_ADC_SEL 0xa0 ///< (8) ADC select
38#define PX_LCD_CMD_DISP_NORMAL_REVERSE 0xa6 ///< (9) Display normal/reverse
39#define PX_LCD_CMD_DISP_ALL_ON_OFF 0xa4 ///< (10) Display all points
40#define PX_LCD_CMD_BIAS_SET 0xa2 ///< (11) LCD bias set
41#define PX_LCD_CMD_RST 0xe2 ///< (14) Reset
42#define PX_LCD_CMD_COM_OUT_MODE_SEL 0xc0 ///< (15) Common output mode select
43#define PX_LCD_CMD_PWR_CTL_SET 0x28 ///< (16) Power control set
44#define PX_LCD_CMD_V_REG_RES_RATIO_SET 0x20 ///< (17) Vo voltage regulator internal resistor ratio set
45#define PX_LCD_CMD_VOL_MODE_SET 0x81 ///< (18) Electronic volume mode set
46#define PX_LCD_CMD_VOL_REG_SET 0x00 ///< (18) Electronic volume register set
47#define PX_LCD_CMD_STATIC_IND_ON_OFF 0xac ///< (19) Static indicator ON/OFF
48#define PX_LCD_CMD_STATIC_IND_REG_SET 0x00 ///< (19) Static indicator register set
49#define PX_LCD_CMD_BOOSTER_RATIO_SET 0xf8 ///< (20) Booster ratio set
50/// @}
51
52#define PX_LCD_ST7565P_MAX_NR_OF_COLS 132
53#define PX_LCD_ST7565P_MAX_NR_OF_ROWS 65
54
55/* _____MACROS_______________________________________________________________ */
56
57/* _____GLOBAL VARIABLES_____________________________________________________ */
58
59/* _____LOCAL VARIABLES______________________________________________________ */
60/// SPI handle to communicate with LCD
61static px_spi_handle_t * px_lcd_spi_handle;
62
63/* _____LOCAL FUNCTION DECLARATIONS__________________________________________ */
64
65/* _____LOCAL FUNCTIONS______________________________________________________ */
66static void px_lcd_wr_control_data(uint8_t data)
67{
68 PX_LOG_D("LCD Cmd 0x%02X", data);
69
71 px_spi_wr(px_lcd_spi_handle, &data, 1, PX_SPI_FLAG_START_AND_STOP);
73}
74
75/* _____GLOBAL FUNCTIONS_____________________________________________________ */
77{
78 // Save handle
79 px_lcd_spi_handle = handle;
80
81 // Perform hardware reset
85
86 // Select 1/9 bias
87 px_lcd_wr_control_data(PX_LCD_CMD_BIAS_SET | 0);
88 // Select normal COM output scan direction
89 px_lcd_wr_control_data(PX_LCD_CMD_COM_OUT_MODE_SEL | 0);
90
91#if PX_LCD_CFG_ROT_180_DEG
92 // Reverse SEG output direction, because LCD is rotated by 180 deg
93 px_lcd_wr_control_data(PX_LCD_CMD_ADC_SEL | 1);
94#else
95 // Normal SEG output direction
96 px_lcd_wr_control_data(PX_LCD_CMD_ADC_SEL | 0);
97#endif
98
99 // Set display line adr to 0
100 px_lcd_wr_control_data(PX_LCD_CMD_DISP_START_LINE_SET | 0);
101 // Enable voltage booster, regulator & follower
102 px_lcd_wr_control_data(PX_LCD_CMD_PWR_CTL_SET | 0x7);
103 // Regulator resistor select
104 px_lcd_wr_control_data(PX_LCD_CMD_V_REG_RES_RATIO_SET | 0x3);
105 //set reference voltage mode
106 px_lcd_wr_control_data(PX_LCD_CMD_VOL_MODE_SET);
107 // set reference voltage
108 px_lcd_wr_control_data(47);
109 // set normal display
110 px_lcd_wr_control_data(PX_LCD_CMD_DISP_ALL_ON_OFF | 0);
111 // set reverse display OFF
112 px_lcd_wr_control_data(PX_LCD_CMD_DISP_NORMAL_REVERSE | 0);
113 // Clear RAM buffer
114 px_lcd_clr();
115 // turns the display ON
116 px_lcd_wr_control_data(PX_LCD_CMD_DISP_ON_OFF | 1);
117}
118
119void px_lcd_clr(void)
120{
121 uint8_t y;
122 uint8_t data[PX_LCD_NR_OF_COLS];
123
124 // Set data for whole column to zero
125 memset(data, 0, PX_LCD_NR_OF_COLS);
126
127 // Repeat for each page
128 for(y = 0; y < PX_LCD_NR_OF_PAGES; y++)
129 {
130 // Select page
132 // Start at column 0
134 // Clear whole column
136 }
137}
138
139void px_lcd_sel_col(uint8_t col)
140{
141#if PX_LCD_CFG_ROT_180_DEG
142 col = (PX_LCD_ST7565P_MAX_NR_OF_COLS - PX_LCD_NR_OF_COLS) + col;
143#endif
144
145 // Column most significant nibble
146 px_lcd_wr_control_data(PX_LCD_CMD_COL_ADR_SET_HI | ((col & 0xf0) >> 4));
147 // Column least significant nibble
148 px_lcd_wr_control_data(PX_LCD_CMD_COL_ADR_SET_LO | (col & 0x0f));
149}
150
151void px_lcd_sel_page(uint8_t page)
152{
153#if !PX_LCD_CFG_ROT_180_DEG
154 page = (PX_LCD_NR_OF_PAGES - 1) - page;
155#endif
156
157 px_lcd_wr_control_data(PX_LCD_CMD_PAGE_ADR_SET | page);
158}
159
160void px_lcd_wr_disp_u8(uint8_t data)
161{
162 px_spi_wr(px_lcd_spi_handle, &data, 1, PX_SPI_FLAG_START_AND_STOP);
163}
164
165void px_lcd_wr_disp_data(uint8_t * data, size_t nr_of_bytes)
166{
167 px_spi_wr(px_lcd_spi_handle, data, nr_of_bytes, PX_SPI_FLAG_START_AND_STOP);
168}
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.
#define PX_LOG_D(format,...)
Macro to display a formatted DEBUG message.
Definition: px_log.h:410
#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