From 86130c8747a4af7ce93f4ac93d1c4d9c94c917eb Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 23 Sep 2025 15:27:41 -0400 Subject: Add activity 5 --- project/Core/Src/Activties/activity5.c | 24 ++++++++++++++++++++++++ project/Core/Src/Homework/printf.c | 5 +++++ project/Core/Src/main.c | 6 ++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 project/Core/Src/Activties/activity5.c (limited to 'project/Core/Src') diff --git a/project/Core/Src/Activties/activity5.c b/project/Core/Src/Activties/activity5.c new file mode 100644 index 0000000..9201f70 --- /dev/null +++ b/project/Core/Src/Activties/activity5.c @@ -0,0 +1,24 @@ +/* + * activity5.c + * + * Created on: Sep 23, 2025 + * Author: sowgro + */ + + +#include +#include "printf.h" + +void read_and_print_char() { + uint8_t ch = USART_Read(USART2); + printf("%c", ch); + if (ch == '\r') { + printf("\n"); + } +} + +void run2() { + for(;;) { + read_and_print_char(); + } +} diff --git a/project/Core/Src/Homework/printf.c b/project/Core/Src/Homework/printf.c index 60605f8..9384215 100644 --- a/project/Core/Src/Homework/printf.c +++ b/project/Core/Src/Homework/printf.c @@ -13,6 +13,11 @@ char buffer[120]; +int putchar(int value) { + USART_Write(USART2, (unsigned char *) &value, 1); + return 1; +} + int puts(const char *string) { int n = strlen(string); USART_Write(USART2, (unsigned char *) string, n); diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c index 8d76d3a..ff819f2 100644 --- a/project/Core/Src/main.c +++ b/project/Core/Src/main.c @@ -8,6 +8,7 @@ #include "LED.h" #include "UART.h" #include "demo.h" +#include "activity5.h" #include "midi_header.h" #include @@ -19,9 +20,10 @@ int main(void){ LED_Init(); UART2_Init(); - printf("Hello world \r\n"); +// printf("Hello world \r\n"); - run(); +// run(); + run2(); // application run function // run_demo() ; -- cgit v1.2.3