-
Notifications
You must be signed in to change notification settings - Fork 0
/
hal_LCD.c
231 lines (212 loc) · 7.21 KB
/
hal_LCD.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* --COPYRIGHT--,BSD
* Copyright (c) 2014, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --/COPYRIGHT--*/
/*******************************************************************************
*
* hal_LCD.c
*
* Hardware abstraction layer for the FH-1138P Segmented LCD
*
* September 2014
* E. Chen
*
******************************************************************************/
#include "hal_LCD.h"
#include "string.h"
#include "main.h"
// LCD memory map for numeric digits
const char digit[13][2] =
{
{0x01, 0x00}, /* "-" */
{0x10, 0x00}, /* "." */
{0x00, 0x28}, /* "/" */
{0xFC, 0x28}, /* "0" LCD segments a+b+c+d+e+f+k+q */
{0x60, 0x20}, /* "1" */
{0xDB, 0x00}, /* "2" */
{0xF3, 0x00}, /* "3" */
{0x67, 0x00}, /* "4" */
{0xB7, 0x00}, /* "5" */
{0xBF, 0x00}, /* "6" */
{0xE4, 0x00}, /* "7" */
{0xFF, 0x00}, /* "8" */
{0xF7, 0x00} /* "9" */
};
// LCD memory map for uppercase letters
const char alphabetBig[26][2] =
{
{0xEF, 0x00}, /* "A" LCD segments a+b+c+e+f+g+m */
{0xF1, 0x50}, /* "B" */
{0x9C, 0x00}, /* "C" */
{0xF0, 0x50}, /* "D" */
{0x9F, 0x00}, /* "E" */
{0x8F, 0x00}, /* "F" */
{0xBD, 0x00}, /* "G" */
{0x6F, 0x00}, /* "H" */
{0x90, 0x50}, /* "I" */
{0x78, 0x00}, /* "J" */
{0x0E, 0x22}, /* "K" */
{0x1C, 0x00}, /* "L" */
{0x6C, 0xA0}, /* "M" */
{0x6C, 0x82}, /* "N" */
{0xFC, 0x00}, /* "O" */
{0xCF, 0x00}, /* "P" */
{0xFC, 0x02}, /* "Q" */
{0xCF, 0x02}, /* "R" */
{0xB7, 0x00}, /* "S" */
{0x80, 0x50}, /* "T" */
{0x7C, 0x00}, /* "U" */
{0x0C, 0x28}, /* "V" */
{0x6C, 0x0A}, /* "W" */
{0x00, 0xAA}, /* "X" */
{0x00, 0xB0}, /* "Y" */
{0x90, 0x28} /* "Z" */
};
const char specialChar[3][2] =
{
{0x00, 0x22}, /* "[" - Will appear as "<" */
{0x00, 0x82}, /* "\" */
{0x00, 0x88} /* "]" - Will appear as ">" */
};
void Init_LCD()
{
// L0~L26 & L36~L39 pins selected
LCD_E_setPinAsLCDFunctionEx(LCD_E_BASE, LCD_E_SEGMENT_LINE_0, LCD_E_SEGMENT_LINE_26);
LCD_E_setPinAsLCDFunctionEx(LCD_E_BASE, LCD_E_SEGMENT_LINE_36, LCD_E_SEGMENT_LINE_39);
LCD_E_initParam initParams = {0};
initParams.clockSource = LCD_E_CLOCKSOURCE_XTCLK;
initParams.clockDivider = LCD_E_CLOCKDIVIDER_3;
initParams.muxRate = LCD_E_4_MUX;
initParams.waveforms = LCD_E_STANDARD_WAVEFORMS;
initParams.segments = LCD_E_SEGMENTS_ENABLED;
// Init LCD as 4-mux mode
LCD_E_init(LCD_E_BASE, &initParams);
// LCD Operation - Mode 3, internal 3.02v, charge pump 256Hz
LCD_E_setVLCDSource(LCD_E_BASE, LCD_E_INTERNAL_REFERENCE_VOLTAGE, LCD_E_EXTERNAL_SUPPLY_VOLTAGE);
LCD_E_setVLCDVoltage(LCD_E_BASE, LCD_E_REFERENCE_VOLTAGE_2_96V);
LCD_E_enableChargePump(LCD_E_BASE);
LCD_E_setChargePumpFreq(LCD_E_BASE, LCD_E_CHARGEPUMP_FREQ_16);
// Clear LCD memory
LCD_E_clearAllMemory(LCD_E_BASE);
// Configure COMs and SEGs
// L0 = COM0, L1 = COM1, L2 = COM2, L3 = COM3
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_0, LCD_E_MEMORY_COM0);
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_1, LCD_E_MEMORY_COM1);
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_2, LCD_E_MEMORY_COM2);
LCD_E_setPinAsCOM(LCD_E_BASE, LCD_E_SEGMENT_LINE_3, LCD_E_MEMORY_COM3);
// Select to display main LCD memory
LCD_E_selectDisplayMemory(LCD_E_BASE, LCD_E_DISPLAYSOURCE_MEMORY);
// Turn on LCD
LCD_E_on(LCD_E_BASE);
}
/*
* Scrolls input string across LCD screen from left to right
*/
void displayScrollText(char *msg)
{
int length = strlen(msg);
int i;
int s = 5;
char buffer[6] = " ";
for (i=0; i<length+7; i++)
{
int t;
for (t=0; t<6; t++)
buffer[t] = ' ';
int j;
for (j=0; j<length; j++)
{
if (((s+j) >= 0) && ((s+j) < 6))
buffer[s+j] = msg[j];
}
s--;
showChar(buffer[0], pos1);
showChar(buffer[1], pos2);
showChar(buffer[2], pos3);
showChar(buffer[3], pos4);
showChar(buffer[4], pos5);
showChar(buffer[5], pos6);
__delay_cycles(200000);
}
}
/*
* Displays input character at given LCD digit/position
* Only spaces, numeric digits, and uppercase letters are accepted characters
*/
void showChar(char c, int position)
{
if (c == ' ')
{
// Display space
LCDMEMW[position/2] = 0;
}
else if (c >= '-' && c <= '9')
{
// Display digit
LCDMEMW[position/2] = digit[c-45][0] | (digit[c-45][1] << 8);
}
else if (c >= 'A' && c <= 'Z')
{
// Display alphabet
LCDMEMW[position/2] = alphabetBig[c-65][0] | (alphabetBig[c-65][1] << 8);
}
else if (c >= '[' && c <= ']')
{
LCDMEMW[position/2] = specialChar[c-91][0] | (specialChar[c-91][1] << 8);
}
else
{
// Turn all segments on if character is not a space, digit, or uppercase letter
LCDMEMW[position/2] = 0xFFFF;
}
}
/*
* Displays hex value
*/
void showHex(int hex)
{
showChar((char)((0xC0 & hex) >> 6) + '0', pos3);
showChar((char)((0x30 & hex) >> 4) + '0', pos4);
showChar((char)((0x0C & hex) >> 2) + '0', pos5);
showChar((char)(0x03 & hex) + '0', pos6);
}
/*
* Clears memories to all 6 digits on the LCD
*/
void clearLCD()
{
LCDMEMW[pos1/2] = 0;
LCDMEMW[pos2/2] = 0;
LCDMEMW[pos3/2] = 0;
LCDMEMW[pos4/2] = 0;
LCDMEMW[pos5/2] = 0;
LCDMEMW[pos6/2] = 0;
LCDMEM[12] = LCDMEM[13] = 0;
}