usart character output

This commit is contained in:
maddiebaka
2026-04-26 11:00:40 -04:00
parent 103fa9e8a8
commit 89a9b79aa9
2 changed files with 30 additions and 2 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
[env:pro16MHzatmega328] [env:pro16MHzatmega328]
platform = atmelavr platform = atmelavr
board = pro16MHzatmega328 board = pro16MHzatmega328
monitor_speed = 115200 monitor_speed = 9600
lib_deps = lib_deps =
https://github.com/Sylaina/bme280.git https://github.com/Sylaina/bme280.git
+29 -1
View File
@@ -3,12 +3,38 @@
* See LICENSE for details. * See LICENSE for details.
*/ */
#define F_CPU 16000000UL
#define BAUD 9600
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h> #include <util/delay.h>
#include <util/setbaud.h>
#include "bme280.h" #include "bme280.h"
#include <stdio.h> #include <stdio.h>
void uart_init(void) {
// Set baud rate
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
// Don't use double rate
UCSR0A &= ~(1 << U2X0);
// Enable rx and tx
UCSR0B = (1 << TXEN0) | (1 << RXEN0);
// Set frame format: 8-N-1
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
}
void uart_putchar(char c) {
while(!(UCSR0A & (1 << UDRE0)));
UDR0 = c;
}
int main(void) int main(void)
{ {
// make the LED pin an output for PORTB5 // make the LED pin an output for PORTB5
@@ -24,12 +50,14 @@ int main(void)
pressure = bme280_readPressure(0); pressure = bme280_readPressure(0);
humidity = bme280_readHumidity(0); humidity = bme280_readHumidity(0);
uart_init();
while (1) while (1)
{ {
_delay_ms(1000); _delay_ms(1000);
uart_putchar('!');
printf("Temp: %f\tPressure: %f\tHumidity: %f\n", temp, pressure, humidity); //printf("Temp: %f\tPressure: %f\tHumidity: %f\n", temp, pressure, humidity);
// toggle the LED // toggle the LED
PORTB ^= 1 << 5; PORTB ^= 1 << 5;