ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
pcd8544.h File Reference
#include "fw_hal.h"

Go to the source code of this file.

Data Structures

struct  FontDef_t
 

Macros

#define PCD8544_CS   P35
 
#define PCD8544_MOSI   P34
 
#define PCD8544_SCK   P32
 
#define PCD8544_RES   P37
 
#define PCD8544_DC   P36
 
#define PCD8544_BL   P12
 
#define PCD8544_WIDTH   84
 
#define PCD8544_HEIGHT   48
 
#define PCD8544_PAGES   6
 
#define PCD8544_FUNCTIONSET   0x20
 
#define PCD8544_POWERDOWN   0x04
 
#define PCD8544_ENTRYMODE   0x02
 
#define PCD8544_EXT_INSTRUCTION   0x01
 
#define PCD8544_DISPLAY_CONTROL   0x08
 
#define PCD8544_DISPLAY_BLANK   0x00
 
#define PCD8544_DISPLAY_NORMAL   0x04
 
#define PCD8544_DISPLAY_ALLON   0x01
 
#define PCD8544_DISPLAY_INVERTED   0x05
 
#define PCD8544_SET_YADDR   0x40
 
#define PCD8544_SET_XADDR   0x80
 
#define PCD8544_SET_TEMP   0x04
 
#define PCD8544_SET_BIAS   0x10
 
#define PCD8544_SET_VOP   0x80
 

Functions

void PCD8544_SetBackLightState (HAL_State_t state)
 Turn PCD8544 LCD backlight on or off.
 
void PCD8544_WriteData (uint8_t dat)
 Writes single byte data to PCD8544.
 
void PCD8544_WriteSameData (uint8_t dat, uint32_t size)
 
void PCD8544_WriteCommand (uint8_t command)
 Write a single byte command to PCD8544.
 
void PCD8544_Reset (void)
 Hardware reset PCD8544 LCD.
 
void PCD8544_SetPowerDownMode (HAL_State_t state)
 Powerdown mode control.
 
void PCD8544_SetBias (uint8_t val)
 Set bias system level.
 
void PCD8544_SetTemperatureCoef (uint8_t val)
 Set TCx (temperature coefficient)
 
void PCD8544_SetContrast (uint8_t bias, uint8_t val)
 Set the contrast level by adjusting Vlcd.
 
void PCD8544_SetDisplayAllOn (void)
 Set PCD8544 To Turn On All Segments.
 
void PCD8544_SetDisplayInverted (void)
 Set PCD8544 Display Mode to Inverted.
 
void PCD8544_SetDisplayBlank (void)
 Set PCD8544 Display Mode to Blank.
 
void PCD8544_SetDisplayNormal (void)
 Set PCD8544 Display Mode to Normal.
 
void PCD8544_Init (void)
 Initializes PCD8544 Display.
 
void PCD8544_Fill (uint8_t color)
 Fills entire LCD with specified color.
 
void PCD8544_UpdateScreen (void)
 Update LCD display with changes.
 
void PCD8544_DrawPixel (uint8_t x, uint8_t y, uint8_t color)
 Draws pixel at desired location.
 
void PCD8544_DrawLine (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t color)
 Draws line on LCD.
 
void PCD8544_GotoXY (uint8_t x, uint8_t y)
 Sets cursor pointer to desired location for strings.
 
char PCD8544_Putc (char ch, FontDef_t *font, uint8_t color)
 Put one character to internal RAM.
 
char PCD8544_Puts (char *str, FontDef_t *Font, uint8_t color)
 Puts string to internal RAM.
 

Variables

__CODE FontDef_t Font_3x5
 
__CODE FontDef_t Font_5x7
 

Macro Definition Documentation

◆ PCD8544_BL

#define PCD8544_BL   P12

Definition at line 35 of file pcd8544.h.

◆ PCD8544_CS

#define PCD8544_CS   P35

PCD8544

Philips – PCD8544 is a single-chip low-power CMOS LCD driver controller The chip is designed to drive a graphic display of 84×48 pixels with SPI interface. Display Data RAM = 6 banks x 84 segments x 8 bits = 4032 bits = 504 bytes Each bank contains 84 columns/segments (from 0 to 83) Each column can store 8 bits of data (from 0 to 7)

Definition at line 30 of file pcd8544.h.

◆ PCD8544_DC

#define PCD8544_DC   P36

Definition at line 34 of file pcd8544.h.

◆ PCD8544_DISPLAY_ALLON

#define PCD8544_DISPLAY_ALLON   0x01

Definition at line 52 of file pcd8544.h.

