diff --git a/include/uart.c b/include/uart.c index 8b6cecf..3ecd4f3 100644 --- a/include/uart.c +++ b/include/uart.c @@ -1,3 +1,4 @@ +#include #include "uart.h" void uart_init() { /* This make stuff not work, idk @@ -24,10 +25,24 @@ void uart_printc(char c) { /* Put data into buffer, sends the data */ UDR0 = c; } +void uart_printsnl(char* s) { + while(*s) + uart_printc(*s++); + uart_printc('\n'); +} void uart_prints(char* s) { while(*s) uart_printc(*s++); } +void uart_printi(char* pre, int i) { + // we want to print this, + // so we store the ascii repr in our buffer + char buf[10]; + itoa(i, buf, 10); // base 10 + uart_prints(pre); + uart_printsnl(buf); + +} char uart_getc() { while (UCSR0A & (1 << RXC0)); return UDR0; diff --git a/include/uart.h b/include/uart.h index 6d4e40e..bf4cd06 100644 --- a/include/uart.h +++ b/include/uart.h @@ -8,5 +8,6 @@ void uart_init(); void uart_prints(char* s); void uart_printc(char c); +void uart_printi(char* pre, int i); char uart_getc(); diff --git a/print/main.c b/print/main.c index 5b65a87..12b0981 100644 --- a/print/main.c +++ b/print/main.c @@ -4,8 +4,6 @@ #include #include #include "../include/uart.h" -#include -#include #define BAUD 9600 #define MYUBRR F_CPU/16/BAUD-1 @@ -24,10 +22,7 @@ int main (void) // lets say we read some value from a sensor sensor = 65; // we want to print this, so we store the ascii repr in our buffer - itoa(sensor, buf, 10); // base 10 - uart_prints("sensor status: "); - uart_prints(buf); - uart_prints("\n"); + uart_printi("sensor status: ", sensor); _delay_ms(1000); } }