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 - HSERX.pbp

PICBASIC PRO to send and receive from the hardware serial port.
' Name        : HSERX.pbp
' Compiler    : PICBASIC PRO Compiler 2.60
' Assembler   : PM or MPASM
' Target PIC  : 40-pin 16F887
' Hardware    : LAB-X1 Experimenter Board
' Oscillator  : 4MHz external crystal
' Keywords    : HSERIN, HSEROUT, LCDOUT
' Description : PICBASIC PRO to send and receive from the hardware
' serial port.
'

' Define LCD registers and bits
Define LCD_DREG  PORTD
Define LCD_DBIT  4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG  PORTE
Define LCD_EBIT  1

char Var Byte       ' Storage for serial character
col  Var Byte       ' Keypad column
row  Var Byte       ' Keypad row
key  Var Byte       ' Key value
lastkey Var Byte    ' Last key storage

   ANSEL = %00000000 ' Make AN0-AN7 digital
   ANSELH= %00000000 ' Make AN8-AN13 digital
   Low PORTE.2      ' LCD R/W line low (W)
   Pause 500	    ' Wait for LCD to startup

   OPTION_REG.7 = 0 ' Enable PORTB pullups

   key = 0          ' Initialize vars
   lastkey = 0
   Lcdout $fe, 1    ' Initialize and clear LCD display

mainloop:
   Hserin 1, tlabel, [char] ' Get a char from serial port
   Lcdout char              ' Send char to display

tlabel: 
   Gosub getkey             ' Get a keypress if any
   If (key != 0) and (key != lastkey) Then
       Hserout [key]        ' Send key out serial port
   Endif
   lastkey = key            ' Save last key value
   Goto mainloop            ' Do it all over again

' Subroutine to get a key from keypad
getkey:
   key = 0                  ' Preset to no key
   For col = 0 To 3         ' 4 columns in keypad
       PORTB = 0            ' All output pins low
       TRISB = (dcd col) ^ $ff ' Set one column pin to output
       row = PORTB >> 4     ' Read row
       If row != $f Then gotkey ' If any keydown, exit
   Next col
   Return                   ' No key pressed

gotkey: ' Change row and column to ASCII key number
   key = (col * 4) + (ncd (row ^ $f)) + "0"
   Return                   ' Subroutine over

   End

           

Download the program file.