uart_printi
This commit is contained in:
parent
e09dfd8f3e
commit
d22c59614c
3 changed files with 17 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -24,10 +24,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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue