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

PICBASIC PRO program to demonstrate a method of storing text strings in a table. The strings can be called by storing the location of the first character in a variable and calling the strout subroutine. The string will be sent to both LCD and Serial pin and the main program will resume when the null terminating character is encountered in the table.
' Name        : STRTBLX.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    : LCDOUT, LOOKUP, SEROUT2
' Description : PICBASIC PRO program to demonstrate a method of storing
' text strings in a table. The strings can be called by storing the
' location of the first character in a variable and calling the strout subroutine.
' The string will be sent to both LCD and Serial pin and the main program will
' resume when the null terminating character is encountered in the table.
'

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

strloc   VAR BYTE   ' Stores the numerical location of the first character in the string
nextchar VAR BYTE   ' Stores each charater retrieved from the table

' Use constants to hold the locations of your strings. This will make
' modifications easier and it doesn't use any RAM or code space.
hello CON 0         ' "Hello" is at location 0
world CON 6	    ' "World" is at location 6

   ANSEL = %00000000 ' Make PORTA and PORTE digital
   ANSELH= %00000000 ' Make PORTA and PORTE digital
   Low PORTE.2      ' LCD R/W line low (W)
   Pause 200        ' Wait for LCD to start up

mainloop:	    ' Main program starts here
   LCDOut $fe, 1    ' Clear LCD screen
   SerOut2 PORTC.6, 396, [10,13,10,13] ' Send linefeeds on serial
   Pause 500        ' Wait .5 second

   strloc = hello   ' Prepare to get string "Hello" (strloc = 0)
   GoSub strout     ' Display the string
   Pause 500        ' Wait .5 second
	
   LCDOut $fe, $c0  ' Move LCD cursor to second line
   SerOut2 PORTC.6, 396, [10,13] ' Send linefeed on serial
   strloc = world   ' Prepare to get string "World" (strloc = 6)
   GoSub strout	    ' Make it so
   Pause 500        ' Wait .5 second
   GoTo mainloop    ' Do it forever

' Beginning of string-display routine
strout: 
   ' Put strings in this table, terminating each with a 0 (null value)
   LookUp strloc, ["Hello",0,"World",0], nextchar ' get character in specified location
   IF nextchar != 0 Then   ' Check for null value (end of string), if not null:
      LCDOut nextchar	   ' Put the character on the display
      SerOut2 PORTC.6, 396, [nextchar]	' Send the character on the serial port.
      strloc = strloc + 1  ' Increment position in table
      GoTo strout	   ' Jump to get another character
   EndIF
   Return		   ' Return when the string is complete
		
   End

           

Download the program file.