-
Notifications
You must be signed in to change notification settings - Fork 0
/
Serial.h
38 lines (32 loc) · 840 Bytes
/
Serial.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef msoe_sae_Serial_h
#define msoe_sae_Serial_h
typedef struct
{
register8_t udr;
register8_t ucsra;
register8_t ucsrb;
} Serial_t;
void SerialBegin(Serial_t* serial,uint32_t baud, register8_t udr,register8_t ucsra, register8_t ucsrb, register16_t ubrr)
{
serial->udr = udr;
serial->ucsra = ucsra;
serial->ucsrb = ucsrb;
*ubrr = 1000000UL/baud - 1; //Set the baud rate (assuming we are using the external 16mhz clock)
*ucsrb |= 1 << RXEN0; //Enable receive
*ucsrb |= 1 << TXEN0; //Enable transmit
}
void SerialSend(Serial_t* serial,uint8_t data)
{
*serial->udr = data;
while (!(*serial->ucsra & 1<<TXC0));
*serial->ucsra |= 1<<TXC0;
}
void SerialSend(Serial_t* serial, const char* data)
{
while (*data)
{
SerialSend(serial,*data);
data++;
}
}
#endif