LCDDriver_NXP_Arduino 1.0.0
Temperature sensor device operation sample code for Arduino
Loading...
Searching...
No Matches
LCDDriver.cpp
Go to the documentation of this file.
1#include "LCDDriver.h"
2
3/* PCA8561 class ******************************************/
4
5PCA8561::PCA8561( uint8_t i2c_address ) : I2C_device( i2c_address )
6{
7 init();
8}
9
10PCA8561::PCA8561( TwoWire& wire, uint8_t i2c_address ) : I2C_device( wire, i2c_address )
11{
12 init();
13}
14
15void PCA8561::init( void )
16{
17 for ( int i = 0; i < 12; i++ )
18 bf[ i ] = 0x00;
19
20 str_pos = 0;
21
22// reg_w(PCA8561::Display_ctrl_1, 0x01);
23}
24
26{
27}
28
29void PCA8561::begin( void )
30{
32}
33
34void PCA8561::com_seg( int com, int seg, bool v )
35{
36 const int reg[ 4 ][ 3 ] = {
41 };
42
43 bit_op8( reg[ com][ seg / 8 ], (uint8_t)(~(1 << (seg % 8))), v << (seg % 8) );
44}
45
46void PCA8561::puts( const char* s, int dly )
47{
48 while ( int c = *s++ ) {
49 putchar( c );
50 delay( dly );
51 }
52}
53
54void PCA8561::putchar( char c )
55{
56 if ( ('\n' == c) || ('\r' == c)) {
57 clear( true );
58 return;
59 }
60
61 if (4 == str_pos) {
62 for ( int i = 0; i < (4 - 1); i++ )
63 str_buffer[ i ] = str_buffer[ i + 1 ];
64
65 str_buffer[ 3 ] = c;
66 }
67 else {
68 str_buffer[ str_pos++ ] = c;
69 }
70
71 for ( int i = 0; i < str_pos; i++ )
72 char2seg( i, str_buffer[ i ] );
73
74 flush();
75}
76
77void PCA8561::flush( void )
78{
79 reg_w( COM0_07_00, bf, 12 );
80}
81
82void PCA8561::clear( bool no_flush )
83{
84 for ( int i = 0; i < 12; i++ )
85 bf[ i ] = 0x00;
86
87 str_pos = 0;
88
89 if ( !no_flush )
90 flush();
91}
92
93void PCA8561::char2seg( int pos, int c )
94{
95 c = toupper( c );
96
97 if ( (c < 32) || (92 < c) )
98 c = 32;
99
100 uint16_t p = char_pattern[ c - 32 ];
101
102 uint8_t c0 = p & 0x0F;
103 uint8_t c1 = (p >> 4) & 0x0F;
104 uint8_t c2 = (p >> 8) & 0x0F;
105 uint8_t c3 = (p >> 12) & 0x0F;
106
107 bf[ pos / 2 + 0 ] &= ~(0x0F << (4 * (pos % 2)));
108 bf[ pos / 2 + 3 ] &= ~(0x0F << (4 * (pos % 2)));
109 bf[ pos / 2 + 6 ] &= ~(0x0F << (4 * (pos % 2)));
110 bf[ pos / 2 + 9 ] &= ~(0x0F << (4 * (pos % 2)));
111
112 bf[ pos / 2 + 0 ] |= c0 << (4 * (pos % 2));
113 bf[ pos / 2 + 3 ] |= c1 << (4 * (pos % 2));
114 bf[ pos / 2 + 6 ] |= c2 << (4 * (pos % 2));
115 bf[ pos / 2 + 9 ] |= c3 << (4 * (pos % 2));
116}
117
118uint16_t PCA8561::char_pattern[] = { //from ASCII code 32 ~ 92 (61 slots)
119 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4001,
120 0x0000, 0x0000, 0x2AA8, 0x8282, 0x8282, 0x0280, 0x4000, 0x0820,
121 0x1D74, 0x0440, 0x13C4, 0x16C4, 0x06D0, 0x1694, 0x1794, 0x0444,
122 0x17D4, 0x16D4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
123 0x0000, 0x07D4, 0x17B4, 0x1114, 0x9446, 0x1394, 0x0394, 0x1714,
124 0x07D0, 0x9006, 0x1540, 0x21B0, 0x1110, 0x0578, 0x2558, 0x1554,
125 0x03D4, 0x3554, 0x23D4, 0x1694, 0x8006, 0x1550, 0x0930, 0x2D50,
126 0x2828, 0x8028, 0x1824, 0x0000, 0x2008,
127};
void bit_op8(uint8_t reg, uint8_t mask, uint8_t value)
@ Display_ctrl_1
Definition LCDDriver.h:34
@ COM3_15_08
Definition LCDDriver.h:37
@ COM2_17_16
Definition LCDDriver.h:37
@ COM0_07_00
Definition LCDDriver.h:35
@ COM3_17_16
Definition LCDDriver.h:37
@ COM3_07_00
Definition LCDDriver.h:37
@ COM2_07_00
Definition LCDDriver.h:36
@ COM0_15_08
Definition LCDDriver.h:35
@ COM1_15_08
Definition LCDDriver.h:36
@ COM1_07_00
Definition LCDDriver.h:35
@ COM1_17_16
Definition LCDDriver.h:36
@ COM0_17_16
Definition LCDDriver.h:35
@ COM2_15_08
Definition LCDDriver.h:36
void putchar(char c)
Definition LCDDriver.cpp:54
void clear(bool no_flush=false)
Definition LCDDriver.cpp:82
void puts(const char *s, int dly=0)
Definition LCDDriver.cpp:46
void com_seg(int com, int seg, bool v)
Definition LCDDriver.cpp:34
void flush(void)
Definition LCDDriver.cpp:77
static uint16_t char_pattern[61]
Definition LCDDriver.h:166
void init(void)
Definition LCDDriver.cpp:15
PCA8561(uint8_t i2c_address=(0x70 > > 1))
Definition LCDDriver.cpp:5
void char2seg(int pos, int c)
Definition LCDDriver.cpp:93
uint8_t bf[12]
Definition LCDDriver.h:163
void begin(void)
Definition LCDDriver.cpp:29
char str_buffer[4]
Definition LCDDriver.h:164
virtual ~PCA8561()
Definition LCDDriver.cpp:25
int str_pos
Definition LCDDriver.h:165
int reg_w(uint8_t reg_adr, uint8_t *data, uint16_t size)