PICBasic and PICBasic Pro Examples

Connect the serial input of the LCD to PortB.0 (pin 6) of a PIC Microcontroller. The following PIC Basic program demonstrates sending data and commands to the LCD:

main:

pause 1000 ' wait for the LCD to startup
serout 0,T2400,($FE,$01) ' clear the screen
serout 0,T2400,("Wherever you go") ' send the string “wherever you go'
serout 0,T2400,($FE,$C0) ' move the cursor to the second line
serout 0,T2400,(" there you are ") ' send the string “ there you are “
pause 1000 ' wait one second
goto main ' do it again

The program will clear the LCD and send the message: “Wherever you go, there you are” at 2400 baud (true mode), wait for two seconds and then loop indefinitly. Note that in the above example, the control codes were written in hexidecimal (base 16). Hexidecimal is specified by a dollar sign ($) prefix. If you wish, the lines:

serout 0,T2400,($FE,$01) ' clear the screen
serout 0,T2400,($FE,$C0) ' move the cursor to the second line

Could also be written with decimal (base 10) notation as:

serout 0,T2400,(254,1) ' clear the screen
serout 0,T2400,(254,192) ' move the cursor to the second line

Which notation you choose to use is a matter of preference. An equivalent program can be written with PIC Basic Pro as follows:

main:

pause 1000 ' wait for the LCD to startup
serout PortB.0,0,[$FE,$01] ' clear the screen
serout PortB.0,0,["Wherever you go"] ' send string “Wherever you go”
serout PortB.0,0,[$FE,$C0] ' move the cursor to the 2nd line
serout PortB.0,0,[" there you are "] ' send string “ there you are ”
pause 1000 ' pause for a second
goto main ' loop

Message

Printing Variables in PICBasic and PICBasic Pro

Say you have a variable, foo, in which some number is stored. In PIC Basic, foo would be declared like so:

symbol foo = B0

In PIC Basic Pro, foo would be declared:

foo var byte

The serout command, when given a variable, will by default print the character which is represented by the number stored in the variable and not the value of the variable itself. If you want to print the number inside the variable, you must prefix the variable name with a pound sign (‘#’). For example, if the value of foo was 65:

serout 0,T2400,(foo) ' PICBasic, prints ‘A’ character
serout 0,0,[foo] ' PICBasic Pro, prints ‘A’ character

The above example would not print “65” on the display, but meerly the ascii character ‘A’ (capital A). Why? Look at an ASCII decimal to character chart -- the ASCII representation of the number “65” is ‘A’! Likewise, if foo was 66, a ‘B’ would have been printed, etc. While this may be desirable for some applications, most would simply want the “65” to print and not it’s ASCII equivalent. To do accomplish this -- that is, to print a variable foo in numeric form -- we prefix the varaible with a pound sign, as noted above:

serout 0,T2400,(#foo) ' PICBasic, prints “65”
serout 0,0,[#foo] ' PICBasic Pro, prints “65”

Dimensions and Specifications

  • 16 characters x 2 lines
  • High-contrast supertwist display
  • LED Backlight
  • Accepts RS232, inverted or true TTL / CMOS at 300, 1200, 2400 and 9600 bps.
  • Power Requirment: 4.8 - 5.2 VDC, approx. 40 mA
  • Size: 3.1" L x 1.4" W
  • Weight: 0.1 lbs

Next Page