1 | /*******************************************************************************
|
2 | *
|
3 | * MODULE : main.c
|
4 | *
|
5 | * COMPILER : TI 4.10
|
6 | *
|
7 | * LANGUAGE : ANSI-C
|
8 | *
|
9 | * DESCRIPTION : (fill in a detailed description of the module’s
|
10 | * function here).
|
11 | *
|
12 | * SYSTEM : MSP430G2553
|
13 | *
|
14 | * AUTHOR :
|
15 | *
|
16 | * HISTORY :
|
17 | *
|
18 | *******************************************************************************/
|
19 |
|
20 | /*
|
21 | * EA DOGM162E-A MSP430G2553
|
22 | * __________ __________
|
23 | * | | | |
|
24 | * | RS |----------------| P1.3 |
|
25 | * | CSB |----------------| P1.4 |
|
26 | * | | | |
|
27 | * | | | |
|
28 | * | | | |
|
29 | * | | | |
|
30 | * | D6 |----------------| P1.5 |
|
31 | * | D7 |----------------| P1.7 |
|
32 | * |__________| |__________|
|
33 | *
|
34 | * Angeschlossen am Display
|
35 | * 3,3V = D5, D4, D3, D2, D1, D0, E, /Reset, RW, Vin (Pin 25), Vdd
|
36 | * GND = Vss, PSB
|
37 | */
|
38 |
|
39 | /*******************************************************************************
|
40 | * INCLUDE SECTION
|
41 | *******************************************************************************/
|
42 | /*
|
43 | * ======== Standard MSP430 includes ========
|
44 | */
|
45 | #include <msp430.h>
|
46 | //#include <ti/mcu/msp430/csl/CSL.h>
|
47 | #include <stdint.h>
|
48 | #include <stdio.h>
|
49 |
|
50 | /*******************************************************************************
|
51 | * DEFINE AND MACRO SECTION
|
52 | *******************************************************************************/
|
53 |
|
54 | /*******************************************************************************
|
55 | * GLOBAL VARIABLES SECTION
|
56 | *******************************************************************************/
|
57 |
|
58 | /*******************************************************************************
|
59 | * FUNCTION SECTION
|
60 | *******************************************************************************/
|
61 | void lcd_write(char command, char daten);
|
62 |
|
63 | void delay_30us(void);
|
64 | void delay_50ms(void);
|
65 | void delay_2ms(void);
|
66 | void delay_200ms(void);
|
67 | void delay_100ms(void);
|
68 | void init_msp(void); // Initialize MSP430 2553
|
69 | void dogm_init5V(void); // Initialize LCD
|
70 | void dogm_init3V(void); // Initialize LCD
|
71 | void dogm_putc(char); // Write character to display
|
72 | void dogm_puts(char *); // Write string to display
|
73 | void dogm_gotoxy(uint8_t, uint8_t); // Go to position
|
74 |
|
75 | /*******************************************************************************
|
76 | * Function name : void main(void)
|
77 | * return : void
|
78 | * arg1 : void
|
79 | * Author :
|
80 | * History : date and event
|
81 | * Description : none
|
82 | * Notes : none
|
83 | *******************************************************************************/
|
84 | void main(void){
|
85 | //CSL_init();
|
86 | init_msp();
|
87 | volatile unsigned int i; // Use volatile to prevent removal
|
88 | volatile unsigned int k;
|
89 |
|
90 | P1OUT |= BIT0; //LED ON;
|
91 | //Init char buffer for text message
|
92 | char buffer[16]=" ";
|
93 | unsigned int loop = 0;
|
94 |
|
95 | // initialise Display
|
96 | dogm_init3V();
|
97 | dogm_puts("Hallo Welt !");
|
98 | //Loop to count up a number on second display line
|
99 | while(1){
|
100 | loop++;
|
101 | P1OUT ^= BIT0; // toggle LED
|
102 |
|
103 | sprintf(buffer, "Loop %d", loop);
|
104 | dogm_gotoxy(0, 1);
|
105 | dogm_puts(buffer);
|
106 |
|
107 | // Verzögerung um etwas auf dem Display zu sehen...
|
108 | for (k = 0; k < 100; k++){
|
109 | for (i = 0; i < 100; i++);
|
110 | }
|
111 | }
|
112 | }
|
113 |
|
114 | // ************************************************************
|
115 | // INIT DOGM162 Functions
|
116 | //************************************************************
|
117 |
|
118 | void dogm_init5V(void)
|
119 | {
|
120 | delay_200ms(); // 200ms delay
|
121 |
|
122 | lcd_write(0x38,0); // switch back to instrcution table 0
|
123 | delay_30us(); // 30us delay
|
124 |
|
125 | lcd_write(0x39, 0); // 8-bit modus
|
126 | delay_30us(); // 30us delay
|
127 |
|
128 | lcd_write(0x1C, 0); // 2 line LCD
|
129 | delay_30us(); // 30us delay
|
130 |
|
131 | lcd_write(0x74, 0); // Contrast Set: C3=1, C2=C1=C0=0
|
132 | delay_30us(); // 30us delay
|
133 |
|
134 | lcd_write(0x52, 0); // booster off
|
135 | delay_30us(); // 30us delay
|
136 |
|
137 | lcd_write(0x69, 0); // voltage follower and gain
|
138 | delay_2ms(); // 30us delay
|
139 |
|
140 | lcd_write(0x0F, 0); // display, cursors and blink ON
|
141 | delay_30us(); // 30us delay
|
142 |
|
143 | lcd_write(0x01, 0); // delete display
|
144 | delay_50ms(); // 50ms delay
|
145 | }
|
146 |
|
147 | void dogm_init3V(void)
|
148 | {
|
149 | delay_200ms(); // 200ms delay
|
150 |
|
151 | lcd_write(0x39,0); // 8-bit modus
|
152 | delay_30us(); // 30us delay
|
153 |
|
154 | lcd_write(0x14, 0); // 2 line LCD
|
155 | delay_30us(); // 30us delay
|
156 |
|
157 | lcd_write(0x55, 0); // booster on
|
158 | delay_30us(); // 30us delay
|
159 |
|
160 | lcd_write(0x6D, 0); // voltage follower and gain
|
161 | delay_30us(); // 30us delay
|
162 |
|
163 | lcd_write(0x78, 0); // Contrast Set: C3=1, C2=C1=C0=0
|
164 | delay_30us(); // 30us delay
|
165 |
|
166 | lcd_write(0x38, 0); // switch back to instrcution table 0
|
167 | delay_2ms(); // 30us delay
|
168 |
|
169 | lcd_write(0x0F, 0); // display, cursors and blink ON
|
170 | delay_30us(); // 30us delay
|
171 |
|
172 | lcd_write(0x01, 0); // delete display, cursor @ home
|
173 | delay_50ms(); // 50ms delay
|
174 |
|
175 | lcd_write(0x06, 0); // cursor auto increment
|
176 | delay_30us(); // 30us delay
|
177 | }
|
178 |
|
179 | void lcd_write(char command, char daten)
|
180 | {
|
181 | volatile uint8_t i;
|
182 |
|
183 |
|
184 | if (daten==0){
|
185 | P1OUT &= ~(BIT3); // RS = LOW, es handelt sich um ein Kommando
|
186 | }
|
187 |
|
188 | if (daten==1){
|
189 | P1OUT |= BIT3; // RS = HIGH, es handelt sich um Daten
|
190 | }
|
191 |
|
192 | P1OUT &= ~BIT4; // /ChipSelect enable, LCD is listening
|
193 |
|
194 | UCB0TXBUF = command;
|
195 |
|
196 | while (!(IFG2 & UCB0TXIFG)); // Wait for TX to finish (NOT WORKING)!
|
197 |
|
198 | //delay to make sure all data transimmte during cs on, works for 256 kbps
|
199 | __delay_cycles( 30UL );
|
200 |
|
201 | P1OUT |= BIT4; // /CS disable, LCD not anymore listening
|
202 | }
|
203 |
|
204 |
|
205 | // ************************************************************
|
206 | // INIT MSP430F2553
|
207 | // ************************************************************
|
208 |
|
209 | void init_msp(void){
|
210 | /* Stop watchdog timer from timing out during initial start-up. */
|
211 | WDTCTL = WDTPW + WDTHOLD;
|
212 | /*Basic Clock System Control 2*/
|
213 | BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0;
|
214 |
|
215 | if (CALBC1_1MHZ != 0xFF) {
|
216 | /* Follow recommended flow. First, clear all DCOx and MODx bits. Then
|
217 | * apply new RSELx values. Finally, apply new DCOx and MODx bit values.
|
218 | */
|
219 | DCOCTL = 0x00;
|
220 | BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */
|
221 | DCOCTL = CALDCO_1MHZ;
|
222 | }
|
223 | BCSCTL1 |= XT2OFF + DIVA_0;
|
224 | BCSCTL3 = XT2S_0 + LFXT1S_0 + XCAP_1;
|
225 | /* Disable USCI */
|
226 | UCB0CTL1 |= UCSWRST;
|
227 | UCB0CTL0 = UCCKPL + UCMSB + UCMST + UCMODE_0 + UCSYNC;
|
228 | UCB0CTL1 = UCSSEL_2 + UCSWRST;
|
229 | /* Bit Rate Control Register 0 */
|
230 | UCB0BR0 = 4; //256kbps
|
231 | /* Enable USCI */
|
232 | UCB0CTL1 &= ~UCSWRST;
|
233 | /* Port 1 Output Register */
|
234 | P1OUT = 0;
|
235 | /* Port 1 Port Select Register */
|
236 | P1SEL = BIT5 + BIT7;
|
237 | /* Port 1 Port Select 2 Register */
|
238 | P1SEL2 = BIT5 + BIT7;
|
239 | /* Port 1 Direction Register */
|
240 | P1DIR = BIT0 + BIT2 + BIT3 + BIT4;
|
241 | /* Port 1 Interrupt Edge Select Register */
|
242 | P1IES = 0;
|
243 | /* Port 1 Interrupt Flag Register */
|
244 | P1IFG = 0;
|
245 | /* Port 2 Interrupt Edge Select Register */
|
246 | P2IES = 0;
|
247 | /* Port 2 Interrupt Flag Register */
|
248 | P2IFG = 0;
|
249 | __bis_SR_register(GIE);
|
250 |
|
251 | }
|
252 |
|
253 | // ************************************************************
|
254 | // Write single character to display
|
255 | // ************************************************************
|
256 |
|
257 | void dogm_putc(char c)
|
258 | {
|
259 | lcd_write(c, 1);
|
260 | }
|
261 |
|
262 |
|
263 | // ************************************************************
|
264 | // Write string to display
|
265 | // ************************************************************
|
266 |
|
267 | void dogm_puts(char * str)
|
268 | {
|
269 | while(*str != '\0')
|
270 | dogm_putc(*str++);
|
271 | }
|
272 |
|
273 |
|
274 | // ************************************************************
|
275 | // Go to position xy
|
276 | // ************************************************************
|
277 |
|
278 | void dogm_gotoxy(uint8_t x, uint8_t y)
|
279 | {
|
280 | uint8_t addr;
|
281 |
|
282 | addr = (y * 0x40) + x;
|
283 | lcd_write(0x80 | addr, 0);
|
284 | }
|
285 |
|
286 | void delay_30us(void)
|
287 | {
|
288 | __delay_cycles( 50UL );
|
289 | }
|
290 |
|
291 |
|
292 | void delay_2ms(void)
|
293 | {
|
294 | __delay_cycles( 2000UL );
|
295 | }
|
296 |
|
297 |
|
298 | void delay_50ms(void)
|
299 | {
|
300 | __delay_cycles( 50000UL );
|
301 | }
|
302 |
|
303 |
|
304 | void delay_200ms(void)
|
305 | {
|
306 | __delay_cycles( 200000UL );
|
307 | }
|
308 |
|
309 | void delay_100ms(void)
|
310 | {
|
311 | __delay_cycles( 100000UL );
|
312 | }
|
313 |
|
314 | /*******************************************************************************
|
315 | * END OF FILE
|
316 | *******************************************************************************/
|