ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

ME Labs, Inc. | 1-719-520-5323 | Example Program - USART.pbp

PICBASIC PRO program to demonstrate reading & writing the hardware serial port without HSERIN/HSEROUT. Defaults to 2400 bps.
' Name        : USART.pbp
' Compiler    : PICBASIC PRO Compiler 2.6
' Assembler   : PM or MPASM
' Target PIC  : 16F, 18F with hardware USART
' Hardware    : PC hardware serial port connection
' Oscillator  : 4MHz external crystal or resonator
' Keywords    : HARDWARE USART
' Description : PICBASIC PRO program to demonstrate reading & writing
' the hardware serial port without HSERIN/HSEROUT. Defaults to 2400 bps.
'

B1 Var byte

' Initialize hardware USART
   TRISC = %10111111       ' Set TX (PortC.6) to out, rest in
   SPBRG = 25              ' Set baud rate to 2400
   RCSTA = %10010000       ' Enable serial port and continuous receive
   TXSTA = %00100000       ' Enable transmit and asynchronous mode

' Echo received characters in infinite loop
mainloop: 
   Gosub charin            ' Get a character from serial input, if any
   If B1 = 0 Then mainloop ' No character yet

   Gosub charout           ' Send character to serial output
   Goto mainloop           ' Do it forever

' Subroutine to get a character from USART receiver
charin:
   B1 = 0                  ' Preset to no character received

   If PIR1.5 = 1 Then      ' If receive flag then...
       B1 = RCREG          ' Get received character to B1
   Endif
   Return                  ' Go back to caller

' Subroutine to send a character to USART transmitter
charout:
   If PIR1.4 = 0 Then charout ' Wait for transmit register empty
   TXREG = B1              ' Send character to transmit register
   Return                  ' Go back to caller

   End

           

Download the program file.