UART test program for 16F628

Software in C (CCS PCM)

Function
This program sends an alive message and then echoes characters received from a terminal via RS232.

Hardware
The testboard K4 is set up with reset circuit and a ST232 (or MAX232) for RS232 communication.


Testboard K4 configured for UART test

Software in C

//************************************************************
// Function:  Test the UART at 9600 baud
// Processor: PIC16F628 at 4 MHz using internal RC oscillator
// Hardware:  Testboard K4
// Software:  CCS PCM
// Author:    Lars Petersen, [email protected]
// Website:   www.qsl.net/oz1bxm/PIC/pic.htm
//************************************************************

#include <16F628.h>
#fuses INTRC_IO, NOLVP, NOWDT, PUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=pin_B2, rcv=pin_B1)

main() {

   printf("PIC16F628 alive\n\r"); // send alive message

   while(true) {
      putc(getc());               // echo the received characters
   }
}

Remark #1
A PC terminal program (e.g. HyperTerminal) is set up for 9600 baud with 8 data bits, no parity, no flowcontrol and 1 stop bit. A screenshot showing terminal parametes in HyperTerminal can be found here.

Remark #2
The C-compiler loads CMCON at address 1F with value 7. This means, that the comperators in port A are off.



This page created October 14th, 2002 by Lars Petersen, [email protected]
Updated July 7th, 2003.

Back to PIC experiments