From 8bd8dd6ce07fb8e247f651b3c61c94bb1f00895a Mon Sep 17 00:00:00 2001 From: Väinö Kauppila Date: Sun, 19 Apr 2026 00:33:08 +0300 Subject: starting files and example programs --- PIC/test_uart.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 PIC/test_uart.c (limited to 'PIC/test_uart.c') diff --git a/PIC/test_uart.c b/PIC/test_uart.c new file mode 100644 index 0000000..f453e21 --- /dev/null +++ b/PIC/test_uart.c @@ -0,0 +1,36 @@ +#include + +typedef unsigned char uint8_t; + +// UART memory-mapped registers (hooked up in dpram.vhd). +// Placed at 0x70-0x72: unimplemented in the real PIC16F84A so no +// conflict with the SFR definitions in pic16f84a.h. +// 0x70 UART_TX write: transmit a byte +// 0x71 UART_RX read: receive a byte (pops the RX FIFO) +// 0x72 UART_STATUS read: bit0=tx_busy, bit1=rx_empty, bit2=rx_full +__sfr __at(0x70) UART_TX; +__sfr __at(0x71) UART_RX; +__sfr __at(0x72) UART_STATUS; + +static void uart_send(uint8_t byte) { + while (UART_STATUS & 0x01); // wait until tx_busy = 0 + UART_TX = byte; +} + +static void uart_puts(const char *s) { + while (*s) { + uart_send((uint8_t)*s); + s++; + } +} + +void main(void) { + uart_puts("Hello from PIC!\r\n"); + + // Echo loop: read every incoming byte and send it back + while (1) { + if (!(UART_STATUS & 0x02)) { // rx_empty = 0 → data available + uart_send(UART_RX); + } + } +} -- cgit v1.3