diff options
| author | Väinö Kauppila <vaino@vke.fi> | 2026-04-19 00:33:08 +0300 |
|---|---|---|
| committer | Väinö Kauppila <vaino@vke.fi> | 2026-04-19 00:33:08 +0300 |
| commit | 8bd8dd6ce07fb8e247f651b3c61c94bb1f00895a (patch) | |
| tree | 87bd95bd073d68efd0ad31a34f0d8926c32ff6db /PIC/test_uart.c | |
| download | vhdl_pic-8bd8dd6ce07fb8e247f651b3c61c94bb1f00895a.tar.gz vhdl_pic-8bd8dd6ce07fb8e247f651b3c61c94bb1f00895a.zip | |
starting files and example programs
Diffstat (limited to 'PIC/test_uart.c')
| -rw-r--r-- | PIC/test_uart.c | 36 |
1 files changed, 36 insertions, 0 deletions
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 <pic16f84a.h> + +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); + } + } +} |
