PDA

View Full Version : serial LCD display?



ra68gi
- 6th March 2006, 14:20
Hello everbody,
Iam Interested in constructing a serial lcd display like the commercially available back pack.I tried using the serin command of Pic basic to receive the items( string of characters ) and display it on a 16*2 lcd Hitachi module in the 4 bit mode.It displayed junk.I was successful in displaying single variable but not string.can any one help me ? can any one give code example with serin2 with over flow pin,str(string variable).Preferably on pic16f84.A good explanation on its working will greatly be appreciated.
Thanks.
ra68gi.

BigWumpus
- 6th March 2006, 18:03
Hi,

The PIC is to slow to manage the seriel communication and the LCD-work in software !
You have to use an hardware-UART !
Try to use also an 32-byte-ringbuffer for the received data (Interrupt-service-routine in assembler).
I realized the same with an I2C-communication on a 16F872. The PIC is to big, but it is one of our "favorites".

victorf57
- 7th March 2006, 01:14
Look at the melabs site.
I know they have some examples for the lab X1 board and they may have it for others.
Victor

picster
- 8th March 2006, 02:28
I did this with a 'F88 - worked fine at 2400 baud (at 4MHz XT) so it should work fine on a 'F84/'F84A

I had it storing stuff in a buffer until it saw a chr$(13), then sending it all out to the LCD in one go...

Here's my code:

'Serial Control LCD
'for 24-char x 2 line display
'Serial data in at 2400 baud on PA0
'LCDout connections:
' PB0-PB3: DB4-DB7 ON LCD
' PB4: RS ON LCD
' PB5: E on LCD
' PB6: active high LCD backlight output
' R/W on LCD must be connected to GND
'
'Serial mode depends on the status of PA1 on powerup
' PA1=0:non-inverted mode (pic-to-pic)
' PA1=1:inverted mode (RS-232)
'
'turn the LCD backlight on/off by sending <1><13> or <0><13> respectively

DEFINE LCD_DREG PORTB 'set LCD data port
DEFINE LCD_DBIT 0 'Set starting Data bit (0 or 4) for 4-bit bus
DEFINE LCD_RSREG PORTB 'set LCD register select port
DEFINE LCD_RSBIT 4 'set LCD register select BIT
DEFINE LCD_EREG PORTB 'set LCD enable port
DEFINE LCD_EBIT 5 'set LCD enable bit
DEFINE LCD_BITS 4 'LCD bus size (4 or 8)
DEFINE LCD_LINES 2 'number of lines on LCD
DEFINE LCD_COMMANDUS 2000 'set command delay time in microseconds
DEFINE LCD_DATAUS 50 'set data delay time in microseconds
'
sermode VAR BYTE
mybyte VAR BYTE
pointer VAR BYTE
sendline VAR BYTE[24]
'
TRISA=63 'all inputs
TRISB=255 'all outputs
'note: pulldown PB3 if using 16F88
High PORTB.6

'read PA1 on powerup to determine mode
'jumper to ground for PIC-PIC communication (non-inverted, non-driven)
'jumper to + for RS-232 communication (inverted, driven)

IF PORTA.1=0 Then
sermode=0
Else
sermode=4
EndIF

Pause 1000 'initial pause before using the LCD
LCDOut $FE,1,"Display Initialized" 'clear display, send message
IF sermode=0 Then
LCDOut $FE,$C0,"PIC mode @2400 baud"
Else
LCDOut $FE,$C0,"RS-232 mode @2400 baud"
EndIF

Pause 2000 'wait 2 seconds
LCDOut $FE,1 'clear display again

NEWLINE:
pointer=0

GETMORE:
SerIn PORTA.0,sermode,,mybyte 'get 1 byte at a time
IF mybyte = 13 Then GoTo processme
sendline[pointer] = mybyte
pointer=pointer+1
GoTo getmore

processme:
IF pointer=1 AND sendline[0]=0 Then
Low PORTB.6 'turn off the LCD light if <0><13>
GoTo newline
EndIF

IF pointer=1 AND sendline[0]=1 Then
High PORTB.6 'turn on the lcd light if <1><13>
GoTo newline
EndIF

IF pointer=2 AND sendline[0]=$FE Then
IF sendline[1]=$01 Then 'clear display
LCDOut $FE,1
EndIF
IF sendline[1]=$02 Then 'return home
LCDOut $FE,2
EndIF
IF sendline[1]=$0C Then 'cursor off
LCDOut $FE,$0C
EndIF
IF sendline[1]=$80 Then 'beginning of first line
LCDOut $FE,$80
EndIF
IF sendline[1]=$C0 Then 'beginning of 2nd line
LCDOut $FE,$C0
EndIF
GoTo newline
EndIF


LCDOut STR sendline\pointer
GoTo newline
End

--------------Picster-------------

ra68gi
- 11th March 2006, 14:27
Picster,
Thanks for the code.I will soon try it out.I have a few more questions with regard to the code you have sent.
First,
' PA1=0:non-inverted mode (pic-to-pic)
' PA1=1:inverted mode (RS-232)

is there some sort of a convention to use non-inv mode for pic to pic & inverting mode for RS-232.
Please explain.

Second,
GETMORE:
SerIn PORTA.0,sermode,,mybyte 'get 1 byte at a time

I can see two comas after sermode.Is that right.
ra68gi

picster
- 12th March 2006, 20:05
Picster,
Thanks for the code.I will soon try it out.I have a few more questions with regard to the code you have sent.
First,
' PA1=0:non-inverted mode (pic-to-pic)
' PA1=1:inverted mode (RS-232)

is there some sort of a convention to use non-inv mode for pic to pic & inverting mode for RS-232.
Please explain.


You must use inverted mode (through a resistor) if you're using RS-232 voltage levels (i.e. - to a PC serial port). For PIC-PIC serial communication, this is not necessary, you can merely use non-inverted, TTL levels.



Second,
GETMORE:
SerIn PORTA.0,sermode,,mybyte 'get 1 byte at a time

I can see two comas after sermode.Is that right.
ra68gi

Yes, because there is no "qualifier" to satisfy, you put 2 commas in as placeholders.

----------------------Picster----------------------