GLCD Library
A C Library for Embedded Applications
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
PCD8544.c
Go to the documentation of this file.
1 
8 /*
9  Copyright (c) 2012, Andy Gock
10 
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of Andy Gock nor the
21  names of its contributors may be used to endorse or promote products
22  derived from this software without specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY
28  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 
36 #if defined(GLCD_CONTROLLER_PCD8544)
37 
38 #include "../glcd.h"
39 
40 void glcd_command(uint8_t c)
41 {
42  GLCD_DC_LOW();
43  glcd_spi_write(c);
44 }
45 
46 void glcd_data(uint8_t c)
47 {
48  GLCD_DC_HIGH();
49  glcd_spi_write(c);
50 }
51 
52 void glcd_set_contrast(uint8_t val) {
54  glcd_command(PCD8544_SET_VOP | (val&0x7f));
57 }
58 
59 void glcd_power_down(void)
60 {
61  /* First, fill RAM with zeroes to ensure minimum specified current consumption */
62  glcd_clear();
63 
64  /* Power down */
66 }
67 
68 void glcd_power_up(void)
69 {
71 }
72 
73 void glcd_set_y_address(uint8_t y)
74 {
75  glcd_command(PCD8544_SET_Y_ADDRESS|(y > 5 ? 5 : y));
76 }
77 
78 void glcd_set_x_address(uint8_t x)
79 {
81 }
82 
83 void glcd_write()
84 {
85  uint8_t bank;
86 
87 
88  for (bank = 0; bank < PCD8544_MAX_BANKS; bank++) {
89  /* Each bank is a single row 8 bits tall */
90  uint8_t column;
91 
92  if (glcd_bbox_selected->y_min >= (bank+1)*8) {
93  continue; /* Skip the entire bank */
94  }
95 
96  if (glcd_bbox_selected->y_max < bank*8) {
97  break; /* No more banks need updating */
98  }
99 
102 
103  for (column = glcd_bbox_selected->x_min; column <= glcd_bbox_selected->x_max; column++)
104  {
105  glcd_data( glcd_buffer_selected[PCD8544_MAX_COLS * bank + column] );
106  }
107  }
108 
109  glcd_reset_bbox();
110 
111 }
112 
113 #endif
#define PCD8544_FUNCTION_SET
Definition: PCD8544.h:43
void glcd_spi_write(uint8_t c)
Write a byte to the connected SPI slave.
void glcd_power_up(void)
Power up the device.
glcd_BoundingBox_t * glcd_bbox_selected
Pointer to bounding box currently in use.
Definition: glcd.c:65
void glcd_write(void)
Update the display within the specified bounding box.
#define PCD8544_SET_VOP
Definition: PCD8544.h:75
#define PCD8544_EXTENDED_INSTRUCTION
Definition: PCD8544.h:47
void glcd_set_x_address(uint8_t x)
Set X address of RAM (column).
#define PCD8544_DISPLAY_NORMAL
Definition: PCD8544.h:56
#define PCD8544_POWER_DOWN
Definition: PCD8544.h:44
uint8_t y_max
Definition: glcd.h:166
#define PCD8544_DISPLAY_CONTROL
Definition: PCD8544.h:54
void glcd_power_down(void)
Power down the device.
uint8_t y_min
Definition: glcd.h:164
#define PCD8544_MAX_BANKS
Definition: PCD8544.h:78
void glcd_data(uint8_t c)
Send data byte to LCD.
uint8_t * glcd_buffer_selected
Pointer to screen buffer currently in use.
Definition: glcd.c:60
#define PCD8544_SET_Y_ADDRESS
Definition: PCD8544.h:59
void glcd_set_y_address(uint8_t y)
Set Y address of RAM (select bank).
void glcd_command(uint8_t c)
Send command byte to LCD.
#define PCD8544_MAX_COLS
Definition: PCD8544.h:79
#define PCD8544_SET_X_ADDRESS
Definition: PCD8544.h:60
uint8_t x_min
Definition: glcd.h:163
void glcd_clear(void)
Clear the display.
Definition: glcd.c:122
void glcd_set_contrast(uint8_t val)
Set contrast.
void glcd_reset_bbox()
Reset the bounding box.
Definition: glcd.c:101