uart_printi

This commit is contained in:
Christoph J. Scherr 2023-12-09 12:06:16 +01:00
parent e09dfd8f3e
commit a51532e059
3 changed files with 17 additions and 6 deletions

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#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;

View File

@ -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();

View File

@ -4,8 +4,6 @@
#include <avr/io.h>
#include <util/delay.h>
#include "../include/uart.h"
#include <stdlib.h>
#include <stdlib.h>
#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);
}
}