Commit b21eaa0f17eb2b1f6a0e65b4450dbb4e66659335
1 parent
8da267d4
code de libretour.c effectif
Showing
1 changed file
with
73 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
1 | +#include <avr/io.h> | ||
2 | +#include <avr/interrupt.h> | ||
3 | +#include <util/delay.h> | ||
4 | +#include <string.h> | ||
5 | +#include <stdlib.h> | ||
6 | +#include <stdio.h> | ||
7 | + | ||
8 | + | ||
9 | +#define PRESCALER 1024 | ||
10 | +#define TIME_SLOT 20 | ||
11 | +#define BAUDRATE 103 | ||
12 | + | ||
13 | +//// INIT SERIAL ///// | ||
14 | + | ||
15 | +void init_serial(void) | ||
16 | +{ | ||
17 | + /* ACHTUNG : we suppose UBRR value < 0xff */ | ||
18 | + /* Not true in all case */ | ||
19 | + uint8_t baudrate = BAUDRATE; | ||
20 | + /* Set baud rate */ | ||
21 | + UBRR0H = 0; | ||
22 | + UBRR0L = baudrate; | ||
23 | + | ||
24 | + UCSR0B = (1<<TXEN0); | ||
25 | + /* Set frame format */ | ||
26 | + UCSR0C = 0x06; | ||
27 | + | ||
28 | +} | ||
29 | + | ||
30 | +//// ENVOI DE MESSAGES ///// | ||
31 | + | ||
32 | +void send_serial(unsigned char c) | ||
33 | +{ | ||
34 | + loop_until_bit_is_set(UCSR0A, UDRE0); | ||
35 | + UDR0 = c; | ||
36 | +} | ||
37 | + | ||
38 | + | ||
39 | +void send_msg2(char Donnee[]){ | ||
40 | + | ||
41 | + while (( UCSR0A & (1<<UDRE0)) == 0){}; | ||
42 | + | ||
43 | + for (int i = 0; i < strlen(Donnee); i++){ | ||
44 | + while (( UCSR0A & (1<<UDRE0)) == 0){}; | ||
45 | + UDR0 = Donnee[i]; | ||
46 | + if (i == (strlen(Donnee) - 1)){ | ||
47 | + send_serial('\n'); | ||
48 | + send_serial('\r'); | ||
49 | + } | ||
50 | + } | ||
51 | +} | ||
52 | + | ||
53 | +void send_msg(char Donnee[]){ | ||
54 | + int i=0; | ||
55 | + for(i=0; i<strlen(Donnee); i++){ | ||
56 | + if (i==strlen(Donnee)-1){ | ||
57 | + send_serial(Donnee[i]); | ||
58 | + send_serial('\n'); | ||
59 | + send_serial('\r'); | ||
60 | + } | ||
61 | + else{ | ||
62 | + send_serial(Donnee[i]); | ||
63 | + } | ||
64 | + _delay_ms(100); | ||
65 | + } | ||
66 | +} | ||
67 | + | ||
68 | +//////// RETOUR ///////// | ||
69 | +void retour(char* show_a){ | ||
70 | + send_msg2(show_a); | ||
71 | +} | ||
72 | + | ||
73 | + |