blob: 10eabe5fd140670cdf0b8be5094152c0a1cdee66 [file] [log] [blame]
zongqiang.zhang0c6a0882019-08-07 14:48:21 +08001/**
2 * \file ST7565R.c
3 * \brief Functions relating to ST7565R.
4 * \author Andy Gock
5 * \see glcd.h
6 */
7
8#include "ST7565R.h"
9#include "glcd_spi.h"
10
11void glcd_command(uint8_t c)
12{
13 GLCD_A0_LOW();
14 glcd_spi_write(c);
15}
16
17void glcd_data(uint8_t c)
18{
19 GLCD_A0_HIGH();
20 glcd_spi_write(c);
21}
22
23void glcd_set_contrast(uint8_t val) {
24 /* Can set a 6-bit value (0 to 63) */
25
26 /* Must send this command byte before setting the contrast */
27 glcd_command(0x81);
28
29 /* Set the contrat value ("electronic volumne register") */
30 if (val > 63) {
31 glcd_command(63);
32 } else {
33 glcd_command(val);
34 }
35 return;
36}
37
38void glcd_power_down(void)
39{
40 /* Command sequence as in ST7565 datasheet */
41 glcd_command(0xac); // Static indicator off
42 glcd_command(0x00); // Static indicator register, not blinking
43 glcd_command(0xae); // Display OFF
44 glcd_command(0xa5); // Display all points ON
45
46 /* Display is now in sleep mode */
47}
48
49void glcd_power_up(void)
50{
51 glcd_command(0xa4); // Display all points OFF
52 glcd_command(0xad); // Static indicator ON
53 glcd_command(0x00); // Static indicator register, not Blinking
54 glcd_command(0xaf);
55
56 return;
57}
58
59void glcd_set_y_address(uint8_t y)
60{
61 glcd_command(ST7565R_PAGE_ADDRESS_SET | (0x0F & y)); /* 0x0F = 0b00001111 */
62}
63
64void glcd_set_x_address(uint8_t x)
65{
66 glcd_set_column_upper(x);
67 glcd_set_column_lower(x);
68}
69
70void glcd_all_on(void)
71{
72 glcd_command(ST7565R_DISPLAY_ALL_ON);
73}
74
75void glcd_normal(void)
76{
77 glcd_command(ST7565R_DISPLAY_NORMAL);
78}
79
80void glcd_set_column_upper(uint8_t addr)
81{
82 glcd_command(ST7565R_COLUMN_ADDRESS_SET_UPPER | (addr >> 4));
83}
84
85void glcd_set_column_lower(uint8_t addr)
86{
87 glcd_command(ST7565R_COLUMN_ADDRESS_SET_LOWER | (0x0f & addr));
88}
89
90void glcd_set_start_line(uint8_t addr)
91{
92 glcd_command( ST7565R_SET_START_LINE | (0x3F & addr)); /* 0x3F == 0b00111111 */
93}
94
95/** Clear the display immediately, does not buffer */
96void glcd_clear_now(void)
97{
98 uint8_t page;
99 for (page = 0; page < GLCD_NUMBER_OF_BANKS1; page++) {
100 uint8_t col;
101 glcd_set_y_address(page);
102 glcd_set_x_address(0);
103 for (col = 0; col < GLCD_NUMBER_OF_COLS1; col++) {
104 glcd_data(0);
105 }
106 }
107}
108
109void glcd_pattern(void)
110{
111 uint8_t page;
112 for (page = 0; page < GLCD_NUMBER_OF_BANKS1; page++) {
113 uint8_t col;
114 glcd_set_y_address(page);
115 glcd_set_x_address(0);
116 for (col = 0; col < GLCD_NUMBER_OF_COLS1; col++) {
117 glcd_data( (col / 8 + 2) % 2 == 1 ? 0xff : 0x00 );
118 }
119 }
120}
121
122
123#define GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M
zongqiang.zhang9da97752019-11-14 16:13:26 +0800124uint8_t contrast = 33;
zongqiang.zhang0c6a0882019-08-07 14:48:21 +0800125void glcd_ST7565R_init(void) {
126
127#if defined(GLCD_INIT_NHD_C12832A1Z_FSW_FBW_3V3)
128
129 /* Init sequence based on datasheet example code for NHD-C12832A1Z-FSW-FBW-3V3 */
130 /* Datasheet says max SCK frequency 20MHz for this LCD */
131 /* We use "reverse direction" for common output mode, as opposed to datasheet specifying "normal direction" */
132
133 glcd_command(0xa0); /* ADC select in normal mode */
134 glcd_command(0xae); /* Display OFF */
135 glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */
136 glcd_command(0xa2); /* LCD bias set at 1/9 */
137 glcd_command(0x2f); /* Power control set to operating mode: 7 */
138 glcd_command(0x21); /* Internal resistor ratio, set to: 1 */
139 glcd_set_contrast(40); /* Set contrast, value experimentally determined, can set to 6-bit value, 0 to 63 */
140 glcd_command(0xaf); /* Display on */
141
142#elif defined(GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT)
143
144 /* Init sequence based on datasheet example code for NHD-C12864A1Z-FSW-FBW-HTT */
145 /* Datasheet says max SCK frequency 2.5MHz for this LCD */
146 /* We use "reverse direction" for common output mode, as opposed to datasheet specifying "normal direction" */
147
148 glcd_command(0xa0); /* ADC select in normal mode */
149 glcd_command(0xae); /* Display OFF */
150 glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */
151 glcd_command(0xa2); /* LCD bias set at 1/9 */
152 glcd_command(0x2f); /* Power control set to operating mode: 7 */
153 glcd_command(0x26); /* Internal resistor ratio, set to: 6 */
154 glcd_set_contrast(30); /* Set contrast, value experimentally determined */
155 glcd_command(0xaf); /* Display on */
156
157#elif defined(GLCD_INIT_NHD_C12864WC_FSW_FBW_3V3_M)
158
159 /* Init sequence for NHD-C12864WC-FSW-FBW-3V3-M */
160
161 glcd_command(ST7565R_RESET); /* Internal reset */
162 glcd_command(0xa2); /* 1/9 bias */
163 glcd_command(0xa0); /* ADC select, normal */
164 glcd_command(0xc8); /* Com output reverse */
165 glcd_command(0xa4); /* Display all points normal */
166 glcd_command(0x40); /* Display start line set */
167 glcd_command(0x25); /* Internal resistor ratio */
168 glcd_set_contrast(contrast); /* Set contrast value, experimentally determined, value 0 to 63 */
169 glcd_command(0x2f); /* Power controller set */
170 glcd_command(0xaf); /* Display on */
171
172#elif defined(GLCD_INIT_ZOLEN_12864_FFSSWE_NAA)
173 /* Init sequence for Zolen 128x64 module with
174 * size 40x35mm. Chip ST7567 */
175
176 glcd_command(0xa0); /* ADC select in normal mode */
177 glcd_command(0xae); /* Display OFF */
178 glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */
179 glcd_command(0xa3); /* LCD bias set at 1/9 */
180 glcd_command(0x2f); /* Power control set to operating mode: 7 */
181 glcd_command(0x24); /* Internal resistor ratio, set to: 6 */
182 glcd_set_contrast(45); /* Set contrast, value experimentally determined, value 0 to 63 */
183 glcd_command(0xaf); /* Display on */
184
185#elif defined(GLCD_MY)
186
187 glcd_command(0xa2); /* 1/9 bias */
188 glcd_command(0xa0); /* Select SEG Normal Direction */
189 glcd_command(0xc0); /* Select COM Normal Direction */
190 glcd_command(0x24); /* Select Regulation Ration=5.0 */
191 glcd_command(0x81); /* Set EV Command */
192 glcd_command(0x20); /* Set EV Command */
193 glcd_command(0x2c); /* Power controller set */
194 glcd_command(0x2e); /* Power controller set */
195 glcd_command(0x2f); /* Power controller set */
196 glcd_command(0xaf); /* Display on */
197#else
198
199 /* Default init sequence */
200 /* Currently just set the same as GLCD_INIT_NHD_C12864A1Z_FSW_FBW_HTT */
201
202 glcd_command(0xa0); /* ADC select in normal mode */
203 glcd_command(0xae); /* Display OFF */
204 glcd_command(0xc8); /* Common output mode select: reverse direction (last 3 bits are ignored) */
205 glcd_command(0xa2); /* LCD bias set at 1/9 */
206 glcd_command(0x2f); /* Power control set to operating mode: 7 */
207 glcd_command(0x26); /* Internal resistor ratio, set to: 6 */
208 glcd_set_contrast(20); /* Set contrast, value experimentally determined, value 0 to 63 */
209 glcd_command(0xaf); /* Display on */
210
211#endif
212
213}