ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
st7567.c File Reference
#include "st7567.h"
#include <string.h>

Go to the source code of this file.

Macros

#define ABS(x)   ((x) > 0 ? (x) : -(x))
 

Functions

void ST7567_WriteData (uint8_t dat)
 Write a single byte data to ST7567.
 
void ST7567_WriteSameData (uint8_t dat, uint32_t size)
 
void ST7567_WriteCommand (uint8_t command)
 Write a single byte command to ST7567.
 
static void ST7567_Transmit (const uint8_t *pDat, uint32_t size)
 
void ST7567_Reset (void)
 Hardware reset ST7567 LCD.
 
void ST7567_Init (void)
 Initializes ST7567 LCD.
 
void ST7567_SetPowerSaveMode (HAL_State_t state)
 Powersave mode control.
 
void ST7567_SetBackLightState (HAL_State_t state)
 Turn ST7567 LCD backlight on or off.
 
void ST7567_SetContrast (uint8_t val)
 Turn ST7567 LCD backlight off.
 
void ST7567_UpdateScreen (void)
 Update LCD display with buffer changes.
 
void ST7567_ToggleInvert (void)
 Toggles pixels invertion inside internal RAM.
 
void ST7567_Fill (uint8_t color)
 Fills entire LCD with specified color.
 
void ST7567_DrawPixel (uint8_t x, uint8_t y, uint8_t color)
 Draws pixel at desired location.
 
void ST7567_GotoXY (uint16_t x, uint16_t y)
 Sets cursor pointer to desired location for strings.
 
char ST7567_Putc (char ch, FontDef_t *font, uint8_t color)
 Puts character to internal RAM.
 
char ST7567_Puts (char *str, FontDef_t *Font, uint8_t color)
 Puts string to internal RAM.
 
void ST7567_DrawLine (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t c)
 Draws line on LCD.
 

Variables

__BIT ST7567_colorInverted = RESET
 
uint8_t ST7567_currentX = 0
 
uint8_t ST7567_currentY = 0
 
static __XDATA uint8_t ST7567_Buffer_all [ST7567_WIDTH *ST7567_PAGES]
 
static __CODE uint8_t Font3x5 []
 
static __CODE uint8_t Font5x7 []
 
__CODE FontDef_t Font_3x5 = {3, 5, 1, 1, Font3x5}
 
__CODE FontDef_t Font_5x7 = {5, 7, 1, 1, Font5x7}
 

Macro Definition Documentation

◆ ABS

#define ABS (   x)    ((x) > 0 ? (x) : -(x))

Definition at line 19 of file st7567.c.

Function Documentation

◆ ST7567_DrawLine()

void ST7567_DrawLine ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
uint16_t  y1,
uint8_t  c 
)

Draws line on LCD.

Note
ST7567_UpdateScreen() must be called after that in order to see updated LCD screen
Parameters
x0Line X start point. Valid input is 0 to ST7567_WIDTH - 1
y0Line Y start point. Valid input is 0 to ST7567_HEIGHT - 1
x1Line X end point. Valid input is 0 to ST7567_WIDTH - 1
y1Line Y end point. Valid input is 0 to ST7567_HEIGHT - 1
cColor to be used. This parameter can be a value of ST7567_COLOR_t enumeration
Return values
None

Definition at line 257 of file st7567.c.

