sysprog-basic/print/main.c

41 lines
884 B
C
Raw Normal View History

2023-12-09 11:27:55 +01:00
#define F_CPU 16000000UL
#define __AVR_ATmega328P__
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
#include "../include/uart.h"
2023-12-09 14:20:18 +01:00
#include "../include/adc.h"
#include "../include/rand.h"
2023-12-09 11:27:55 +01:00
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
int main (void)
{
uart_init();
2023-12-09 14:29:29 +01:00
adc_init();
2023-12-09 11:27:55 +01:00
sei();
2023-12-09 12:00:23 +01:00
2023-12-09 14:29:29 +01:00
uint16_t sensor[2] = { 0, 1 };
2023-12-09 12:00:23 +01:00
2023-12-09 11:27:55 +01:00
while (1)
{
2023-12-09 12:00:23 +01:00
// lets say we read some value from a sensor
2023-12-09 14:29:29 +01:00
sensor[0] = adc_read(0);
sensor[1] = adc_read(1);
2023-12-09 12:00:23 +01:00
// we want to print this, so we store the ascii repr in our buffer
2023-12-09 14:20:18 +01:00
uart_printi("sensor 0: ", sensor[0]);
uart_printi("sensor 1: ", sensor[1]);
2023-12-09 14:36:58 +01:00
uart_printi("sensor 2 (noise): ", adc_read(2));
uart_printi("rand: ", rand());
2023-12-09 11:50:23 +01:00
_delay_ms(1000);
2023-12-09 11:27:55 +01:00
}
}
ISR (USART_RX_vect) {
// echo the message
char c = UDR0;
uart_printc(c);
}