◆ PCD8544_DISPLAY_BLANK

#define PCD8544_DISPLAY_BLANK   0x00

Definition at line 50 of file pcd8544.h.

◆ PCD8544_DISPLAY_CONTROL

#define PCD8544_DISPLAY_CONTROL   0x08

Definition at line 49 of file pcd8544.h.

◆ PCD8544_DISPLAY_INVERTED

#define PCD8544_DISPLAY_INVERTED   0x05

Definition at line 53 of file pcd8544.h.

◆ PCD8544_DISPLAY_NORMAL

#define PCD8544_DISPLAY_NORMAL   0x04

Definition at line 51 of file pcd8544.h.

◆ PCD8544_ENTRYMODE

#define PCD8544_ENTRYMODE   0x02

Definition at line 46 of file pcd8544.h.

◆ PCD8544_EXT_INSTRUCTION

#define PCD8544_EXT_INSTRUCTION   0x01

Definition at line 47 of file pcd8544.h.

◆ PCD8544_FUNCTIONSET

#define PCD8544_FUNCTIONSET   0x20

Definition at line 44 of file pcd8544.h.

◆ PCD8544_HEIGHT

#define PCD8544_HEIGHT   48

Definition at line 40 of file pcd8544.h.

◆ PCD8544_MOSI

#define PCD8544_MOSI   P34

Definition at line 31 of file pcd8544.h.

◆ PCD8544_PAGES

#define PCD8544_PAGES   6

Definition at line 42 of file pcd8544.h.

◆ PCD8544_POWERDOWN

#define PCD8544_POWERDOWN   0x04

Definition at line 45 of file pcd8544.h.

◆ PCD8544_RES

#define PCD8544_RES   P37

Definition at line 33 of file pcd8544.h.

◆ PCD8544_SCK

#define PCD8544_SCK   P32

Definition at line 32 of file pcd8544.h.

◆ PCD8544_SET_BIAS

#define PCD8544_SET_BIAS   0x10

Definition at line 59 of file pcd8544.h.

◆ PCD8544_SET_TEMP

#define PCD8544_SET_TEMP   0x04

Definition at line 58 of file pcd8544.h.

◆ PCD8544_SET_VOP

#define PCD8544_SET_VOP   0x80

Definition at line 60 of file pcd8544.h.

◆ PCD8544_SET_XADDR

#define PCD8544_SET_XADDR   0x80

Definition at line 56 of file pcd8544.h.

◆ PCD8544_SET_YADDR

#define PCD8544_SET_YADDR   0x40

Definition at line 55 of file pcd8544.h.

◆ PCD8544_WIDTH

#define PCD8544_WIDTH   84

Definition at line 38 of file pcd8544.h.

Function Documentation

◆ PCD8544_DrawLine()

void PCD8544_DrawLine ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
uint16_t  y1,
uint8_t  color 
)

Draws line on LCD.

Note
PCD8544_UpdateScreen() must be called after that in order to show updates
Parameters
x0Line X start point, value between [0, PCD8544_WIDTH)
y0Line Y start point, value between [0, PCD8544_HEIGHT)
x1Line X end point, value between [0, PCD8544_WIDTH)
y1Line Y end point, value between [0, PCD8544_HEIGHT)
colorColor to be used. 0x00 or 0x01
Return values
None

Definition at line 177 of file pcd8544.c.