258{
259 int16_t dx, dy, sx, sy, err, e2, i, tmp;
260
261 /* Check for overflow */
262 if (x0 >= ST7567_WIDTH)
263 {
264 x0 = ST7567_WIDTH - 1;
265 }
266 if (x1 >= ST7567_WIDTH)
267 {
268 x1 = ST7567_WIDTH - 1;
269 }
270 if (y0 >= ST7567_HEIGHT)
271 {
272 y0 = ST7567_HEIGHT - 1;
273 }
274 if (y1 >= ST7567_HEIGHT)
275 {
276 y1 = ST7567_HEIGHT - 1;
277 }
278
279 dx = (x0 < x1) ? (x1 - x0) : (x0 - x1);
280 dy = (y0 < y1) ? (y1 - y0) : (y0 - y1);
281 sx = (x0 < x1) ? 1 : -1;
282 sy = (y0 < y1) ? 1 : -1;
283 err = ((dx > dy) ? dx : -dy) / 2;
284
285 if (dx == 0)
286 {
287 if (y1 < y0)
288 {
289 tmp = y1;
290 y1 = y0;
291 y0 = tmp;
292 }
293
294 if (x1 < x0)
295 {
296 tmp = x1;
297 x1 = x0;
298 x0 = tmp;
299 }
300
301 /* Vertical line */
302 for (i = y0; i <= y1; i++)
303 {
304 ST7567_DrawPixel(x0, i, c);
305 }
306
307 /* Return from function */
308 return;
309 }
310
311 if (dy == 0)
312 {
313 if (y1 < y0)
314 {
315 tmp = y1;
316 y1 = y0;
317 y0 = tmp;
318 }
319
320 if (x1 < x0)
321 {
322 tmp = x1;
323 x1 = x0;
324 x0 = tmp;
325 }
326
327 /* Horizontal line */
328 for (i = x0; i <= x1; i++)
329 {
330 ST7567_DrawPixel(i, y0, c);
331 }
332
333 /* Return from function */
334 return;
335 }
336
337 while (1)
338 {
339 ST7567_DrawPixel(x0, y0, c);
340 if (x0 == x1 && y0 == y1)
341 {
342 break;
343 }
344 e2 = err;
345 if (e2 > -dx)
346 {
347 err -= dy;
348 x0 += sx;
349 }
350 if (e2 < dy)
351 {
352 err += dx;
353 y0 += sy;
354 }
355 }
356}
short int16_t
Definition: fw_types.h:24
uint8_t __XDATA i
void ST7567_DrawPixel(uint8_t x, uint8_t y, uint8_t color)
Draws pixel at desired location.
Definition: st7567.c:164
#define ST7567_WIDTH
Definition: st7567.h:38
#define ST7567_HEIGHT
Definition: st7567.h:40

◆ ST7567_DrawPixel()

void ST7567_DrawPixel ( uint8_t  x,
uint8_t  y,
uint8_t  color 
)

Draws pixel at desired location.

Note
ST7567_UpdateScreen() must called after that in order to see updates
Parameters
xX location. This parameter can be a value between 0 and ST7567_WIDTH - 1
yY location. This parameter can be a value between 0 and ST7567_HEIGHT - 1
colorColor to be used for screen fill. This parameter can be a value of ST7567_COLOR_t enumeration
Return values
None

Definition at line 164 of file st7567.c.

165{
166 uint8_t page, column;
167 if (x >= ST7567_WIDTH || y >= ST7567_HEIGHT)
168 {
169 /* Error */
170 return;
171 }
172
173 if (color == ST7567_COLOR_FRONT)
174 {
175 ST7567_Buffer_all[x + (y / 8) * ST7567_WIDTH] |= 1 << (y % 8);
176 }
177 else
178 {
179 ST7567_Buffer_all[x + (y / 8) * ST7567_WIDTH] &= ~(1 << (y % 8));
180 }
181}
unsigned char uint8_t
Definition: fw_types.h:18
volatile int16_t y
Definition: main.c:34
volatile int16_t x
Definition: main.c:34
static __XDATA uint8_t ST7567_Buffer_all[ST7567_WIDTH *ST7567_PAGES]
Definition: st7567.c:25
#define ST7567_COLOR_FRONT
Definition: st7567.h:143

◆ ST7567_Fill()

void ST7567_Fill ( uint8_t  Color)

Fills entire LCD with specified color.

Note
ST7567_UpdateScreen() must be called after that in order to see updates
Parameters
ColorColor to be used for screen fill, ST7567_COLOR_FRONT or ST7567_COLOR_BACK
Return values
None

Definition at line 158 of file st7567.c.

159{
160 /* Set memory */
161 memset((uint8_t *)ST7567_Buffer_all, (color == ST7567_COLOR_BACK) ? 0x00 : 0xFF, sizeof(ST7567_Buffer_all));
162}
#define ST7567_COLOR_BACK
Definition: st7567.h:145

◆ ST7567_GotoXY()

