1 | #include "avr/io.h"
|
2 |
|
3 | int main (void)
|
4 | {
|
5 |
|
6 | if(PINE & (1<<PE5))
|
7 | while(true)
|
8 | {
|
9 |
|
10 | /*****************************************************************
|
11 | **************** *******************
|
12 | **************** BTM-222 *******************
|
13 | **************** Master_Modus *******************
|
14 | **************** Baudrate 19200 Baud *******************
|
15 | **************** *******************
|
16 | *****************************************************************/
|
17 |
|
18 |
|
19 | #define F_CPU 16000000UL
|
20 | #define OSCSPEED 16000000 // in Hz
|
21 |
|
22 |
|
23 | #include "util/delay.h"
|
24 | #include "avr/io.h"
|
25 | #include "lcd.c"
|
26 | #include "EB128_BBS2.h"
|
27 |
|
28 |
|
29 | const char info1[]PROGMEM = " Bluetooth -> Master";
|
30 |
|
31 | char Line[40]; // String mit maximal 39 zeichen
|
32 | char display_buffer[21];
|
33 |
|
34 |
|
35 | uint8_t EmpfangZeichen;
|
36 |
|
37 | //-------------------------------------------------------------------
|
38 |
|
39 | void UART_Init(uint32_t Baud)
|
40 | {
|
41 | unsigned int BaudRate = OSCSPEED / (16 * Baud) - 1; //BaudRate
|
42 |
|
43 |
|
44 | UBRR1L = (unsigned char) BaudRate;
|
45 | UBRR1H = (unsigned char) (BaudRate>>8);
|
46 |
|
47 | UCSR1C |= 0x06; // 8 Data , 1 Stoppbit , keine Parität
|
48 | UCSR1B |= 0x18; // Freigabe RxD und TxD
|
49 | }
|
50 |
|
51 | //-------------------------------------------------------------------
|
52 |
|
53 |
|
54 | void USART1_Transmit (unsigned char data)
|
55 | {
|
56 |
|
57 | while ( ! ( UCSR1A & (1<<UDRE1)));//Warte bis Transmit-Speicher leer
|
58 | {
|
59 | UDR1 = data;
|
60 | }
|
61 | }
|
62 |
|
63 | //-------------------------------------------------------------------
|
64 |
|
65 |
|
66 | int uart_putc(unsigned char c)
|
67 | {
|
68 | while (!(UCSR1A & (1<<UDRE1))) // warten bis Senden möglich
|
69 | {
|
70 | }
|
71 |
|
72 | UDR1 = c; // sende Zeichen
|
73 | return 0;
|
74 | }
|
75 |
|
76 |
|
77 |
|
78 | void uart_puts (char *s)
|
79 | {
|
80 | while (*s)
|
81 | {
|
82 | uart_putc(*s); // solange s ungleich '\0'
|
83 | s++;
|
84 | }
|
85 | }
|
86 |
|
87 | //-------------------------------------------------------------------
|
88 |
|
89 | uint8_t uart_getc(void)
|
90 | {
|
91 | //while (!(UCSR1A & (1<<RXC1))) // warten bis Zeichen verfügbar
|
92 |
|
93 | return UDR1;
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 | void uart_gets( char* Buffer, uint8_t MaxLen )
|
99 | {
|
100 | uint8_t NextChar;
|
101 |
|
102 |
|
103 | NextChar = uart_getc();
|
104 |
|
105 | while( NextChar != 0x0D)
|
106 | {
|
107 | *Buffer++ = NextChar;
|
108 |
|
109 | NextChar = uart_getc();
|
110 | }
|
111 |
|
112 | *Buffer = '\0';
|
113 | }
|
114 |
|
115 | //-------------------------------------------------------------------
|
116 |
|
117 |
|
118 | int main()
|
119 |
|
120 | {
|
121 |
|
122 | DDRA=0xFF;
|
123 | DDRB=0xFF;
|
124 | DDRC=0xFF;
|
125 | DDRE=0x00;
|
126 | DDRG=0x00;
|
127 |
|
128 | lcd_init( LCD_DISP_ON );
|
129 | G_DISPLAY = (1<<BELEUCHTUNG);
|
130 | lcd_init( LCD_DISP_ON );
|
131 | lcd_puts_p(info1); // Ausgabe Überschrift
|
132 |
|
133 | UART_Init(19200); // Baudrate 19200 Baud
|
134 | _delay_ms(200);
|
135 |
|
136 |
|
137 | //-----------------------------------------------------------------------
|
138 |
|
139 | uart_puts ("ATR0\r"); // Master oder Slave Master=0; Slave=1
|
140 | _delay_ms(1000);
|
141 |
|
142 | uart_puts ("ATO0\r"); // automatische Verbindung Enable=0
|
143 | _delay_ms(1000);
|
144 |
|
145 |
|
146 | uart_puts ("ATD=00126F09B37C\r"); //automatische Verbindung Enable=0
|
147 | _delay_ms(3000);
|
148 |
|
149 | uart_puts ("ATP=1234\r"); // Passwort Standard ist 1234
|
150 | _delay_ms(1000);
|
151 |
|
152 | //-----------------------------------------------------------------------
|
153 |
|
154 |
|
155 |
|
156 | while(1)
|
157 | {
|
158 |
|
159 | /* uart_putc(0x01);
|
160 | lcd_gotoxy(0,2);
|
161 | lcd_puts("Slave -> LED_1 = AN");
|
162 |
|
163 |
|
164 | _delay_ms(3000);
|
165 |
|
166 |
|
167 | uart_putc(0x02);
|
168 | lcd_gotoxy(0,2);
|
169 | lcd_puts("Slave -> LED_2 = AN");
|
170 |
|
171 |
|
172 | _delay_ms(3000);
|
173 |
|
174 |
|
175 | uart_putc(0x03);
|
176 | lcd_gotoxy(0,2);
|
177 | lcd_puts("Slave -> LED_3 = AN");
|
178 |
|
179 |
|
180 | _delay_ms(3000);*/
|
181 |
|
182 | //--------------------------------------------
|
183 |
|
184 |
|
185 | if(PINE & (1<<PE0))
|
186 | {
|
187 | uart_putc(0x01);
|
188 | lcd_gotoxy(0,2);
|
189 | lcd_puts("Slave -> LED1 -> EIN");
|
190 | }
|
191 |
|
192 | if(PINE & (1<<PE1))
|
193 | {
|
194 | uart_putc(0x02);
|
195 | lcd_gotoxy(0,2);
|
196 | lcd_puts("Slave -> LED2 -> EIN");
|
197 | }
|
198 |
|
199 | if(PINE & (1<<PE2))
|
200 | {
|
201 | uart_putc(0x03);
|
202 | lcd_gotoxy(0,2);
|
203 | lcd_puts("Slave -> LED3 -> EIN");
|
204 | }
|
205 |
|
206 | //---------------------------------------------
|
207 |
|
208 | }
|
209 |
|
210 | }
|
211 |
|
212 | }
|
213 |
|
214 | else
|
215 | while(true)
|
216 | {
|
217 |
|
218 | /*****************************************************************
|
219 | **************** *******************
|
220 | **************** BTM-222 *******************
|
221 | **************** Slave-Modus *******************
|
222 | **************** Baudrate19200 Baud *******************
|
223 | **************** *******************
|
224 | *****************************************************************/
|
225 |
|
226 |
|
227 | #define F_CPU 16000000UL
|
228 | #define OSCSPEED 16000000 // in Hz
|
229 |
|
230 |
|
231 | #include "util/delay.h"
|
232 | #include "avr/io.h"
|
233 | #include "lcd.c"
|
234 | #include "EB128_BBS2.h"
|
235 |
|
236 |
|
237 | const char info1[]PROGMEM = " Bluetooth -> Slave";
|
238 |
|
239 | char Line[40]; // String mit maximal 39 zeichen
|
240 | char display_buffer[21];
|
241 |
|
242 |
|
243 | uint8_t EmpfangZeichen;
|
244 |
|
245 | //-------------------------------------------------------------------
|
246 |
|
247 | void UART_Init(uint32_t Baud)
|
248 | {
|
249 | unsigned int BaudRate = OSCSPEED / (16 * Baud) - 1; //BaudRate
|
250 |
|
251 |
|
252 | UBRR1L = (unsigned char) BaudRate;
|
253 | UBRR1H = (unsigned char) (BaudRate>>8);
|
254 |
|
255 | UCSR1C |= 0x06; // 8 Data , 1 Stoppbit , keine Parität
|
256 | UCSR1B |= 0x18; // Freigabe RxD und TxD
|
257 | }
|
258 |
|
259 | //-------------------------------------------------------------------
|
260 |
|
261 |
|
262 | void USART1_Transmit (unsigned char data)
|
263 | {
|
264 |
|
265 | while ( ! ( UCSR1A & (1<<UDRE1)));//Warte bis Transmit-Speicher leer
|
266 | {
|
267 | UDR1 = data;
|
268 | }
|
269 | }
|
270 |
|
271 | //-------------------------------------------------------------------
|
272 |
|
273 |
|
274 | int uart_putc(unsigned char c)
|
275 | {
|
276 | while (!(UCSR1A & (1<<UDRE1))) // warten bis Senden möglich
|
277 | {
|
278 | }
|
279 |
|
280 | UDR1 = c; // sende Zeichen
|
281 | return 0;
|
282 | }
|
283 |
|
284 |
|
285 |
|
286 | void uart_puts (char *s)
|
287 | {
|
288 | while (*s)
|
289 | {
|
290 | uart_putc(*s); // solange s ungleich '\0'
|
291 | s++;
|
292 | }
|
293 | }
|
294 |
|
295 | //-------------------------------------------------------------------
|
296 |
|
297 | uint8_t uart_getc(void)
|
298 | {
|
299 | //while (!(UCSR1A & (1<<RXC1))) // warten bis Zeichen verfügbar
|
300 |
|
301 | return UDR1;
|
302 | }
|
303 |
|
304 |
|
305 |
|
306 | void uart_gets( char* Buffer, uint8_t MaxLen )
|
307 | {
|
308 | uint8_t NextChar;
|
309 |
|
310 |
|
311 | NextChar = uart_getc();
|
312 |
|
313 | while( NextChar != 0x0D)
|
314 | {
|
315 | *Buffer++ = NextChar;
|
316 |
|
317 | NextChar = uart_getc();
|
318 | }
|
319 |
|
320 | *Buffer = '\0';
|
321 | }
|
322 |
|
323 | //-------------------------------------------------------------------
|
324 |
|
325 |
|
326 | int main()
|
327 |
|
328 | {
|
329 |
|
330 | DDRA=0xFF;
|
331 | DDRB=0xFF;
|
332 | DDRC=0xFF;
|
333 | DDRE=0x00;
|
334 | DDRG=0x00;
|
335 |
|
336 | lcd_init( LCD_DISP_ON );
|
337 | G_DISPLAY = (1<<BELEUCHTUNG);
|
338 | lcd_init( LCD_DISP_ON );
|
339 | lcd_puts_p(info1); // Ausgabe Überschrift
|
340 |
|
341 | UART_Init(19200); // Baudrate 19200 Baud
|
342 | _delay_ms(200);
|
343 |
|
344 |
|
345 | //-----------------------------------------------------------------------
|
346 | uart_puts ("ATR1\r"); // Master oder Slave Master=0; Slave=1
|
347 | _delay_ms(1000);
|
348 |
|
349 | uart_puts ("ATO0\r"); // automatische Verbindung Enable=0
|
350 | _delay_ms(1000);
|
351 |
|
352 |
|
353 | uart_puts ("ATE0\r"); // Echo ausschalten
|
354 | _delay_ms(1000);
|
355 |
|
356 |
|
357 | //-----------------------------------------------------------------------
|
358 |
|
359 |
|
360 | while(1)
|
361 | {
|
362 |
|
363 | EmpfangZeichen = uart_getc();
|
364 |
|
365 |
|
366 | if(EmpfangZeichen == 0x01)
|
367 | {
|
368 | PORTA = 0x01;
|
369 | lcd_gotoxy(5,2);
|
370 | lcd_puts("LED1 = EIN");
|
371 | }
|
372 |
|
373 |
|
374 | if(EmpfangZeichen == 0x02)
|
375 | {
|
376 | PORTA = 0x02;
|
377 | lcd_gotoxy(5,2);
|
378 | lcd_puts("LED2 = EIN");
|
379 | }
|
380 |
|
381 |
|
382 | if(EmpfangZeichen == 0x03)
|
383 | {
|
384 | PORTA = 0x04;
|
385 | lcd_gotoxy(5,2);
|
386 | lcd_puts("LED3 = EIN");
|
387 | }
|
388 |
|
389 |
|
390 | //--------------------------------------------
|
391 |
|
392 | /* switch(EmpfangZeichen)
|
393 | {
|
394 |
|
395 | case 0x01: PORTA = 0x01;
|
396 | lcd_gotoxy(5,2);
|
397 | lcd_puts("LED_1 = AN");
|
398 | break;
|
399 |
|
400 |
|
401 | case 0x02: PORTA = 0x02 ;
|
402 | lcd_gotoxy(5,2);
|
403 | lcd_puts("LED_2 = AN");
|
404 | break;
|
405 |
|
406 |
|
407 | case 0x03: PORTA = 0x04;
|
408 | lcd_gotoxy(5,2);
|
409 | lcd_puts("LED_3 = AN");
|
410 | break;
|
411 |
|
412 | } */
|
413 |
|
414 | }
|
415 |
|
416 | }
|
417 |
|
418 | }
|
419 |
|
420 | }
|