Super easy 18F print strings to UART


Closed Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2003
    Posts
    2,405

    Default Super easy 18F print strings to UART

    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.
    Code:
     ' 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.
    Attached Files Attached Files
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Memory use - how much do you use?
    By keymuu in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 10th June 2009, 22:39

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts