PDA

View Full Version : Super easy 18F print strings to UART



Bruce
- 27th August 2007, 00:19
Just found this on the Microchip forum, and made a slight modification to it for use with PBP.
Thought someone here may find it useful.

Just include PrintStr.INC before you main routine. This is really nice for 18F parts, and super
easy to use. Here's a simple demo program using it with PBP.


' In-line string printing via the UART (18F parts only)

DEFINE LOADER_USED 1
DEFINE OSC 20

Butn VAR PORTB.0 ' push-button switch to ground on RB0

INTCON2.7=0 ' For 18F2431, PORTB pull-ups on
TRISB.0=1 ' Butn pin = input
PORTC.6=1 ' UART TX pin idles high
TRISC.6=0 ' UART TX pin = output

INCLUDE "PrintStr.INC"

Init:
TXSTA = $24 ' TX enabled, 8-bit, BRGH=1 for high-speed
SPBRG = 129 ' Set baud rate generator for 9600bps @20MHz
RCSTA = $90 ' USART enabled, 8-bit, continuous receive

PAUSE 5000
@ PrintStr "Start: Please press the button on RB0 to begin.\r\r\n"

Main:
WHILE Butn=1 ; wait for button press
WEND

@ PrintStr "Button pressed RB0 = 0\r\r\n"

WHILE Butn=0 ; wait for button release
WEND

@ PrintStr "Button released RB0 = 1\r\r\n"

PAUSE 1000
GOTO Main

END
The PrintStr include file is attached as PrintStr.txt. Just save it with the .inc extension. The
link to the original post on the Microchip forum is in the include file.