void ST7567_GotoXY ( uint16_t  x,
uint16_t  y 
)

Sets cursor pointer to desired location for strings.

Parameters
xX location. This parameter can be a value between 0 and ST7567_WIDTH - 1
yY location. This parameter can be a value between 0 and ST7567_HEIGHT - 1
Return values
None

Definition at line 183 of file st7567.c.

184{
185 /* Set write pointers */
188}
uint8_t ST7567_currentY
Definition: st7567.c:24
uint8_t ST7567_currentX
Definition: st7567.c:23

◆ ST7567_Init()

void ST7567_Init ( void  )

Initializes ST7567 LCD.

Parameters
None
Return values
None

Definition at line 68 of file st7567.c.

69{
72
74 // adjust contrast
77 // adjust regular voltage. LCD may fail to display if it is set too low.
83 // Start from line 0
85 // Start from page 0
87 // Start from column 0
90 // power control, LCD may fail to display if it is not properly set.
91 // recommend to set them all
98}
@ HAL_State_ON
Definition: fw_types.h:71
void ST7567_WriteCommand(uint8_t command)
Write a single byte command to ST7567.
Definition: st7567.c:44
void ST7567_Reset(void)
Hardware reset ST7567 LCD.
Definition: st7567.c:61
void ST7567_SetBackLightState(HAL_State_t state)
Turn ST7567 LCD backlight on or off.
Definition: st7567.c:121
#define ST7567_DISPLAY_ON
Definition: st7567.h:55
#define ST7567_REGULATION_RATIO_5_0
Definition: st7567.h:110
#define ST7567_POWER_CONTROL
Definition: st7567.h:94
#define ST7567_X_ORIENT
Definition: st7567.h:46
#define ST7567_POWER_CONTROL_VR
Definition: st7567.h:96
#define ST7567_SET_PAGE_ADDRESS
Definition: st7567.h:60
#define ST7567_Y_ORIENT
Definition: st7567.h:48
#define ST7567_SET_START_LINE_MASK
Definition: st7567.h:58
#define ST7567_REGULATION_RATIO
Definition: st7567.h:105
#define ST7567_SET_PAGE_ADDRESS_MASK
Definition: st7567.h:61
#define ST7567_ALL_PIXEL_NORMAL
Definition: st7567.h:79
#define ST7567_SET_COLUMN_ADDRESS_MSB
Definition: st7567.h:63
#define ST7567_POWER_CONTROL_VF
Definition: st7567.h:95
#define ST7567_SET_COLUMN_ADDRESS_MSB_MASK
Definition: st7567.h:64
#define ST7567_BIAS_1_9
Definition: st7567.h:82
#define ST7567_SET_EV_MASK
Definition: st7567.h:122
#define ST7567_SET_EV
Definition: st7567.h:121
#define ST7567_SET_COLUMN_ADDRESS_LSB_MASK
Definition: st7567.h:67
#define ST7567_RESET
Definition: st7567.h:88
#define ST7567_POWER_CONTROL_VB
Definition: st7567.h:97
#define ST7567_SET_START_LINE
Definition: st7567.h:57
#define ST7567_INVERSE_DISPLAY_OFF
Definition: st7567.h:75
#define ST7567_SET_COLUMN_ADDRESS_LSB
Definition: st7567.h:66

◆ ST7567_Putc()

char ST7567_Putc ( char  ch,
FontDef_t Font,
uint8_t  color 
)

Puts character to internal RAM.

Note
ST7567_UpdateScreen() must be called after that in order to see updated LCD screen
Parameters
chCharacter to be written
*FontPointer to FontDef_t structure with used font
colorColor used for drawing. This parameter can be a value of ST7567_COLOR_t enumeration
Return values
Characterwritten

Definition at line 190 of file st7567.c.

