uart_printi
This commit is contained in:
parent
e09dfd8f3e
commit
a51532e059
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue