monitor example sensor value

This commit is contained in:
Christoph J. Scherr 2023-12-09 12:00:23 +01:00
parent 4e85110447
commit e09dfd8f3e
2 changed files with 13 additions and 2 deletions

View File

@ -27,7 +27,6 @@ void uart_printc(char c) {
void uart_prints(char* s) { void uart_prints(char* s) {
while(*s) while(*s)
uart_printc(*s++); uart_printc(*s++);
uart_printc('\n');
} }
char uart_getc() { char uart_getc() {
while (UCSR0A & (1 << RXC0)); while (UCSR0A & (1 << RXC0));

View File

@ -4,6 +4,8 @@
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h> #include <util/delay.h>
#include "../include/uart.h" #include "../include/uart.h"
#include <stdlib.h>
#include <stdlib.h>
#define BAUD 9600 #define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1 #define MYUBRR F_CPU/16/BAUD-1
@ -13,9 +15,19 @@ int main (void)
{ {
uart_init(); uart_init();
sei(); sei();
char buf[10];
int sensor;
while (1) while (1)
{ {
uart_prints("foofofofo"); // 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");
_delay_ms(1000); _delay_ms(1000);
} }
} }