Commit e742bccc85fd659b0d596cd2a76444f7d4f7f5cc
1 parent
ac8974ba
ADD - Séparation des fonctions de liaison série dans une librairie serial.
Cette librairie contient également la fonction send_ack qui sera utilisé pour informer de la réalisation de l'action
Showing
2 changed files
with
46 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,33 @@ |
1 | +#include "serial.h" | |
2 | + | |
3 | +void init_serial(unsigned long int speed) //initialisation de la liaison série | |
4 | +{ | |
5 | +/* Set baud rate */ | |
6 | +UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; | |
7 | + | |
8 | +/* Enable transmitter & receiver */ | |
9 | +UCSR0B = (1<<TXEN0 | 1<<RXEN0); | |
10 | + | |
11 | +/* Set 8 bits character and 1 stop bit */ | |
12 | +UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); | |
13 | + | |
14 | +/* Set off UART baud doubler */ | |
15 | +UCSR0A &= ~(1 << U2X0); | |
16 | +} | |
17 | + | |
18 | +void send_serial(uint8_t c) //envoyer un carctère sur le port série | |
19 | +{ | |
20 | +loop_until_bit_is_set(UCSR0A, UDRE0); | |
21 | +UDR0 = c; | |
22 | +} | |
23 | + | |
24 | + | |
25 | +uint8_t get_serial(void) //récupérer un caractère envoyé sur le port série | |
26 | +{ | |
27 | +loop_until_bit_is_set(UCSR0A, RXC0); | |
28 | +return UDR0; | |
29 | +} | |
30 | + | |
31 | +void send_ack(void){ | |
32 | + send_serial(0x01); | |
33 | +} | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +#ifndef __SERIAL_H__ | |
2 | +#define __SERIAL_H__ | |
3 | + | |
4 | +#include <avr/io.h> // for the input/output register | |
5 | +#include <util/delay.h> | |
6 | + | |
7 | +#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz | |
8 | + | |
9 | +void init_serial(unsigned long int speed); | |
10 | +void send_serial(uint8_t c); | |
11 | +uint8_t get_serial(void); | |
12 | +void send_ack(void); | |
13 | +#endif | ... | ... |