Posts

Showing posts with the label PIC16F877A

PIC16F877A - UART Registers

Image
Registers used for Serial Communication TXSTA RCSTA (Receive Status And Control Register) SPBRG (USART Baud Rate Generator) TXREG (USART Transmit Register) RCREG (USART Receiver Register) TXSTA (Transmit Status And Control Register) This register is used to configure the Serial communication for TX. CSRC: Clock Source Select bit (Asynchronous mode: Don’t care). TX9 : 9-bit Transmit Enable bit 1 = Selects 9-bit transmission 0 = Selects 8-bit transmission TXEN : Transmit Enable bit 1 = Transmit enabled 0 = Transmit disabled SYNC : USART Mode Select bit 1 = Synchronous mode 0 = Asynchronous mode  BRGH : High Baud Rate Select bit 1 = High speed 0 = Low speed TRMT : Transmit Shift Register Status bit 1 = TSR empty 0 = TSR full TX9D : 9th bit of Transmit Data, can be a Parity bit RCSTA (Receive Status And Control Register) Register is used to configure the Serial communication for RX. SPEN : Serial Port Enable bit 1 = Serial port enabled (configures RC7/RX/DT and RC6/TX/CK pins as seri...

PIC16F877A - UART Transmitter (with code)

Image
   CODE TO TRANSMIT STRING (Pic16f877A) -Xc8 Compiler #include <xc.h> #define _XTAL_FREQ 8000000  // Define the oscillator frequency (e.g., 8 MHz) void main() {     TRISC6 = 0;  // TX pin (RC6) set as output     TRISC7 = 1;  // RX pin (RC7) set as input     // UART initialization     SPBRG = 51;             // Baud rate set to 9600 for 8 MHz     TXSTAbits.BRGH = 1;     // High Baud Rate Select bit     TXSTAbits.TXEN = 1;     // Enable transmitter     RCSTAbits.SPEN = 1;     // Enable UART (serial port)     // Transmit the text repeatedly     while (1)     {         const char* message = "Hello, UART!\r\n";  // Message to transmit         const char* ptr = message;  // Pointer to the message         while (*ptr ...