LCDDriver_NXP_Arduino 0.2.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 for ( int i = 0; i < 12; i++ )
8 bf[ i ] = 0x00;
9
10 str_pos = 0;
11
12// reg_w(PCA8561::Display_ctrl_1, 0x01);
13}
14
16{
17}
18
19void PCA8561::begin( void )
20{
21 reg_w(PCA8561::Display_ctrl_1, 0x01);
22}
23
24void PCA8561::com_seg( int com, int seg, bool v )
25{
26 const int reg[ 4 ][ 3 ] = {
31 };
32
33 bit_op8( reg[ com][ seg / 8 ], (uint8_t)(~(1 << (seg % 8))), v << (seg % 8) );
34}
35
36void PCA8561::puts( const char* s, int dly )
37{
38 while ( int c = *s++ ) {
39 putchar( c );
40 delay( dly );
41 }
42}
43
44void PCA8561::putchar( char c )
45{
46 if ( ('\n' == c) || ('\r' == c)) {
47 clear( true );
48 return;
49 }
50
51 if (4 == str_pos) {
52 for ( int i = 0; i < (4 - 1); i++ )
53 str_buffer[ i ] = str_buffer[ i + 1 ];
54
55 str_buffer[ 3 ] = c;
56 }
57 else {
58 str_buffer[ str_pos++ ] = c;
59 }
60
61 for ( int i = 0; i < str_pos; i++ )
62 char2seg( i, str_buffer[ i ] );
63
64 flush();
65}
66
67void PCA8561::flush( void )
68{
69 reg_w( COM0_07_00, bf, 12 );
70}
71
72void PCA8561::clear( bool no_flush )
73{
74 for ( int i = 0; i < 12; i++ )
75 bf[ i ] = 0x00;
76
77 str_pos = 0;
78
79 if ( !no_flush )
80 flush();
81}
82
83void PCA8561::char2seg( int pos, int c )
84{
85 c = toupper( c );
86
87 if ( (c < 32) || (92 < c) )
88 c = 32;
89
90 uint16_t p = char_pattern[ c - 32 ];
91
92 uint8_t c0 = p & 0x0F;
93 uint8_t c1 = (p >> 4) & 0x0F;
94 uint8_t c2 = (p >> 8) & 0x0F;
95 uint8_t c3 = (p >> 12) & 0x0F;
96
97 bf[ pos / 2 + 0 ] &= ~(0x0F << (4 * (pos % 2)));
98 bf[ pos / 2 + 3 ] &= ~(0x0F << (4 * (pos % 2)));
99 bf[ pos / 2 + 6 ] &= ~(0x0F << (4 * (pos % 2)));
100 bf[ pos / 2 + 9 ] &= ~(0x0F << (4 * (pos % 2)));
101
102 bf[ pos / 2 + 0 ] |= c0 << (4 * (pos % 2));
103 bf[ pos / 2 + 3 ] |= c1 << (4 * (pos % 2));
104 bf[ pos / 2 + 6 ] |= c2 << (4 * (pos % 2));
105 bf[ pos / 2 + 9 ] |= c3 << (4 * (pos % 2));
106}
107
108uint16_t PCA8561::char_pattern[] = { //from ASCII code 32 ~ 92 (61 slots)
109 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4001,
110 0x0000, 0x0000, 0x2AA8, 0x8282, 0x8282, 0x0280, 0x4000, 0x0820,
111 0x1D74, 0x0440, 0x13C4, 0x16C4, 0x06D0, 0x1694, 0x1794, 0x0444,
112 0x17D4, 0x16D4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
113 0x0000, 0x07D4, 0x17B4, 0x1114, 0x9446, 0x1394, 0x0394, 0x1714,
114 0x07D0, 0x9006, 0x1540, 0x21B0, 0x1110, 0x0578, 0x2558, 0x1554,
115 0x03D4, 0x3554, 0x23D4, 0x1694, 0x8006, 0x1550, 0x0930, 0x2D50,
116 0x2828, 0x8028, 0x1824, 0x0000, 0x2008,
117};
@ 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:44
void clear(bool no_flush=false)
Definition: LCDDriver.cpp:72
void puts(const char *s, int dly=0)
Definition: LCDDriver.cpp:36
void com_seg(int com, int seg, bool v)
Definition: LCDDriver.cpp:24
void flush(void)
Definition: LCDDriver.cpp:67
static uint16_t char_pattern[61]
Definition: LCDDriver.h:91
PCA8561(uint8_t i2c_address=(0x70 > > 1))
Definition: LCDDriver.cpp:5
void char2seg(int pos, int c)
Definition: LCDDriver.cpp:83
uint8_t bf[12]
Definition: LCDDriver.h:88
void begin(void)
Definition: LCDDriver.cpp:19
char str_buffer[4]
Definition: LCDDriver.h:89
virtual ~PCA8561()
Definition: LCDDriver.cpp:15
int str_pos
Definition: LCDDriver.h:90