#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); } } }