178{
179 int16_t dx, dy, sx, sy, err, e2, i, tmp;
180
181 /* Check for overflow */
182 if (x0 >= PCD8544_WIDTH)
183 {
184 x0 = PCD8544_WIDTH - 1;
185 }
186 if (x1 >= PCD8544_WIDTH)
187 {
188 x1 = PCD8544_WIDTH - 1;
189 }
190 if (y0 >= PCD8544_HEIGHT)
191 {
192 y0 = PCD8544_HEIGHT - 1;
193 }
194 if (y1 >= PCD8544_HEIGHT)
195 {
196 y1 = PCD8544_HEIGHT - 1;
197 }
198
199 dx = (x0 < x1) ? (x1 - x0) : (x0 - x1);
200 dy = (y0 < y1) ? (y1 - y0) : (y0 - y1);
201 sx = (x0 < x1) ? 1 : -1;
202 sy = (y0 < y1) ? 1 : -1;
203 err = ((dx > dy) ? dx : -dy) / 2;
204
205 if (dx == 0)
206 {
207 if (y1 < y0)
208 {
209 tmp = y1;
210 y1 = y0;
211 y0 = tmp;
212 }
213
214 if (x1 < x0)
215 {
216 tmp = x1;
217 x1 = x0;
218 x0 = tmp;
219 }
220
221 /* Vertical line */
222 for (i = y0; i <= y1; i++)
223 {
224 PCD8544_DrawPixel(x0, i, color);
225 }
226 return;
227 }
228
229 if (dy == 0)
230 {
231 if (y1 < y0)
232 {
233 tmp = y1;
234 y1 = y0;
235 y0 = tmp;
236 }
237
238 if (x1 < x0)
239 {
240 tmp = x1;
241 x1 = x0;
242 x0 = tmp;
243 }
244
245 /* Horizontal line */
246 for (i = x0; i <= x1; i++)
247 {
248 PCD8544_DrawPixel(i, y0, color);
249 }
250 return;
251 }
252
253 while (1)
254 {
255 PCD8544_DrawPixel(x0, y0, color);
256 if (x0 == x1 && y0 == y1)
257 {
258 break;
259 }
260 e2 = err;
261 if (e2 > -dx)
262 {
263 err -= dy;
264 x0 += sx;
265 }
266 if (e2 < dy)
267 {
268 err += dx;
269 y0 += sy;
270 }
271 }
272}
short int16_t
Definition: fw_types.h:24
uint8_t __XDATA i
void PCD8544_DrawPixel(uint8_t x, uint8_t y, uint8_t color)
Draws pixel at desired location.
Definition: pcd8544.c:159
#define PCD8544_HEIGHT
Definition: pcd8544.h:40
#define PCD8544_WIDTH
Definition: pcd8544.h:38

◆ PCD8544_DrawPixel()

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

Draws pixel at desired location.

Note
PCD8544_UpdateScreen() must called after that in order to show updates
Parameters
xX location, value between [0, PCD8544_WIDTH)
yY location, value between [0, PCD8544_HEIGHT)
colorColor to be used for screen fill, 0x00 or 0x01
Return values
None

Definition at line 159 of file pcd8544.c.

160{
161 if (x >= PCD8544_WIDTH || y >= PCD8544_HEIGHT)
162 {
163 /* Error */
164 return;
165 }
166
167 if (color == 0x01)
168 {
169 PCD8544_Buffer[x + (y / 8) * PCD8544_WIDTH] |= 1 << (y % 8);
170 }
171 else
172 {
173 PCD8544_Buffer[x + (y / 8) * PCD8544_WIDTH] &= ~(1 << (y % 8));
174 }
175}
static __XDATA uint8_t PCD8544_Buffer[PCD8544_WIDTH *PCD8544_HEIGHT/8]
Definition: pcd8544.c:21
volatile int16_t y
Definition: main.c:34
volatile int16_t x
Definition: main.c:34

◆ PCD8544_Fill()

void PCD8544_Fill ( uint8_t  color)

Fills entire LCD with specified color.

Note
PCD8544_UpdateScreen() must be called after that in order to see updates
Parameters
ColorColor to be used for screen fill, 0x00 or 0x01
Return values
None

Definition at line 141 of file pcd8544.c.

142{
143 /* Set memory */
144 memset((uint8_t *)PCD8544_Buffer, (color == 0x00) ? 0x00 : 0xFF, sizeof(PCD8544_Buffer));
145}
unsigned char uint8_t
Definition: fw_types.h:18

◆ PCD8544_GotoXY()

void PCD8544_GotoXY ( uint8_t  x,
uint8_t  y 
)

Sets cursor pointer to desired location for strings.

Parameters
xX location, value between [0, PCD8544_WIDTH)
yY location, value between [0, PCD8544_HEIGHT)
Return values
None

Definition at line 274 of file pcd8544.c.

275{
276 /* Set write pointers */
279}
uint8_t PCD8544_currentY
Definition: pcd8544.c:20
uint8_t PCD8544_currentX
Definition: pcd8544.c:19

◆ PCD8544_Init()

void PCD8544_Init ( void  )

Initializes PCD8544 Display.

Parameters
None
Return values
None

Definition at line 129 of file pcd8544.c.

130{
132 PCD8544_SetContrast(0x06, 0x20);
134}
void PCD8544_Reset(void)
Hardware reset PCD8544 LCD.
Definition: pcd8544.c:57
void PCD8544_SetContrast(uint8_t bias, uint8_t val)
Set the contrast level by adjusting Vlcd.
Definition: pcd8544.c:87
void PCD8544_SetDisplayNormal(void)
Set PCD8544 Display Mode to Normal.
Definition: pcd8544.c:124

◆ PCD8544_Putc()

