Angry Badger
Member
Hello,
I am playing with an LCD display for the first time and suspect that somehow its' character memory has been corrupted by yours truly.
Initially I had a go at getting the display working by myself but couldn't so then had a look at Nigels' tutorial (thanks Nigel - they really are useful for beginners like me). I modded the code a little; stripped out irrelevent bits and used 8 bit rather than 4 bit mode. However, now that it 'works' I see most of the characters are not as they should be; in the first pic it should display 'Hello / ready...' and in the second the whole alphabet capitalised.
Did I corrupt the character memory (CGRAM) when I first fiddled - is that possible? Can I rectify it and how?
Thanks in advance for any help.
**broken link removed**
**broken link removed**
I am playing with an LCD display for the first time and suspect that somehow its' character memory has been corrupted by yours truly.
Initially I had a go at getting the display working by myself but couldn't so then had a look at Nigels' tutorial (thanks Nigel - they really are useful for beginners like me). I modded the code a little; stripped out irrelevent bits and used 8 bit rather than 4 bit mode. However, now that it 'works' I see most of the characters are not as they should be; in the first pic it should display 'Hello / ready...' and in the second the whole alphabet capitalised.
Did I corrupt the character memory (CGRAM) when I first fiddled - is that possible? Can I rectify it and how?
Thanks in advance for any help.
**broken link removed**
**broken link removed**
Code:
;A project to drive a 16 x 2 LCD alphanumeric module (Powertip PC1602 from Rapid Electronics). 11 June 2009
;Most of this code is copied from Nigel Goodwins' tutorial. I've used 8 bit mode rather than 4 bit.
list p=16F690
#include <p16F690.inc>
errorlevel -302 ; suppress message 302 from list file
errorlevel -305
__config (_INTRC_OSC_NOCLKOUT &_WDT_OFF &_PWRTE_OFF &_CP_OFF &_BOR_OFF &_IESO_OFF &_FCMEN_OFF &_MCLRE_OFF)
INT_VAR UDATA 0x20
count RES 1
count1 RES 1
counta RES 1
countb RES 1
#define LCD_PORT PORTC
#define LCD_RS PORTB,4
#define LCD_E PORTB,5
org 0
;____________________________________________________________________________________________________________________
Start:
banksel ANSEL
clrf ANSELH
clrf ANSEL
banksel TRISA
clrf TRISA
clrf TRISB
clrf TRISC
banksel PORTA
clrf PORTA
clrf PORTB
clrf PORTC
;____________________________________________________________________________________________________________________
Main:
call Delay100 ;LCD settling time
call Initialise_LCD
clrf count ;set counter register to zero
Message
movf count,w ;put counter value in W
call Text ;get a character from the text table
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
goto NextMessage
call LCD_Char
call Delay255
incf count, f
goto Message
;____________________________________________________________________________________________________________________
NextMessage
call LCD_Line2 ;move to 2nd row, first column
clrf count ;set counter register to zero
Message2
movf count, w ;put counter value in W
call Text2 ;get a character from the text table
xorlw 0x00 ;is it a zero?
btfsc STATUS, Z
goto EndMessage
call LCD_Char
call Delay255
incf count, f
goto Message2
EndMessage
Stop
goto Stop ;endless loop
;____________________________________________________________________________________________________________________
Initialise_LCD
movlw b'00111100' ;8 bit mode / 2 lines / 5x11
call LCD_CMD
movlw b'00011100' ;display shift / right shift.
call LCD_CMD
movlw b'00000110' ;Character entry mode
call LCD_CMD
movlw b'00001111' ;display on / cursor off / cursor position on
call LCD_CMD
call LCD_Clr
retlw .0
;____________________________________________________________________________________________________________________
LCD_CMD
movwf PORTC
bcf LCD_RS
call Pulse_E
call Delay5
retlw .0
;____________________________________________________________________________________________________________________
LCD_Char
movwf LCD_PORT
bsf LCD_RS ;RS line to 1
call Pulse_E ;Pulse the E line high
call Delay5
retlw 0x00
;____________________________________________________________________________________________________________________
LCD_Line2
movlw 0xc0 ;move to 2nd row, first column
call LCD_CMD
retlw 0x00
LCD_Clr
movlw 0x01 ;Clear display
call LCD_CMD
retlw 0x00
;____________________________________________________________________________________________________________________
Delay255
movlw 0xff ;delay 255 mS
goto d0
Delay100
movlw d'100' ;delay 100mS
goto d0
Delay50
movlw d'50' ;delay 50mS
goto d0
Delay20
movlw d'20' ;delay 20mS
goto d0
Delay5
movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
;____________________________________________________________________________________________________________________
Pulse_E
bsf LCD_E
nop
bcf LCD_E
retlw .0
;____________________________________________________________________________________________________________________
Text
addwf PCL, f
retlw 'A';'H'
retlw 'B';'e'
retlw 'C';'l'
retlw 'D';'l'
retlw 'E';'o'
retlw 'F'
retlw 'G'
retlw 'H'
retlw 'I'
retlw 'J'
retlw 'K'
retlw 'L'
retlw 'M'
retlw 'N'
retlw 'O'
retlw 'P'
retlw 0x00
Text2
ADDWF PCL, f
RETLW 'R'
RETLW 'S';'e'
RETLW 'T';'a'
RETLW 'U';'d'
RETLW 'V';'y'
RETLW 'W';'.'
RETLW 'X';'.'
RETLW 'Y';'.'
retlw 'Z'
RETLW 0x00
end