yacwc
This commit is contained in:
94
helpers_uart.c
Normal file
94
helpers_uart.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "helpers_uart.h"
|
||||
|
||||
|
||||
|
||||
void USART0_init(void) {
|
||||
PORTA.DIR &= ~PIN1_bm;
|
||||
PORTA.DIR |= PIN0_bm;
|
||||
|
||||
USART0.BAUD = (uint16_t) USART0_BAUD_RATE(9600);
|
||||
USART0.CTRLB |= USART_TXEN_bm;
|
||||
}
|
||||
|
||||
void USART0_sendChar(char c) {
|
||||
while (!(USART0.STATUS & USART_DREIF_bm)) {
|
||||
;
|
||||
}
|
||||
USART0.TXDATAL = c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void USART0_sendString(const char *str) {
|
||||
for (size_t i = 0; i < strlen(str); i++) {
|
||||
USART0_sendChar(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void uart_print_uint16(uint16_t meas, const char* buf) {
|
||||
|
||||
sprintf(array, "%u", meas);
|
||||
USART0_sendString(" ");
|
||||
USART0_sendString(array);
|
||||
USART0_sendString(" ");
|
||||
USART0_sendString(buf);
|
||||
|
||||
}
|
||||
|
||||
void uart_print_float(float meas, const char* buf) {
|
||||
dtostrf(meas, 3, 4, array);
|
||||
USART0_sendString(" ");
|
||||
USART0_sendString(array);
|
||||
USART0_sendString(" ");
|
||||
USART0_sendString(buf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void uart_print_bool(bool din, const char* buf)
|
||||
{
|
||||
USART0_sendString(" ");
|
||||
if (din)
|
||||
{
|
||||
USART0_sendString("TRUE ");
|
||||
} else
|
||||
{
|
||||
USART0_sendString("FALSE");
|
||||
}
|
||||
USART0_sendString(" ");
|
||||
USART0_sendString(buf);
|
||||
|
||||
}
|
||||
|
||||
void uart_print_binary(unsigned char vin, const char* buf) {
|
||||
|
||||
USART0_sendString(" ");
|
||||
|
||||
int binary[9];
|
||||
for (int n = 0; n < 8; n++)
|
||||
binary[7 - n] = (vin >> n) & 1;
|
||||
|
||||
|
||||
char str[1];
|
||||
for (int n = 0; n < 8; n++) {
|
||||
sprintf(str, "%d", binary[n]);
|
||||
USART0_sendString(str);
|
||||
}
|
||||
|
||||
USART0_sendString(" ");
|
||||
USART0_sendString(buf);
|
||||
|
||||
}
|
||||
|
||||
void uart_print_uint8(uint8_t vin, const char* buf) {
|
||||
|
||||
USART0_sendString(" ");
|
||||
sprintf(array, "%u", vin);
|
||||
|
||||
USART0_sendString(array);
|
||||
USART0_sendString(" ");
|
||||
USART0_sendString(buf);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user