Syntax
Print Item {, Item... }
Overview
Send Text to an LCD module using the Hitachi HD44780 controller or a graphic LCD based on the KS0108, or Toshiba T6963 chipsets.
Parameters
Item may be a constant, variable, expression, modifier, or string list. There are no operators as such, instead there are modifiers. For example, if an at sign'@' precedes an Item, the ASCII representation for each digit is sent to the LCD.
The modifiers are listed below: -
Modifier Operation
At Ypos (1 to n),Xpos(1 to n) Position the cursor on the LCD
| Cls | Clear the LCD (also creates a 30ms delay) |
| Bin{1..32} | Display binary digits |
| Dec{0..10} | Display decimal digits |
| Hex{1..8} | Display hexadecimal digits |
| Sbin{1..32} | Display signed binary digits |
| Sdec{0..10} | Display signed decimal digits |
| Shex{1..8} | Display signed hexadecimal digits |
| Ibin{1..32} | Display binary digits with a preceding '%' identifier |
| Idec{0..10} | Display decimal digits with a preceding '#' identifier |
| Ihex{1..8} | Display hexadecimal digits with a preceding '$' identifier |
| ISbin{1..32} | Display signed binary digits with a preceding '%' identifier |
| ISdec{0..10} | Display signed decimal digits with a preceding '#' identifier |
| IShex{1..8} | Display signed hexadecimal digits with a preceding '$' identifier |
| Rep c\n | Display character c repeated n times |
| Str array\n | Display all or part of an array |
| Cstr cdata | Display string data defined in a Cdata statement. |
The numbers after the Bin, Dec, and Hex modifiers are optional. If they are omitted, then the default is all the digits that make up the value will be displayed.
If a floating point variable is to be displayed, then the digits after the Dec modifier determine how many remainder digits are printed. i.e. numbers after the decimal point.
Dim MyFloat as Float
MyFloat = 3.145
Print Dec2 MyFloat ' Display 2 values after the decimal point
The above program will display 3.14
If the digit after the Dec modifier is omitted, then 3 values will be displayed after the decimal point.
Dim MyFloat as Float
MyFloat = 3.1456
Print Dec MyFloat ' Display 3 values after the decimal point
The above program will display 3.145
There is no need to use the Sdec modifier for signed floating point values, as the compiler's Dec modifier will automatically display a minus result: -
Dim MyFloat as Float
MyFloat = -3.1456
Print Dec MyFloat ' Display 3 values after the decimal point
The above program will display -3.145
Hex or Bin modifiers cannot be used with floating point values or variables.
The Xpos and Ypos values in the At modifier both start at 1. For example, to place the text "Hello World" on line 1, position 1, the code would be: -
Print At 1, 1, "Hello World"
Example 1
Dim Var1 as Byte
Dim Wrd as Word
Dim Dwd as Dword
Print "Hello World" ' Display the text "Hello World"
Print "Var1= ", Dec Var1 ' Display the decimal value of Var1
Print "Var1= ", Hex Var1 ' Display the hexadecimal value of Var1
Print "Var1= ", Bin Var1 ' Display the binary value of Var1
Print "Dwd= ", Hex6 Dwd ' Display 6 hex characters of a Dword variable
Example 2
' Display a negative value on the LCD.
Symbol Negative = -200
Print At 1, 1, Sdec Negative
Example 3
' Display a negative value on the LCD with a preceding identifier.
Print At 1, 1, IShex -$1234
Example 3 will produce the text "$-1234" on the LCD.
Some PICmicros such as the 16F87x, and 18FXXX range have the ability to read and write to their own flash memory. And although writing to this memory too many times is unhealthy for the PICmicro™, reading this memory is both fast, and harmless. Which offers a unique form of data storage and retrieval, the Cdata command proves this, as it uses the mechanism of reading and storing in the PICmicro's flash memory.
Combining the unique features of the ‘self modifying PICmicro's' with a string format, the compiler is capable of reducing the overhead of printing, or transmitting large amounts of text data. The Cstr modifier may be used in commands that deal with text processing i.e. Serout, HRsout, and RSOUT etc.
The Cstr modifier is used in conjunction with the Cdata command. The Cdata command is used for initially creating the string of characters: -
String1: Cdata "Hello World", 0
The above line of case will create, in flash memory, the values that make up the ASCII text "Hello World", at address String1. Note the null terminator after the ASCII text.
null terminated means that a zero (null) is placed at the end of the string of ASCII characters to signal that the string has finished.
To display this string of characters, the following command structure could be used: -
Print Cstr String1
The label that declared the address where the list of Cdata values resided, now becomes the string's name. In a large program with lots of text formatting, this type of structure can save quite literally hundreds of bytes of valuable code space.
Try both these small programs, and you'll see that using Cstr saves a few bytes of code: -
First the standard way of displaying text: -
Device = 16F1829
Cls
Print "HELLO WORLD"
Print "HOW ARE YOU?"
Print "I AM FINE!"
Stop
Now using the Cstr modifier: -
Cls
Print Cstr TEXT1
Print Cstr TEXT2
Print Cstr TEXT3
Stop
TEXT1: Cdata "HELLO WORLD", 0
TEXT2: Cdata "HOW ARE YOU?", 0
TEXT3: Cdata "I AM FINE!", 0
Again, note the null terminators after the ASCII text in the Cdata commands. Without these, the PICmicro™ will continue to transmit data in an endless loop.
The term 'virtual string' relates to the fact that a string formed from the Cdata command cannot be written too, but only read from.
The Str modifier is used for sending a string of bytes from a byte array variable. A string is a set of bytes sized values that are arranged or accessed in a certain order. The values 1, 2, 3 would be stored in a string with the value 1 first, followed by 2 then followed by the value 3. A byte array is a similar concept to a string; it contains data that is arranged in a certain order. Each of the elements in an array is the same size. The string 1,2,3 would be stored in a byte array containing three bytes (elements).
Below is an example that displays four bytes (from a byte array): -
Dim MyArray[10] as Byte ' Create a 10 element byte array.
MyArray [0] = "H" ' Load the first 5 bytes of the array
MyArray [1] = "E" ' With the data to send
MyArray [2] = "L"
MyArray [3] = "L"
MyArray [4] = "O"
Print Str MyArray\5 ' Display a 5-byte string.
Note that we use the optional \n argument of Str. If we didn't specify this, the PICmicro™ would try to keep sending characters until all 10 bytes of the array were transmitted. Since we do not wish all 10 bytes to be transmitted, we chose to tell it explicitly to only send the first 5 bytes.
The above example may also be written as: -
Dim MyArray[10] as Byte ' Create a 10 element byte array.
Str MyArray = "HELLO" ' Load the first 5 bytes of the array
Print Str MyArray\5 ' Send 5-byte string.
The above example, has exactly the same function as the previous one. The only difference is that the string is now constructed using Str as a command instead of a modifier.
Declares
There are several Declares for use with an Hitachi alphanumeric LCD and Print: -
Declare LCD_Type = 0 or 1 or 2, Alpha or Alphanumeric or Graphic or KS0108 or Toshiba or T6963 Inform the compiler as to the type of LCD that the Print command will output to. If Graphic, KS0108 or 1 is chosen then any output by the Print command will be directed to a graphic LCD based on the KS0108 chipset. A value of 2, or the text Toshiba, or T6963, will direct the output to a graphic LCD based on the Toshiba T6963 chipset. A value of 0 or Alpha, or if the Declare is not issued, will target the standard Hitachi HD44780 alphanumeric LCD type
Targeting the graphic LCD will also enable commands such as Plot, UnPlot, LCDread, LCDwrite, Pixel, Box, Circle and Line.
Declare LCD_DTPin = Port.Pin Assigns the Port and Pins that the LCD's DT lines will attach to.
The LCD may be connected to the microcontroller using either a 4-bit bus or an 8-bit bus. If an 8-bit bus is used, all 8 bits must be on one port. If a 4-bit bus is used, it must be connected to either the bottom 4 or top 4 bits of one port. For example: -
Declare LCD_DTPin PORTB.4 ' Used for 4-line interface.
Declare LCD_DTPin PORTB.0 ' Used for 8-line interface.
In the above examples, PORTB is only a personal preference. The LCD's DT lines can be attached to any valid port on the microcontroller.
Declare LCD_DataX_Pin = Port.Pin Assigns the individual Ports and Pins that the HD4470 LCD’s DT lines will attach to.
Unlike the above LCD_DTPin declares, the LCD’s data pins can also be attached to any separate port and pin. For example:-
Declare LCD_Data0_Pin PORTA.0 ' Connect PORTA.0 to the LCD’s D0 line
Declare LCD_Data1_Pin PORTA.2 ' Connect PORTA.2 to the LCD’s D1 line
Declare LCD_Data2_Pin PORTA.4 ' Connect PORTA.4 to the LCD’s D2 line
Declare LCD_Data3_Pin PORTB.0 ' Connect PORTB.0 to the LCD’s D3 line
Declare LCD_Data4_Pin PORTB.1 ' Connect PORTB.1 to the LCD’s D4 line
Declare LCD_Data5_Pin PORTB.5 ' Connect PORTB.5 to the LCD’s D5 line
Declare LCD_Data6_Pin PORTC.0 ' Connect PORTC.0 to the LCD’s D6 line
Declare LCD_Data7_Pin PORTC.1 ' Connect PORTC.1 to the LCD’s D7 line
There are no default settings for these Declares and they must be used within the BASIC program if required.
Declare LCD_ENPin = Port.Pin Assigns the Port and Pin that the LCD's EN line will attach to. This also assigns the graphic LCD's EN pin.
Declare LCD_RSPin = Port.Pin Assigns the Port and Pins that the LCD's RS line will attach to. This also assigns the graphic LCD's RS pin.
If the Declare is not used in the program, then the default Port and Pin is PORTB.3.
Declare LCD_Interface = 4 or 8 Inform the compiler as to whether a 4-line or 8-line interface is required by the LCD.
If the Declare is not used in the program, then the default interface is a 4-line type.
Declare LCD_Lines = 1, 2, or 4 Inform the compiler as to how many lines the LCD has.
LCD's come in a range of sizes, the most popular being the 2 line by 16 character types. However, there are 4-line types as well. Simply place the number of lines that the particular LCD has into the declare.
If the Declare is not used in the program, then the default number of lines is 2.
Declare LCD_CommandUs = 1 to 65535 Time to wait (in microseconds) between commands sent to the LCD.
If the Declare is not used in the program, then the default delay is 2000us (2ms).
Declare LCD_DataUs = 1 to 255 Time to wait (in microseconds) between data sent to the LCD.
If the Declare is not used in the program, then the default delay is 50us.
Notes
If no modifier precedes an item in a Print command, then the character’s value is sent to the LCD. This is useful for sending control codes to the LCD. For example: -
Print $FE, 128
Will move the cursor to line 1, position 1 (HOME).
Below is a list of some useful control commands: -
| Control Command | Operation |
| $FE, 1 | Clear display |
| $FE, 2 | Return home (beginning of first line) |
| $FE, $0C | Cursor off |
| $FE, $0E | Underline cursor on |
| $FE, $0F | Blinking cursor on |
| $FE, $10 | Move cursor left one position |
| $FE, $14 | Move cursor right one position |
| $FE, $C0 | Move cursor to beginning of second line |
| $FE, $94 | Move cursor to beginning of third line (if applicable) |
| $FE, $D4 | Move cursor to beginning of fourth line (if applicable) |
Note that if the command for clearing the LCD is used, then a small delay should follow it: -

Text in this figure or table
Print $FE, 1 : DelayMs 30
INTELLIGENT LCD
MODULE
5 Volts +5V
DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 EN R/W RS Vo VddVss R1 14 4.7k 13 VDD RB7
| 4 | 12 |
| MCLR | RB6 |
11
RB5 Contrast
10
4mHz RB4 47K
9 RB3
| Crystal | linear |
| 16 | 8 |
| OSC1 | RB2 |
7 RB1 6 RB0 PIC16F84 3 RA4
| C1 | 15 | 2 |
| OSC2 | RA3 | |
| 10uF | 1 |
RA2 18 RA1
C2 17
RA0 VSS
0.1uF C3 C4
5
22pF 22pF
0V
The above diagram shows the default connections for an alphanumeric LCD module. In this instance, connected to the 16F84 PICmicro™.






