View Full Version : Serial LCD ?
Tobias
- 29th November 2008, 05:16
I am using a PIC16F876A. I bought a MELabs serial LCD a while ago. I connected it today to the PIC and loaded the "Hello World" program (hellox2.bas) I modified the mode from T9600 to N9600. I get characters on the LCD and probably would make sense if I spoke Russian, yet I skipped that class in high school. Is this code correct for the LCD and PIC I am using? Could I have damaged the LCD sometime long ago? When I ground out two of the pins on the back of the display to get the default values I get V1.1 N9600. Any ideas?
Include "modedefs.bas" ' Mode definitions for Serout
loop: Serout PORTC.6,N9600,["Hello",10,13] ' Display "Hello", next line
Pause 500 ' Wait .5 second
Serout PORTC.6,N9600,["World",10,13,10,13] ' Display "World", skip a line
Pause 500 ' Wait .5 second
Goto loop ' Do it forever
End
Pic2008
- 30th November 2008, 13:10
Have you wired the LCD correctly to your PIC?
Check out the code below:
' Program SER_LCD.BAS
' ************************************************** *********************
' Simple Serial LCD Controller
' ************************************************** *********************
Include "Modedefs.bas"
DEFINE OSC 4 ' Set the Xtal frequency to 4mHz
' ** Declare LCDOUT Defines **
DEFINE LCD_DREG PortB ' Set Data to PortB
DEFINE LCD_DBIT 0 ' Set starting Data to Bit0
DEFINE LCD_RSREG PortA ' Set Register Select to PortA
DEFINE LCD_RSBIT 2 ' Set RS line to PORTA.2
DEFINE LCD_EREG PortA ' Set Enable to PortA
DEFINE LCD_EBIT 3 ' Set Enable line to PortA.3
DEFINE LCD_BITS 8 ' Set for 8 bit Bus
DEFINE LCD_LINES 2 ' Set number of lines to 2
' ** Define LCD Control Constants **
I Con 254 ' Control Byte
Clr Con 1 ' Clear the display
Line1 Con 128 ' Point to beginning of line 1
Line2 Con 192 ' Point to beginning of line 2
Line3 Con 148 ' Point to beginning of line 3
Line4 Con 212 ' Point to beginning of line 4
Cgram Con 64 ' Point to Cgram within LCD
Shift_L Con 24 ' Shift display left
Shift_R Con 28 ' Shift display right
' ** Declare Variables **
SO Var PortA.0 ' Serial In Inverted
VDD Var PortA.1 ' LCD VDD pin
SO2 Var PortA.4 ' Serial In True
P_Test Var PortB.4 ' Pin for polarity setting
Rcvbyte Var Byte ' The byte received
Main:
Low VDD ' Turn Off LCD
Pause 500 ' Wait for Pic to Initialise
High VDD ' Turn On LCD
Pause 50 ' Wait for LCD to Initialize
' ** Check for Polarity Setting **
TrisB=255 ' Set PortB to Input
If P_Test=1 then Goto True_Pol ' PortB.4 HI then True Polarity
If P_Test=0 then Goto Inv_Pol ' PortB.4 LO then Inverted Polarity
Goto Main ' Just In case it Missed the settings
' ** Receive characters serially with True polarity **
True_Pol:
Gosub Clr_It ' Initialize the LCD
Lcdout I,Line2," T9600 Baud OK!" ' Print message
Start_T9600:
Serin SO,T9600,Rcvbyte ' Get Serial Data in
Lcdout Rcvbyte ' Send send straight out to LCD
Goto Start_T9600 ' Loop back forever
' ** Receive characters serially with Inverted polarity **
Inv_Pol:
Gosub Clr_It ' Initialize the LCD
Lcdout I,Line2," N9600 Baud OK!" ' Print message
Start_N9600:
Serin SO,N9600,Rcvbyte ' Get Serial Data in
Lcdout Rcvbyte ' Send straight out to LCD
Goto Start_N9600 ' Loop back forever
' Initialize LCD ready to print
Clr_It:
High VDD ' Switch On LCD VDD
TrisB=0 ' Set Port to Output
Pause 100 ' Wait for LCD to Initialise
Lcdout I,Clr:Pause 30 ' Clear the LCD
Lcdout I,Line1," LCD Serializer"
Return
Archangel
- 1st December 2008, 05:28
Hello Tobias,
most likely you are not matched as to T/N and baud rate to your serial LCD. I am not familiar with your particular serial LCD, try some different baud rates and try them true and inverted. I would just make several serout statements with a string to identify, the one you can read is the one you use, example:
Serout PORTC.6,N9600,["9600 inverted"]
pause 500
Serout PORTC.6,T9600,["9600 True"]
pause 500
Serout PORTC.6,N2400,["2400 inverted"]
pause 500
Serout PORTC.6,T2400,["2400 True"]
pause 500
add the rest of the available choices and you have a test program to sort out the settings of your LCD.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.