char PCD8544_Putc ( char  ch,
FontDef_t font,
uint8_t  color 
)

Put one character to internal RAM.

Note
PCD8544_UpdateScreen() must be called after that in order to show updates
Parameters
chCharacter to be written
*FontPointer to FontDef_t structure with used font
colorColor used for drawing. 0x00 or 0x01
Return values
valueof ch

Definition at line 281 of file pcd8544.c.

282{
283 uint32_t i, b, j, k;
284
285 for (i = 0; i < font->height; i++)
286 {
287 for (j = 0; j < font->bytes; j++)
288 {
289 b = font->dat[((ch - 32) * font->height + i) * font->bytes + j];
290 if (font->order == 0)
291 {
292 for (k = 0; k < 8 && k < font->width - j * 8; k++)
293 {
294 if ((b << k) & 0x80)
295 {
296 PCD8544_DrawPixel(PCD8544_currentX + (j * 8) + k, (PCD8544_currentY + i), (uint8_t) color);
297 }
298 else
299 {
300 PCD8544_DrawPixel(PCD8544_currentX + (j * 8) + k, (PCD8544_currentY + i), (uint8_t) !color);
301 }
302 }
303 }
304 else
305 {
306 for (k = 0; k < 8 && k < font->width - j * 8; k++)
307 {
308 if (b & (0x0001 << k))
309 {
310 PCD8544_DrawPixel(PCD8544_currentX + (j * 8) + k, (PCD8544_currentY + i), (uint8_t) color);
311 }
312 else
313 {
314 PCD8544_DrawPixel(PCD8544_currentX + (j * 8) + k, (PCD8544_currentY + i), (uint8_t) !color);
315 }
316 }
317 }
318 }
319 }
320
321 /* Increase pointer */
322 PCD8544_currentX += font->width + 1;
323
324 /* Return character written */
325 return ch;
326}
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

◆ PCD8544_Puts()

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

Puts string to internal RAM.

Note
PCD8544_UpdateScreen() must be called after that in order to show updates
Parameters
*strString to be written
*FontPointer to FontDef_t structure with used font
colorColor used for drawing. 0x00 or 0x01
Return values
Zeroon success or character value when function failed

Definition at line 328 of file pcd8544.c.

329{
330 /* Write characters */
331 while (*str)
332 {
333 /* Write character by character */
334 if (PCD8544_Putc(*str, Font, color) != *str)
335 {
336 /* Return error */
337 return *str;
338 }
339
340 /* Increase string pointer */
341 str++;
342 }
343
344 /* Everything OK, zero should be returned */
345 return *str;
346}
char PCD8544_Putc(char ch, FontDef_t *font, uint8_t color)
Put one character to internal RAM.
Definition: pcd8544.c:281

◆ PCD8544_Reset()

void PCD8544_Reset ( void  )

Hardware reset PCD8544 LCD.

Parameters
None
Return values
None

Definition at line 57 of file pcd8544.c.

58{
59 PCD8544_RES = 0;
60 SYS_Delay(5);
61 PCD8544_RES = 1;
62}
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
#define PCD8544_RES
Definition: pcd8544.h:33

◆ PCD8544_SetBackLightState()

void PCD8544_SetBackLightState ( HAL_State_t  state)

Turn PCD8544 LCD backlight on or off.

Parameters
stateHAL_State_ON:on, HAL_State_OFF:off
Return values
None

Definition at line 136 of file pcd8544.c.

137{
138 PCD8544_BL = (state == HAL_State_ON)? SET : RESET;
139}
@ HAL_State_ON
Definition: fw_types.h:71
@ RESET
Definition: fw_types.h:84
@ SET
Definition: fw_types.h:85
#define PCD8544_BL
Definition: pcd8544.h:35

◆ PCD8544_SetBias()

void PCD8544_SetBias ( uint8_t  val)

Set bias system level.

Parameters
valbias value, [0x00,0x07], small value may lead to totally blank display
Return values
None

Definition at line 79 of file pcd8544.c.

80{
81 val = val & 0x07;
85}
uint8_t val[MAX7219_BLOCKS]
void PCD8544_WriteCommand(uint8_t command)
Write a single byte command to PCD8544.
Definition: pcd8544.c:40
#define PCD8544_SET_BIAS
Definition: pcd8544.h:59
#define PCD8544_FUNCTIONSET
Definition: pcd8544.h:44
#define PCD8544_EXT_INSTRUCTION
Definition: pcd8544.h:47

◆ PCD8544_SetContrast()

void PCD8544_SetContrast ( uint8_t  bias,
uint8_t  val 
)

