1 | #include <msp430x44x.h>
|
2 | //#include <io430x44x.h>
|
3 |
|
4 | #define B1 P3IN & BIT4 //B1 - P4.4
|
5 | #define B2 P3IN & BIT5 //B2 - P4.5
|
6 | #define B3 P3IN & BIT6 //B3 - P4.6
|
7 | #define B4 P3IN & BIT7 //B4 - P4.7
|
8 | #define STATUS_LED BIT3 //STATUS_LED - P1.3
|
9 | #define time 200
|
10 | #define time_s 200
|
11 | #define BUZ1_ON P1OUT |= BIT0 //P4.2
|
12 | #define BUZ1_OFF P1OUT &= ~BIT0 //P4.2
|
13 | #define BUZ2_ON P1OUT |= BIT2 //P4.3
|
14 | #define BUZ2_OFF P1OUT &= ~BIT2 //P4.3
|
15 | #define DALLAS P2IN & BIT7 //P2.7 - DALLAS
|
16 | #define CR 0x0d
|
17 | #define LF 0x0a
|
18 | #define LED_OFF P1OUT |= BIT3
|
19 | #define LED_ON P1OUT &= ~BIT3
|
20 |
|
21 |
|
22 | // LCD Segmente
|
23 | #define lcd_a (0x80) // definitions for LCD seegments on the Olimex LCD. 4-Mux operation is assumed
|
24 | #define lcd_b (0x40) // For more details on 4-Mux operation, gather your LCD datasheet,
|
25 | #define lcd_c (0x20) // TI's MSP430F449 User Guide (look for LCD Controller, then 4-Mux),
|
26 | #define lcd_d (0x01) // and MSP-449STK-2 schematic. You will need ALL these 3 when defining
|
27 | #define lcd_e (0x02) // each number or character. Remember, the Olimex LCD doesn't use a LCD driver!
|
28 | #define lcd_f (0x08) // You tell the LCD what characters to display. It's very time consuming!!
|
29 | #define lcd_g (0x04)
|
30 | #define lcd_h (0x10)
|
31 |
|
32 | //LCD digit segments
|
33 | char *LCD = LCDMEM; // pointer to LCD Memory Segments. Pretty cool, got this idea from TI-website
|
34 | //
|
35 | unsigned char i,time_segment,TXData;
|
36 | unsigned int j;
|
37 | unsigned int konst=0;
|
38 | unsigned int konst_2=0;
|
39 | unsigned int Button= 0;
|
40 | unsigned int Button_1= 0;
|
41 | unsigned int zaehler= 0;
|
42 | unsigned int Flanke_1= 0;
|
43 | unsigned int Flanke_2= 0;
|
44 | const unsigned char UART_Message [] = "http://www.olimex.com/dev";
|
45 |
|
46 |
|
47 | void Delay (unsigned int a);
|
48 | void DelayX(unsigned int b);
|
49 | void Clear_LCD(void);
|
50 | void LCD_all(void);
|
51 | void BUZZER (void);
|
52 | void UART_transmit (unsigned char Transmit_Data);
|
53 | void Menu(void);
|
54 | void OK (void);
|
55 | void Timer (void);
|
56 | void An (void);
|
57 | void Aus (void);
|
58 | void Button1 (void);
|
59 | void Button2 (void);
|
60 | void writeLetter(int position,char letter); // displays a single character on the LCD
|
61 |
|
62 | /// Tests
|
63 | void Hallo(void);
|
64 | void du(void);
|
65 | void da(void);
|
66 | void wie(void);
|
67 |
|
68 | void main(void)
|
69 | {
|
70 | //++++++++++++++++++++++++++++++
|
71 | WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
|
72 |
|
73 | FLL_CTL0 &= ~XTS_FLL; // XT1 as low-frequency
|
74 | _BIC_SR(OSCOFF); // turn on XT1 oscillator
|
75 |
|
76 | do // wait in loop until crystal is stable
|
77 | IFG1 &= ~OFIFG;
|
78 | while (IFG1 & OFIFG);
|
79 |
|
80 | FLL_CTL1 &= ~FLL_DIV0; // ACLK = XT1
|
81 | FLL_CTL1 &= ~FLL_DIV1;
|
82 |
|
83 |
|
84 | IFG1 &= ~OFIFG; // clear osc. fault int. flag
|
85 | FLL_CTL1 &= ~SELM0; // set DCO as MCLK
|
86 | FLL_CTL1 &= ~SELM1;
|
87 |
|
88 |
|
89 | //++++++++++++++++++++++++++++++
|
90 |
|
91 |
|
92 |
|
93 | // SVSCTL = 0x68; //brown out
|
94 |
|
95 | // WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
|
96 |
|
97 | // SCFI0 = BIT2 | BIT3 | BIT4 | BIT5 | BIT6 | BIT7;
|
98 | // SCFI0 |= FN_4; // x2 DCO frequency, 8MHz nominal DCO
|
99 | // SCFQCTL = SCFQ_1M;
|
100 |
|
101 | // FLL_CTL0 = /*DCOPLUS + */XCAP10PF; //Set load Cap. for Cristal = 10pF // x2 DCO frequency, 8MHz nominal DCO
|
102 |
|
103 | // FLL_CTL1 |= SELM_XT2; //Select XT2 for CPU MCLK
|
104 | // SCFI1 = 0;
|
105 | // SCFQCTL = SCFQ_M | SCFQ_1M; //M=1, 1Mhz
|
106 | // _BIS_SR(SCG0+SCG1); //disable DCO in status_reg
|
107 | // DelayX(200);
|
108 |
|
109 |
|
110 | //UART ini
|
111 | U1TCTL = SSEL0; //UCLOCK = ACLK
|
112 | U1BR0 = 0x03; //BAUD RATE = 9600
|
113 | U1BR1 = 0x00;
|
114 | U1MCTL = 0x4a; //with modulation
|
115 | U1CTL = CHAR; //Start 8bit 1stop, N
|
116 | ME2 = UTXE1 | URXE1; //enable RX and TX
|
117 | P4SEL |= BIT0 | BIT1; //select UART pins
|
118 | P4DIR |= BIT0; //port direction for TXD0
|
119 | P4DIR &= ~BIT1; //port direction for RXD0
|
120 | // IE1 |= URXIE0; // Enable USART0 RX interrupt
|
121 | // _EINT(); // Enable interrupts
|
122 | // U1CTL &= ~SWRST; //reset UART logic
|
123 |
|
124 |
|
125 |
|
126 | //LCD ini
|
127 | Clear_LCD();
|
128 | TACTL = TASSEL0 | TACLR; //set timer_A
|
129 | LCDCTL = LCDON + LCD4MUX + LCDP0 + LCDP1 + LCDP2; // STK LCD 4Mux, S0-S39
|
130 | BTCTL = BT_fLCD_DIV64; // STK LCD freq ACLK/64
|
131 | P5SEL = 0xFC; // Common and Rxx all selected
|
132 |
|
133 | //IO port ini
|
134 |
|
135 | P1SEL=BIT5; //p1.5 is 32768Hz
|
136 | P1DIR=BIT5 | BIT3 | BIT0 | BIT2; //BUZ,LED are outputs
|
137 |
|
138 | LCD_all(); //light all LCD segments
|
139 |
|
140 | for (i=0; i!=15; i++)
|
141 | {
|
142 | LED_ON;
|
143 | DelayX(60);
|
144 | LED_OFF;
|
145 | DelayX(60);
|
146 | }
|
147 |
|
148 | UART_transmit (CR); //send message by RS232
|
149 | UART_transmit (LF);
|
150 | for (i=0; i!=26; i++) UART_transmit (UART_Message[i]);
|
151 | UART_transmit (CR);
|
152 | UART_transmit (LF);
|
153 |
|
154 | //---------------MAIN LOOP-----------------------------------
|
155 | Button_1 = B2;
|
156 | Flanke_1=1;
|
157 | Flanke_2=1;
|
158 |
|
159 | while (1)
|
160 | {
|
161 |
|
162 |
|
163 | if ((IFG2 & URXIFG1) != 0) UART_transmit (U1RXBUF+1); //test RS 232 (echo+1)
|
164 |
|
165 | while ((DALLAS) == 0) BUZZER(); //test DALLAS button
|
166 |
|
167 | L1: if ((B2) == 0) //Clear_LCD();
|
168 | {
|
169 | if (Flanke_2 == 1 )
|
170 | {
|
171 | zaehler = 0;
|
172 | Button2();
|
173 | Flanke_2 = 0;
|
174 | }
|
175 | }
|
176 | else
|
177 | {
|
178 | Flanke_2 = 1;
|
179 | }
|
180 |
|
181 | if ((B1) == 0)
|
182 | {
|
183 | if (Flanke_1 == 1 )
|
184 | {
|
185 | zaehler = 0;
|
186 | konst_2 = 0;
|
187 | Button1();
|
188 | Flanke_1 = 0;
|
189 | }
|
190 | else
|
191 | { zaehler++;
|
192 |
|
193 | if (zaehler >= 30000)
|
194 | {
|
195 | zaehler = 0;
|
196 | konst =0;
|
197 | Clear_LCD();
|
198 | for (i=0; i!= 20; i++) BUZZER();
|
199 | }
|
200 | }
|
201 | }
|
202 | else
|
203 | {
|
204 | Flanke_1 = 1;
|
205 | }
|
206 | if ((B3) == 0)
|
207 | {
|
208 | time_segment=100;
|
209 | for (i=0; i!= 20; i++)
|
210 | {
|
211 | for (j=0; j!=9; j++)
|
212 | {
|
213 | LCDMEM[i] = (BIT0 << j);
|
214 | if ((IFG2 & URXIFG1) != 0) UART_transmit (U1RXBUF+1); //test RS 232 (echo+1)
|
215 | DelayX(time_segment);
|
216 | if((B1) == 0 ) goto L1;
|
217 | if((B2) == 0 ) goto L1;
|
218 | if((B4) == 0 )
|
219 | {
|
220 | LCD_all();
|
221 | goto L1;
|
222 | }
|
223 | }
|
224 | }
|
225 | }
|
226 | if((B4) == 0)
|
227 | {
|
228 | BUZZER();
|
229 | Hallo();
|
230 | P1OUT &= ~STATUS_LED; //switch on status_led
|
231 | }
|
232 | else P1OUT |= STATUS_LED; //switch off status led
|
233 | }
|
234 | }
|
235 |
|
236 |
|
237 | void Delay (unsigned int a) //9+a*12 cycles
|
238 | {
|
239 | unsigned int l;
|
240 | for (l=0 ; l != a; l++);
|
241 | }
|
242 |
|
243 | void Clear_LCD(void)
|
244 | {
|
245 | for (i=0; i!= 20; i++) LCDMEM[i]=0x00; //clear Sxx
|
246 | }
|
247 |
|
248 | void LCD_all(void)
|
249 | {
|
250 | for (i=0; i!= 20; i++) LCDMEM[i]=0xff; //turnon all LCD segments
|
251 | }
|
252 |
|
253 | void DelayX(unsigned int b)
|
254 | {
|
255 | unsigned int m;
|
256 | for(m=0;m!=b;m++) Delay(255);
|
257 | }
|
258 |
|
259 | void BUZZER (void)
|
260 | {
|
261 | BUZ1_OFF;
|
262 | BUZ2_ON;
|
263 | Delay(40);
|
264 | BUZ2_OFF;
|
265 | BUZ1_ON;
|
266 | Delay(40);
|
267 | }
|
268 |
|
269 | void UART_transmit (unsigned char Transmit_Data) //UART1 Transmit Subroutine
|
270 | {
|
271 | while ((IFG2 & UTXIFG1) == 0); //Wait for ready U1TXBUF
|
272 | U1TXBUF = Transmit_Data; //send data
|
273 | }
|
274 |
|
275 | void writeLetter(int position,char letter) // writes a single character on the LCD. User can specify position as well
|
276 | {
|
277 | // DO NOT PLAY WITH THE CODE BELOW ------------------------------------------------------------------------------
|
278 | if (position == 1) { position = position + 6; } // this is position adjustment for compatibility.
|
279 | else if (position == 2 || position == 3 || position == 4 || position == 5 || position == 6 || position == 7)
|
280 | { position = ((position * 2) - 1) + 6; } // adjust position
|
281 | // --------------------------------------------------------------------------------------------------------------
|
282 |
|
283 | switch(letter)
|
284 | {
|
285 | // letter // LCDM7 // LCDM8 // End
|
286 | case 'A': LCD[position-1] = lcd_a + lcd_b + lcd_c + lcd_e; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
287 | case 'B': LCD[position-1] = lcd_c + lcd_h + lcd_e; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
288 | case 'C': LCD[position-1] = lcd_a + lcd_h; LCD[position] = lcd_b + lcd_c; break;
|
289 | case 'D': LCD[position-1] = lcd_b + lcd_c + lcd_h + lcd_e; LCD[position] = lcd_c + lcd_g; break;
|
290 | case 'E': LCD[position-1] = lcd_a + lcd_h + lcd_e; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
291 | case 'F': LCD[position-1] = lcd_a; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
292 | case 'G': LCD[position-1] = lcd_a + lcd_c + lcd_h + lcd_e; LCD[position] = lcd_b + lcd_c; break;
|
293 | case 'H': LCD[position-1] = lcd_b + lcd_c + lcd_e; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
294 | case 'I': LCD[position-1] = lcd_a + lcd_h + lcd_f; LCD[position] = lcd_d; break;
|
295 | case 'J': LCD[position-1] = lcd_b + lcd_h + lcd_c; LCD[position] = lcd_c; break;
|
296 | case 'K': LCD[position-1] = lcd_d + lcd_g; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
297 | case 'L': LCD[position-1] = lcd_h; LCD[position] = lcd_b + lcd_c ; break;
|
298 | case 'M': LCD[position-1] = lcd_b + lcd_c + lcd_g; LCD[position] = lcd_b + lcd_c + lcd_f; break;
|
299 | case 'N': LCD[position-1] = lcd_b + lcd_c + lcd_d; LCD[position] = lcd_b + lcd_c + lcd_f; break;
|
300 | case 'O': LCD[position-1] = lcd_a + lcd_b + lcd_c + lcd_h; LCD[position] = lcd_b + lcd_c; break;
|
301 | case 'P': LCD[position-1] = lcd_a + lcd_b + lcd_e; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
302 | case 'Q': LCD[position-1] = lcd_a + lcd_b + lcd_c + lcd_h + lcd_d; LCD[position] = lcd_b + lcd_c; break;
|
303 | case 'R': LCD[position-1] = lcd_a + lcd_b + lcd_d + lcd_e; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
304 | case 'S': LCD[position-1] = lcd_a + lcd_c + lcd_h + lcd_e; LCD[position] = lcd_b + lcd_g; break;
|
305 | case 'T': LCD[position-1] = lcd_a + lcd_f + lcd_b; LCD[position] = lcd_d + lcd_b; break;
|
306 | case 'U': LCD[position-1] = lcd_b + lcd_c + lcd_h; LCD[position] = lcd_b + lcd_c; break;
|
307 | case 'V': LCD[position-1] = lcd_g; LCD[position] = lcd_b + lcd_c + lcd_e; break;
|
308 | case 'W': LCD[position-1] = lcd_b + lcd_c + lcd_d; LCD[position] = lcd_b + lcd_c + lcd_e; break;
|
309 | case 'X': LCD[position-1] = lcd_d + lcd_g; LCD[position] = lcd_e + lcd_f; break;
|
310 | case 'Y': LCD[position-1] = lcd_b + lcd_c + lcd_h + lcd_e; LCD[position] = lcd_f; break;
|
311 | case 'Z': LCD[position-1] = lcd_a + lcd_h + lcd_g; LCD[position] = lcd_e; break;
|
312 |
|
313 | // number // LCDM7 // LCDM8 // END
|
314 | case '0': LCD[position-1] = lcd_a + lcd_b + lcd_c + lcd_h; LCD[position] = lcd_b + lcd_c; break;
|
315 | case '1': LCD[position-1] = lcd_b + lcd_c; break;
|
316 | case '2': LCD[position-1] = lcd_a + lcd_b + lcd_e + lcd_h; LCD[position] = lcd_c + lcd_g; break;
|
317 | case '3': LCD[position-1] = lcd_a + lcd_b + lcd_c + lcd_e + lcd_h; LCD[position] = lcd_g; break;
|
318 | case '4': LCD[position-1] = lcd_b + lcd_c + lcd_e; LCD[position] = lcd_b + lcd_g; break;
|
319 | case '5': LCD[position-1] = lcd_a + lcd_c + lcd_h + lcd_e; LCD[position] = lcd_b + lcd_g; break;
|
320 | case '6': LCD[position-1] = lcd_a + lcd_c + lcd_h + lcd_e; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
321 | case '7': LCD[position-1] = lcd_a + lcd_b + lcd_c; break;
|
322 | case '8': LCD[position-1] = lcd_a + lcd_b + lcd_c + lcd_e + lcd_h; LCD[position] = lcd_b + lcd_c + lcd_g; break;
|
323 | case '9': LCD[position-1] = lcd_a + lcd_b + lcd_c + lcd_e ; LCD[position] = lcd_b + lcd_g; break;
|
324 |
|
325 | // others
|
326 | case '.': LCD[position] = lcd_h; break; // decimal point
|
327 | case '^': LCDM2 = lcd_c; break; // top arrow
|
328 | case '!': LCDM2 = lcd_a; break; // bottom arrow
|
329 | case '>': LCDM2 = lcd_b; break; // right arrow
|
330 | case '<': LCDM2 = lcd_h; break; // left arrow
|
331 | case '+': LCDM20= lcd_a; break; // plus sign
|
332 | case '-': LCDM20= lcd_h; break; // minus sign
|
333 | case '&': LCDM2 = lcd_d; break; // zero battery
|
334 | case '*': LCDM2 = lcd_d + lcd_f; break; // low battery
|
335 | case '(': LCDM2 = lcd_d + lcd_f + lcd_g; break; // medium battery
|
336 | case ')': LCDM2 = lcd_d + lcd_e + lcd_f + lcd_g; break; // full battery */
|
337 | }
|
338 | }
|
339 |
|
340 | void Menu (void)
|
341 | {
|
342 | Clear_LCD();
|
343 | LCDMEM[19]=0x68; //M
|
344 | LCDMEM[18]=0x64;
|
345 | LCDMEM[17]=0x64; //E
|
346 | LCDMEM[16]=0x90;
|
347 | LCDMEM[15]=0x68; //N
|
348 | LCDMEM[14]=0x61;
|
349 | LCDMEM[13]=0x60; //U
|
350 | LCDMEM[12]=0x70;
|
351 | }
|
352 |
|
353 | void OK (void)
|
354 | {
|
355 |
|
356 | Clear_LCD();
|
357 | LCDMEM[19]=0x60; // O
|
358 | LCDMEM[18]=0xF0; // O
|
359 | LCDMEM[17]=0x64; // K
|
360 | LCDMEM[16]=0x05; // K
|
361 |
|
362 | }
|
363 |
|
364 | void Timer()
|
365 | {
|
366 | Clear_LCD();
|
367 | LCDMEM[19]=0x01; //T
|
368 | LCDMEM[18]=0x88;
|
369 | LCDMEM[17]=0x01; //I
|
370 | LCDMEM[16]=0x08;
|
371 | LCDMEM[15]=0x68; //M
|
372 | LCDMEM[14]=0x64;
|
373 | LCDMEM[13]=0x64; //E
|
374 | LCDMEM[12]=0x90;
|
375 | LCDMEM[11]=0x64; //R
|
376 | LCDMEM[10]=0xC3;
|
377 | }
|
378 |
|
379 | void An()
|
380 | {
|
381 | Clear_LCD();
|
382 | LCDMEM[19]=0x64; //A
|
383 | LCDMEM[18]=0xE2;
|
384 | LCDMEM[17]=0x68; //N
|
385 | LCDMEM[16]=0x61;
|
386 | }
|
387 |
|
388 | void Aus()
|
389 | {
|
390 | Clear_LCD();
|
391 | LCDMEM[19]=0x64; //A
|
392 | LCDMEM[18]=0xE2;
|
393 | LCDMEM[17]=0x60; //U
|
394 | LCDMEM[16]=0x70;
|
395 | LCDMEM[15]=0x44; //S
|
396 | LCDMEM[14]=0xB2;
|
397 | }
|
398 |
|
399 | void Hallo()
|
400 | {
|
401 | Clear_LCD();
|
402 | writeLetter(7,'H');
|
403 | writeLetter(6,'A');
|
404 | writeLetter(5,'L');
|
405 | writeLetter(4,'L');
|
406 | writeLetter(3,'O');
|
407 | writeLetter(1,'^');
|
408 |
|
409 | }
|
410 |
|
411 | void du()
|
412 | {
|
413 | Clear_LCD();
|
414 | writeLetter(7,'D');
|
415 | writeLetter(6,'U');
|
416 |
|
417 | }
|
418 |
|
419 | void da()
|
420 | {
|
421 | Clear_LCD();
|
422 | writeLetter(7,'D');
|
423 | writeLetter(6,'A');
|
424 | }
|
425 |
|
426 | void wie()
|
427 | {
|
428 | Clear_LCD();
|
429 | writeLetter(7,'W');
|
430 | writeLetter(6,'I');
|
431 |
|
432 | }
|
433 |
|
434 | void Button1 ()
|
435 | { konst++;
|
436 |
|
437 |
|
438 | if (konst ==1)
|
439 | {Menu();
|
440 | }
|
441 |
|
442 | if (konst ==2)
|
443 | {Aus();
|
444 | }
|
445 | if (konst ==3)
|
446 | {An();
|
447 | }
|
448 | if (konst ==4)
|
449 | {Timer();
|
450 | }
|
451 | if (konst ==5)
|
452 | {OK();
|
453 | konst=0;
|
454 | }
|
455 |
|
456 | }
|
457 |
|
458 | void Button2 ()
|
459 | {
|
460 | konst_2++;
|
461 |
|
462 | if (konst ==1)
|
463 | {
|
464 | if (konst_2 ==1)
|
465 | {
|
466 | Hallo();
|
467 | }
|
468 |
|
469 | if (konst_2==2)
|
470 | {
|
471 | du();
|
472 |
|
473 | konst_2 =0;
|
474 | }
|
475 | }
|
476 |
|
477 | if (konst ==2)
|
478 | {
|
479 | if (konst_2 ==1)
|
480 | {
|
481 | da();
|
482 | }
|
483 |
|
484 | if (konst_2==2)
|
485 | {
|
486 | wie();
|
487 |
|
488 | konst_2 =0;
|
489 | }
|
490 | }
|
491 | if (konst ==3)
|
492 | {An();
|
493 | }
|
494 | if (konst ==4)
|
495 | {Timer();
|
496 | }
|
497 | if (konst ==5)
|
498 | {OK();
|
499 | konst=0;
|
500 | }
|
501 |
|
502 | }
|