-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_LCD.c
382 lines (360 loc) · 7.93 KB
/
main_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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#include <msp430xG46x.h>
#include "LCD_defs.h"
void LCD_min();
void LCD_all_off();
void LCD_sec();
void LCD_msec();
unsigned char min, sec;
unsigned int msec;
int main( void )
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
// Select COM1-COM2-COM3
P5DIR |= 0x1E; // Ports P5.2, P5.3 and P5.4 as outputs
P5SEL |= 0x1E; // Ports P5.2, P5.3 and P5.4 as special function (COM1, COM2 and COM3)
// Active S4 to S25
LCDAPCTL0 = LCDS24 | LCDS20 | LCDS16 | LCDS12 | LCDS8 | LCDS4;
// LCDA configuration
LCDACTL = LCDFREQ_192 | LCD4MUX | LCDSON | LCDON; // (ACLK = 32768)/192, 4-mux LCD, LCD_A on, Segments on
LCDAVCTL0 = LCDCPEN; // Charge pump enable
LCDAVCTL1 = VLCD_3_44; // VLCD = 3,44 V
LCD_all_off();
// Timer_A configuration
TAR = 0; // Clean Timer A counter
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 3268; // this count correspond to 1 mseg
TACTL = TASSEL_1 + MC_1 + ID_0; // ACLK, continuous mode
//TACTL = TASSEL_1 + MC_1 + ID_0 + TAIE;
// LED1 and LED2 configuration
P2DIR = 0xFF; // P2 as output
P2OUT = 0x04; // Set P1.1 and P1.2
// SW1 and SW2 ports configuration
P1SEL &= ~0x03; // P1.0 and P1.1 I/O ports
P1DIR &= ~0x03; // P1.0 and P1.1 digital inputs
P1IFG = 0x00; // clear all interrupts pending
P1IE |= 0x03; // enable port interrupts
// init memory clock data
min = 0;
sec = 0;
msec = 0;
LCD_min();
LCD_sec();
LCD_msec();
_BIS_SR(LPM3_bits + GIE); // Enable interrupts and enter LPM3
}
//******************************************************************
// Write min
//******************************************************************
void LCD_min()
{
unsigned char min1,min2;
min1 = min/10;
min2 = min%10;
switch (min1)
{
case 1: P7_A1;
break;
case 2: P7_A2;
break;
case 3: P7_A3;
break;
case 4: P7_A4;
break;
case 5: P7_A5;
break;
case 0: P7_A0;
break;
}
switch (min2)
{
case 1: P6_A1;
break;
case 2: P6_A2;
break;
case 3: P6_A3;
break;
case 4: P6_A4;
break;
case 5: P6_A5;
break;
case 6: P6_A6;
break;
case 7: P6_A7;
break;
case 8: P6_A8;
break;
case 9: P6_A9;
break;
case 0: P6_A0;
break;
}
}
//******************************************************************
// Write sec
//******************************************************************
void LCD_sec()
{
unsigned char sec1,sec2;
sec1 = sec / 10;
sec2 = sec % 10;
switch (sec1)
{
case 1:P5_A1;
break;
case 2:P5_A2;
break;
case 3:P5_A3;
break;
case 4:P5_A4;
break;
case 5:P5_A5;
break;
case 0:P5_A0;
break;
}
switch (sec2)
{
case 1: P4_A1;
break;
case 2: P4_A2;
break;
case 3: P4_A3;
break;
case 4: P4_A4;
break;
case 5: P4_A5;
break;
case 6: P4_A6;
break;
case 7: P4_A7;
break;
case 8: P4_A8;
break;
case 9: P4_A9;
break;
case 0: P4_A0;
}
}
//******************************************************************
// Write msec
//******************************************************************
void LCD_msec()
{
switch (msec)
{
case 1: P3_A1;
break;
case 2: P3_A2;
break;
case 3: P3_A3;
break;
case 4: P3_A4;
break;
case 5: P3_A5;
break;
case 6: P3_A6;
break;
case 7: P3_A7;
break;
case 8: P3_A8;
break;
case 9: P3_A9;
break;
case 0: P3_A0;
break;
}
P2_A0;
P1_A0;
}
//******************************************************************
// Timer_A ISR
//******************************************************************
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0_ISR (void)
{
P2OUT |=0x02; // LED1 turn on
P2OUT ^=0x04; // LED2 toogle
msec++; // manage memory clock
LCD_msec();
if (msec == 10)
{
msec = 0;
sec++;
LCD_sec();
if (sec == 60)
{
sec = 0;
min++;
LCD_min();
if (min == 60)
{
min = 0;
}
}
}
if (sec & 0x01) // toogle clock dots
{
P3_DOT_ON;
P5_DOT_ON;
}
else
{
P3_DOT_OFF;
P5_DOT_OFF;
}
P2OUT &=~0x02; // LED1 turn off
switch (sec) // LCD demo
{
case 2:
PL_ON;
PR_ON;
DOLLAR_ON;
break;
case 4:
P1_ON;
RX_ON;
break;
case 6:
P2_ON;
DOLLAR_OFF;
break;
case 8:
P3_ON;
TX_ON;
break;
case 10:
P4_ON;
AU_ON;
break;
case 12:
AR_ON;
AU_OFF;
TX_OFF;
RX_OFF;
break;
case 14:
AD_ON;
AR_OFF;
ERRO_ON;
break;
case 16:
AL_ON;
AD_OFF;
ANT_ON;
break;
case 18:
AL_OFF;
break;
case 20:
PL_OFF;
P1_OFF;
P2_OFF;
P3_OFF;
P4_OFF;
PR_OFF;
break;
case 22:
ERRO_OFF;
break;
case 24:
break;
case 26:
BAT_LOW;
break;
case 28:
BAT_50;
SIGN_LESS_ON;
break;
case 30:
BAT_90;
MEMO_ON;
break;
case 32:
BAT_FULL;
ANT_OFF;
MEMO_OFF;
break;
case 34:
break;
case 36:
SIGN_LESS_OFF;
break;
case 38:
break;
case 40:
break;
case 42:
BAT_OFF;
break;
case 44:
BAT_FULL;
LEV_1;
break;
case 46:
BAT_OFF;
LEV_2;
break;
case 48:
BAT_FULL;
LEV_3;
break;
case 50:
BAT_OFF;
LEV_OFF;
F1_ON;
F4_OFF;
break;
case 52:
F2_ON;
break;
case 54:
F3_ON;
F1_OFF;
break;
case 56:
F4_ON;
F2_OFF;
break;
case 58:
F4_OFF;
F3_OFF;
ENV_ON;
break;
}
}
//******************************************************************
// Port1 Interrupt Service Rotine
//******************************************************************
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR (void)
{
if (P1IFG == 0x01) // SW1 interrupt
{ // change charg Pump Voltage
if ((LCDAVCTL1 & 0x1E) > 0x1E) LCDAVCTL1 = 0;
else LCDAVCTL1 +=0x02;
}
if (P1IFG == 0x02) // SW2 interrupt
{ // change LCD frequency
if ((LCDACTL & 0xE0)== 0xE0) LCDACTL &= ~0xE0;
else LCDACTL += 0x20;
}
P1IFG = 0x00; // clean all pending interrupts
}
//******************************************************************
// LCD clean routine
//******************************************************************
void LCD_all_off(void)
{
LCDM2 = 0x00;
LCDM3 = 0x00;
LCDM4 = 0x00;
LCDM5 = 0x00;
LCDM6 = 0x00;
LCDM7 = 0x00;
LCDM8 = 0x00;
LCDM9 = 0x00;
LCDM10 = 0x00;
LCDM11 = 0x00;
LCDM12 = 0x00;
LCDM13 = 0x00;
}