Set the contrast level by adjusting Vlcd.

Parameters
bias,biasvalue, [0x00,0x07], small value may lead to totally blank display
valcontrast level, [0x00, 0x7F]
Return values
None

Definition at line 87 of file pcd8544.c.

88{
89 bias = bias & 0x07;
90 val = val & 0x7F;
91 // Extended instruction set
93 // Set Bias System, value can be [0x03, 0x07]
95 // Set Vop, value can be [0x01, 0x7F]
97 // Change back to basic instruction set
99}
#define PCD8544_SET_VOP
Definition: pcd8544.h:60

◆ PCD8544_SetDisplayAllOn()

void PCD8544_SetDisplayAllOn ( void  )

Set PCD8544 To Turn On All Segments.

Parameters
None
Return values
None

Definition at line 109 of file pcd8544.c.

110{
112}
#define PCD8544_DISPLAY_ALLON
Definition: pcd8544.h:52
#define PCD8544_DISPLAY_CONTROL
Definition: pcd8544.h:49

◆ PCD8544_SetDisplayBlank()

void PCD8544_SetDisplayBlank ( void  )

Set PCD8544 Display Mode to Blank.

Parameters
None
Return values
None

Definition at line 119 of file pcd8544.c.

◆ PCD8544_SetDisplayInverted()

void PCD8544_SetDisplayInverted ( void  )

Set PCD8544 Display Mode to Inverted.

Parameters
None
Return values
None

Definition at line 114 of file pcd8544.c.

◆ PCD8544_SetDisplayNormal()

void PCD8544_SetDisplayNormal ( void  )

Set PCD8544 Display Mode to Normal.

Parameters
None
Return values
None

Definition at line 124 of file pcd8544.c.

◆ PCD8544_SetPowerDownMode()

void PCD8544_SetPowerDownMode ( HAL_State_t  state)

Powerdown mode control.

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

Definition at line 64 of file pcd8544.c.

◆ PCD8544_SetTemperatureCoef()

void PCD8544_SetTemperatureCoef ( uint8_t  val)

Set TCx (temperature coefficient)

Parameters
valTCx value, [0x00, 0x03]
Return values
None

Definition at line 101 of file pcd8544.c.

◆ PCD8544_UpdateScreen()

void PCD8544_UpdateScreen ( void  )

Update LCD display with changes.

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

Definition at line 147 of file pcd8544.c.

148{
149 uint8_t i = 0, *pt = PCD8544_Buffer;
150 for (i = 0; i < PCD8544_PAGES; i++)
151 {
155 }
157}
static void PCD8544_Transmit(const uint8_t *pDat, uint32_t size)
Definition: pcd8544.c:47
#define PCD8544_SET_XADDR
Definition: pcd8544.h:56
#define PCD8544_SET_YADDR
Definition: pcd8544.h:55
#define PCD8544_PAGES
Definition: pcd8544.h:42

◆ PCD8544_WriteCommand()

void PCD8544_WriteCommand ( uint8_t  command)

Write a single byte command to PCD8544.

Parameters
commandcommand to be written
Return values
None

Definition at line 40 of file pcd8544.c.

41{
42 PCD8544_DC = 0;
43 PCD8544_WriteData(command);
44 PCD8544_DC = 1;
45}
void PCD8544_WriteData(uint8_t dat)
Writes single byte data to PCD8544.
Definition: pcd8544.c:23
#define PCD8544_DC
Definition: pcd8544.h:34

◆ PCD8544_WriteData()

void PCD8544_WriteData ( uint8_t  dat)

Writes single byte data to PCD8544.

Parameters
datdata to be written
Return values
None

Definition at line 23 of file pcd8544.c.

24{
25 PCD8544_CS = 0;
27 PCD8544_CS = 1;
28}
__CODE int8_t dat[20]
uint8_t SPI_TxRx(uint8_t dat)
Definition: fw_spi.c:20
#define PCD8544_CS
Definition: pcd8544.h:30

◆ PCD8544_WriteSameData()

void PCD8544_WriteSameData ( uint8_t  dat,
uint32_t  size 
)

Definition at line 30 of file pcd8544.c.

31{
32 PCD8544_CS = 0;
33 do
34 {
36 } while (--size);
37 PCD8544_CS = 1;
38}

Variable Documentation

◆ Font_3x5

__CODE FontDef_t Font_3x5
extern

Definition at line 547 of file pcd8544.c.

◆ Font_5x7

__CODE FontDef_t Font_5x7
extern

Definition at line 548 of file pcd8544.c.