191{
192 uint32_t i, b, j, k;
193
194 for (i = 0; i < font->height; i++)
195 {
196 for (j = 0; j < font->bytes; j++)
197 {
198 b = font->dat[((ch - 32) * font->height + i) * font->bytes + j];
199 if (font->order == 0)
200 {
201 for (k = 0; k < 8 && k < font->width - j * 8; k++)
202 {
203 if ((b << k) & 0x80)
204 {
205 ST7567_DrawPixel(ST7567_currentX + (j * 8) + k, (ST7567_currentY + i), (uint8_t) color);
206 }
207 else
208 {
209 ST7567_DrawPixel(ST7567_currentX + (j * 8) + k, (ST7567_currentY + i), (uint8_t) !color);
210 }
211 }
212 }
213 else
214 {
215 for (k = 0; k < 8 && k < font->width - j * 8; k++)
216 {
217 if (b & (0x0001 << k))
218 {
219 ST7567_DrawPixel(ST7567_currentX + (j * 8) + k, (ST7567_currentY + i), (uint8_t) color);
220 }
221 else
222 {
223 ST7567_DrawPixel(ST7567_currentX + (j * 8) + k, (ST7567_currentY + i), (uint8_t) !color);
224 }
225 }
226 }
227 }
228 }
229
230 /* Increase pointer */
231 ST7567_currentX += font->width + 1;
232
233 /* Return character written */
234 return ch;
235}
return ch
unsigned long uint32_t
Definition: fw_types.h:20
uint8_t height
Definition: pcd8544.h:64
const uint8_t * dat
Definition: pcd8544.h:67
uint8_t order
Definition: pcd8544.h:65
uint8_t bytes
Definition: pcd8544.h:66
uint8_t width
Definition: pcd8544.h:63

◆ ST7567_Puts()

char ST7567_Puts ( char *  str,
FontDef_t Font,
uint8_t  color 
)

Puts string to internal RAM.

Note
ST7567_UpdateScreen() must be called after that in order to see updated LCD screen
Parameters
*strString to be written
*FontPointer to FontDef_t structure with used font
colorColor used for drawing. This parameter can be a value of ST7567_COLOR_t enumeration
Return values
Zeroon success or character value when function failed

Definition at line 237 of file st7567.c.

238{
239 /* Write characters */
240 while (*str)
241 {
242 /* Write character by character */
243 if (ST7567_Putc(*str, Font, color) != *str)
244 {
245 /* Return error */
246 return *str;
247 }
248
249 /* Increase string pointer */
250 str++;
251 }
252
253 /* Everything OK, zero should be returned */
254 return *str;
255}
char ST7567_Putc(char ch, FontDef_t *font, uint8_t color)
Puts character to internal RAM.
Definition: st7567.c:190

◆ ST7567_Reset()

void ST7567_Reset ( void  )

Hardware reset ST7567 LCD.

Parameters
None
Return values
None

Definition at line 61 of file st7567.c.

62{
63 ST7567_RES = 0;
64 SYS_Delay(5);
65 ST7567_RES = 1;
66}
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
#define ST7567_RES
Definition: st7567.h:33

◆ ST7567_SetBackLightState()

void ST7567_SetBackLightState ( HAL_State_t  state)

Turn ST7567 LCD backlight on or off.

Parameters
stateHAL_State_ON:on, HAL_State_OFF:off
Return values
None

Definition at line 121 of file st7567.c.

122{
123 ST7567_BL = (state == HAL_State_ON)? SET : RESET;
124}
@ RESET
Definition: fw_types.h:84
@ SET
Definition: fw_types.h:85
#define ST7567_BL
Definition: st7567.h:35

◆ ST7567_SetContrast()

void ST7567_SetContrast ( uint8_t  val)

Turn ST7567 LCD backlight off.

Parameters
valvalue between 0x00 ~ 0x3F
Return values
None

Definition at line 126 of file st7567.c.

127{
130}
uint8_t val[MAX7219_BLOCKS]

◆ ST7567_SetPowerSaveMode()

void ST7567_SetPowerSaveMode ( HAL_State_t  state)

Powersave mode control.

Parameters
stateHAL_State_ON:powersave mode, HAL_State_OFF:work mode
Return values
None

Definition at line 100 of file st7567.c.

101{
102#if (ST7567_MODEL == ST7567_MODEL_ST7565)
103 if (state == HAL_State_ON)
104 ST7567_WriteCommand(ST7567_MODE_SLEEP);
105 else
106 ST7567_WriteCommand(ST7567_MODE_NORMAL);
107#else
108 if (state == HAL_State_ON)
109 {
112 }
113 else
114 {
117 }
118#endif
119}
#define ST7567_DISPLAY_OFF
Definition: st7567.h:54
#define ST7567_ALL_PIXEL_ON
Definition: st7567.h:78

