40 lines
751 B
C
40 lines
751 B
C
#define F_CPU 16000000UL
|
|
#define __AVR_ATmega328P__
|
|
#include <avr/interrupt.h>
|
|
#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
|
|
|
|
|
|
int main (void)
|
|
{
|
|
uart_init();
|
|
sei();
|
|
|
|
char buf[10];
|
|
int sensor;
|
|
|
|
while (1)
|
|
{
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
ISR (USART_RX_vect) {
|
|
// echo the message
|
|
char c = UDR0;
|
|
uart_printc(c);
|
|
}
|