-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSART.h
45 lines (37 loc) · 1.72 KB
/
USART.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
39
40
41
42
43
44
45
/* Functions to initialize, send, receive over USART
initUSART requires BAUD to be defined in order to calculate
the bit-rate multiplier.
*/
#ifndef BAUD /* if not defined in Makefile... */
#define BAUD 9600 /* set a safe default baud rate */
#endif
/* These are defined for convenience */
#define USART_HAS_DATA bit_is_set(UCSR0A, RXC0)
#define USART_READY bit_is_set(UCSR0A, UDRE0)
/* Takes the defined BAUD and F_CPU,
calculates the bit-clock multiplier,
and configures the hardware USART */
void initUSART(void);
/* Blocking transmit and receive functions.
When you call receiveByte() your program will hang until
data comes through. We'll improve on this later. */
void transmitByte(uint8_t data);
uint8_t receiveByte(void);
void printString(const char myString[]);
/* Utility function to transmit an entire string from RAM */
void readString(char myString[], uint8_t maxLength);
/* Define a string variable, pass it to this function
The string will contain whatever you typed over serial */
void printByte(uint8_t byte);
/* Prints a byte out as its 3-digit ascii equivalent */
void printWord(uint16_t word);
/* Prints a word (16-bits) out as its 5-digit ascii equivalent */
void printBinaryByte(uint8_t byte);
/* Prints a byte out in 1s and 0s */
char nibbleToHex(uint8_t nibble);
char nibbleToHexCharacter(uint8_t nibble);
void printHexByte(uint8_t byte);
/* Prints a byte out in hexadecimal */
uint8_t getNumber(void);
/* takes in up to three ascii digits,
converts them to a byte when press enter */