|Use:||lcd_print( value1, value2, … )|
|Description:||Prints text onto an LCD|
|Values to printed.Value may be variable, a number, or a string.|
|Related:||lcd_enable, lcd2w_enable, print|
The lcd_print function writes text onto an LCD connected to the microcontroller.
There are two different ways in mpy to connect the LCD to a microcontroller. The first uses a direct connection using 6 wires, this is the parallel interface. The second interface uses 2 wires, this the serial interface. See here for instructions on how to connect to an LCD.
In order to use the LCD the LCD must first be enabled using either the lcd_enable or the lcd2w_enable command (depending on the interface type used).
The lcd_print command works in the same way as the print command, and printed values can be a variable, a number, or text.
A text value must be surrounded in single or double quotes, (Note text cannot be assigned to a variable.)
Example using the 6 wire interface:
lcd_enable( P1_7, P1_2, P1_5, P1_4, P1_3, P1_0) # DB7,DB6,DB5,DB4,EN,RS lcd_print( 'Hello from the 6 wire LCD' )
When the program runs you should see the following lines printed out on the LCD
Hello from the 6 wire LCD
You can use the lcd_print statement to print multiple values, and each value must be separated by a ‘,’.
Example using 2 wire interface:
lcd2w_enable(P1_0, P1_6) # DATA,CLOCK x = 200 lcd_print( 'The value of x is ', x )
This will print the following in the mpyUart window
The value of x i s 200
Each lcd_print statement is printed out on the first line of the LCD display. If the length of the text is greater than 16 characters the text will be continue onto the second line of the LCD.
If the there is no parameter after the last ‘ , ‘ this will cause the next lcd_print command to print out onto the same line.
2 wire example:
lcd2w_enable(P1_0, P1_6) # DATA,CLOCK lcd_print( 'Oh no! ' , ) lcd_print( 'BOOM')
Oh No! BOOM
If the variable name ends with ‘_hex‘, the variable will be printed using hexadecimal format. Hexadecimal numbers are often useful when you are using hardware registers in the microcontroller.
6 wire example
lcd_enable( P1_7, P1_2, P1_5, P1_4, P1_3, P1_0) y_hex = 1000 lcd_print( 'The hex value of y_hex is ', y_hex )
The hex value of y_hex is 3E8
Note: Variable names which end with ‘_hex‘ are just the same as ordinary variables. The ‘_hex‘ just changes the way it gets displayed with the lcd_print command.