backspace works

This commit is contained in:
hugogogo
2025-03-07 17:58:11 +01:00
parent 3140b1a491
commit 91788897b1
3 changed files with 29 additions and 22 deletions

View File

@@ -104,7 +104,8 @@ void uart_tx(char c) {
UDR0 = (unsigned char) c; // 20.11.1 : Put data into buffer, UDRn USART I/O Data Register (read and write) UDR0 = (unsigned char) c; // 20.11.1 : Put data into buffer, UDRn USART I/O Data Register (read and write)
} }
// screen /dev/ttyUSB0 115200 // write Z on serial port, at a !Hz frequency
// `screen /dev/ttyUSB0 115200`
int main() { int main() {
uart_init(); uart_init();
while (1) { while (1) {

View File

@@ -134,7 +134,7 @@ void uart_printstr(const char* str) {
} }
} }
// print hello world, on serial port, every 2 seconds, with empty infinite loop // print "Hello World!\n", on serial port, every 2 seconds, with empty infinite loop
// `screen /dev/ttyUSB0 115200` // `screen /dev/ttyUSB0 115200`
int main() { int main() {
uart_init(); uart_init();
@@ -154,5 +154,5 @@ int main() {
// ISR interrupt macro : https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html // ISR interrupt macro : https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html
ISR(TIMER1_COMPA_vect) { // Table 12-7 : we select the code for timer 1 on channel A ISR(TIMER1_COMPA_vect) { // Table 12-7 : we select the code for timer 1 on channel A
uart_printstr("Hello World!"); uart_printstr("Hello World!\r\n"); // \n and \r : https://stackoverflow.com/questions/7812142/how-to-toggle-cr-lf-in-gnu-screen
} }

View File

@@ -142,7 +142,13 @@ void uart_tx(char c) {
ISR(USART_RX_vect) { // Table 12-7 : we select the code for USART Receive ISR(USART_RX_vect) { // Table 12-7 : we select the code for USART Receive
// char received_char = uart_rx(); // char received_char = uart_rx();
char received_char = UDR0; // Read received character char received_char = UDR0; // Read received character
if (received_char == '\b' || received_char == 127) { // If backspace is received
uart_tx('\b'); // Move cursor back
uart_tx(' '); // Erase the character on screen
uart_tx('\b'); // Move cursor back again
} else {
uart_tx(SWITCH_CASE(received_char)); // Toggle case and send back uart_tx(SWITCH_CASE(received_char)); // Toggle case and send back
}
} }
// send back caracters received on serial port with case toggling, using interupt and empty infinite loop // send back caracters received on serial port with case toggling, using interupt and empty infinite loop