◆ ST7567_ToggleInvert()

void ST7567_ToggleInvert ( void  )

Toggles pixels invertion inside internal RAM.

Note
ST7567_UpdateScreen() must be called after that in order to see updated LCD screen
Parameters
None
Return values
None

Definition at line 144 of file st7567.c.

145{
146 /* Toggle invert */
149 {
151 }
152 else
153 {
155 }
156}
__BIT ST7567_colorInverted
Definition: st7567.c:22
#define ST7567_INVERSE_DISPLAY_ON
Definition: st7567.h:76

◆ ST7567_Transmit()

static void ST7567_Transmit ( const uint8_t pDat,
uint32_t  size 
)
static

Definition at line 51 of file st7567.c.

52{
53 ST7567_CS = 0;
54 do
55 {
56 SPI_TxRx(*pDat++);
57 } while (--size);
58 ST7567_CS = 1;
59}
uint8_t SPI_TxRx(uint8_t dat)
Definition: fw_spi.c:20
#define ST7567_CS
Definition: st7567.h:30

◆ ST7567_UpdateScreen()

void ST7567_UpdateScreen ( void  )

Update LCD display with buffer changes.

Note
Call this function each time when display is changed
Parameters
None
Return values
None

Definition at line 132 of file st7567.c.

133{
134 uint8_t i = 0, *pt = ST7567_Buffer_all;
135 for (i = 0; i < ST7567_PAGES; i++)
136 {
141 }
142}
static void ST7567_Transmit(const uint8_t *pDat, uint32_t size)
Definition: st7567.c:51
#define ST7567_PAGES
Definition: st7567.h:44

◆ ST7567_WriteCommand()

void ST7567_WriteCommand ( uint8_t  command)

Write a single byte command to ST7567.

Parameters
commandcommand
Return values
None

Definition at line 44 of file st7567.c.

45{
46 ST7567_DC = 0;
47 ST7567_WriteData(command);
48 ST7567_DC = 1;
49}
void ST7567_WriteData(uint8_t dat)
Write a single byte data to ST7567.
Definition: st7567.c:27
#define ST7567_DC
Definition: st7567.h:34

◆ ST7567_WriteData()

void ST7567_WriteData ( uint8_t  dat)

Write a single byte data to ST7567.

Parameters
datdata
Return values
None

Definition at line 27 of file st7567.c.

28{
29 ST7567_CS = 0;
31 ST7567_CS = 1;
32}
__CODE int8_t dat[20]

◆ ST7567_WriteSameData()

void ST7567_WriteSameData ( uint8_t  dat,
uint32_t  size 
)

Definition at line 34 of file st7567.c.

35{
36 ST7567_CS = 0;
37 do
38 {
40 } while (--size);
41 ST7567_CS = 1;
42}

Variable Documentation

◆ Font3x5

__CODE uint8_t Font3x5[]
static

Definition at line 358 of file st7567.c.

◆ Font5x7

__CODE uint8_t Font5x7[]
static

Definition at line 457 of file st7567.c.

◆ Font_3x5

__CODE FontDef_t Font_3x5 = {3, 5, 1, 1, Font3x5}

Definition at line 556 of file st7567.c.

◆ Font_5x7

__CODE FontDef_t Font_5x7 = {5, 7, 1, 1, Font5x7}

Definition at line 557 of file st7567.c.

◆ ST7567_Buffer_all

__XDATA uint8_t ST7567_Buffer_all[ST7567_WIDTH *ST7567_PAGES]
static

Definition at line 25 of file st7567.c.

◆ ST7567_colorInverted

__BIT ST7567_colorInverted = RESET

Definition at line 22 of file st7567.c.

◆ ST7567_currentX

uint8_t ST7567_currentX = 0

Definition at line 23 of file st7567.c.

◆ ST7567_currentY

uint8_t ST7567_currentY = 0

Definition at line 24 of file st7567.c.