pic 16f628 and ks0070B LCD

Status
Not open for further replies.
Hi gang,

If at all possible I'd like to avoid a discussion about the merits or shortcomings of popular tutorial software. Instead I'd like to suggest studying the LCD libraries in some high level languages like BoostC and Swordfish BASIC to see what they use for a "bullet proof" initialization procedure for 4-bit interface mode and then decide for yourself.

Here's a quick pseudo code summary;

Code:
Swordfish BASIC LCD 4-bit initialization procedure

1) delay 100-msecs
2) write 4-bit nibble '0011' to LCD
3) delay 5-msecs
4) write 4-bit nibble '0011' to LCD
5) delay 160-usecs
6) write 4-bit nibble '0011' to LCD
7) delay 160-usecs
8) write 4-bit nibble '0010' to LCD   ' set 4-bit interface mode
9) delay 160-usecs                    ' now configure display
Code:
BoostC LCD 4-bit initialization procedure

1) delay 15-msecs
2) write 4-bit nibble '0011' to LCD
3) delay 5-msecs
4) write 4-bit nibble '0011' to LCD
5) delay 150-usecs
6) write 4-bit nibble '0011' to LCD
7) delay 5-msecs
8) write 4-bit nibble '0010' to LCD   ' set 4-bit interface mode
9) delay 150-usecs                    ' now configure display
Code:
K8LH Assembler LCD 4-bit initialization procedure

1) delay 30-msecs
2) write 4-bit nibble '0011' to LCD
3) delay 5-msecs
4) write 4-bit nibble '0011' to LCD
5) delay 160-usecs
6) write 4-bit nibble '0011' to LCD
7) delay 160-usecs
8) write 4-bit nibble '0010' to LCD   ' set 4-bit interface mode
9) delay 160-usecs                    ' now configure display
Code:
A Popular Tutorial Assembler LCD 4-bit initialization procedure

1) delay 100-msecs
2) write 4-bit nibble '0010' to LCD   ' set 4-bit interface mode (?)
3) write 4-bit nibble '0000' to LCD   ' ???
4) delay 5-msecs                      ' now configure display
 
Last edited:
I'd still like to know where this has suddenly come from, using multiple instances of an undocumented instruction, not mentioned in any datasheet I've ever seen.

Obviously it's absolutely trivial to add, but is it needed? (not in my experience with many displays), and if it is needed why isn't it mentioned anywhere? - does anyone have a link to a datasheet that includes it? (and thanks very much if you do).
 
The attached data sheet from RS components has it on page 7. I always use this sequence and so am not aware of any LCDs that fail if it's not used.

Mike.
 
The attached data sheet from RS components has it on page 7. I always use this sequence and so am not aware of any LCDs that fail if it's not used.

Mike.

hi Mike,
I cannot get the linked pdf to download.???
 
That's weird, if you do save as the filename is clear.gif!!

I said the attachment stuff was broken.

Here's the relevant part.

Mike.
 

Attachments

  • LCD..png
    27.7 KB · Views: 211
That's weird, if you do save as the filename is clear.gif!!

I said the attachment stuff was broken.

Here's the relevant part.

Mike.

hi Mike,
Thanks, the link name you posted has a Chinese looking character as part of the name.??

That data you posted is the same as the original Hitachi doc which I got about 20 years ago.

As I was manufacturing commercial products using these LCD's I had to be sure if the user replaced a faulty LCD, the new one would work, so I always used a software init.

There was/is a big difference in the response of these LCD's

Regards
 
I think im finaly starting to understand - thanks guys

But I have one question,
reading the data sheet that shows how the initilization is done how does it differ from the code in nigels example? Isnt that what he is doing in the LCD_Init routine

Eric, what part do you suggest may be added for better results?


Thanks
Charlie
 
I

Eric, what part do you suggest may be added for better results?


Thanks
Charlie

hi Charlie,
I would add the initialising routine as per the datasheet.

If you post your working/latest code listing, we can show you how.
 
Eric
Here is the code that I have been using.

As you can see the LCD is being initialised.

If you could show me how it is different from the datasheet and how to correct it I would most appreciated.

Your data sheet shows 8 bit mode, i am trying to controll this in 4 bit mode.
Thanks
Charlie


LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)




cblock 0x20 ;start of general purpose registers
count ;used in looping routines
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
tmp1 ;temporary storage
tmp2
templcd ;temp store for 4 bit mode
templcd2
endc

LCD_PORT Equ PORTA
LCD_TRIS Equ TRISA
LCD_RS Equ 0x04 ;LCD handshake lines
LCD_RW Equ 0x06
LCD_E Equ 0x07

org 0x0000

movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)

Initialise clrf count
clrf PORTA
clrf PORTB



SetPorts bsf STATUS, RP0 ;select bank 1
movlw 0x00 ;make all pins outputs
movwf LCD_TRIS
bcf STATUS, RP0 ;select bank 0

call Delay100 ;wait for LCD to settle


call LCD_Init ;setup 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
incf count, f
goto Message2

EndMessage

Stop goto Stop ;endless loop




;Subroutines and text tables

;LCD routines

;Initialise LCD
LCD_Init movlw 0x20 ;Set 4 bit mode
call LCD_Cmd

movlw 0x28 ;Set display shift
call LCD_Cmd

movlw 0x06 ;Set display character mode
call LCD_Cmd

movlw 0x0d ;Set display on/off and cursor command
call LCD_Cmd

call LCD_Clr ;clear display

retlw 0x00

; command set routine
LCD_Cmd movwf templcd
swapf templcd, w ;send upper nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bcf LCD_PORT, LCD_RS ;RS line to 0
call Pulse_e ;Pulse the E line high

movf templcd, w ;send lower nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bcf LCD_PORT, LCD_RS ;RS line to 0
call Pulse_e ;Pulse the E line high
call Delay5
retlw 0x00

LCD_CharD addlw 0x30
LCD_Char movwf templcd
swapf templcd, w ;send upper nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bsf LCD_PORT, LCD_RS ;RS line to 1
call Pulse_e ;Pulse the E line high

movf templcd, w ;send lower nibble
andlw 0x0f ;clear upper 4 bits of W
movwf LCD_PORT
bsf LCD_PORT, LCD_RS ;RS line to 1
call Pulse_e ;Pulse the E line high
call Delay5
retlw 0x00

LCD_Line1 movlw 0x80 ;move to 1st row, first column
call LCD_Cmd
retlw 0x00

LCD_Line2 movlw 0xc0 ;move to 2nd row, first column
call LCD_Cmd
retlw 0x00

LCD_Line1W addlw 0x80 ;move to 1st row, column W
call LCD_Cmd
retlw 0x00

LCD_Line2W addlw 0xc0 ;move to 2nd row, column W
call LCD_Cmd
retlw 0x00

LCD_CurOn movlw 0x0d ;Set display on/off and cursor command
call LCD_Cmd
retlw 0x00

LCD_CurOff movlw 0x0c ;Set display on/off and cursor command
call LCD_Cmd
retlw 0x00

LCD_Clr movlw 0x01 ;Clear display
call LCD_Cmd
retlw 0x00

LCD_HEX movwf tmp1
swapf tmp1, w
andlw 0x0f
call HEX_Table
call LCD_Char
movf tmp1, w
andlw 0x0f
call HEX_Table
call LCD_Char
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_PORT, LCD_E
nop
bcf LCD_PORT, LCD_E
retlw 0x00

;end of LCD routines

HEX_Table ADDWF PCL , f
RETLW 0x30
RETLW 0x31
RETLW 0x32
RETLW 0x33
RETLW 0x34
RETLW 0x35
RETLW 0x36
RETLW 0x37
RETLW 0x38
RETLW 0x39
RETLW 0x41
RETLW 0x42
RETLW 0x43
RETLW 0x44
RETLW 0x45
RETLW 0x46


Text addwf PCL, f
retlw 'H'
retlw 'e'
retlw 'l'
retlw 'l'
retlw 'o'
retlw 0x00

Text2 ADDWF PCL, f
RETLW 'R'
RETLW 'e'
RETLW 'a'
RETLW 'd'
RETLW 'y'
RETLW '.'
RETLW '.'
RETLW '.'
RETLW 0x00


end
 

Tks, I was having random LCD startup errors with my code until I added delays and setup the LCD controller twice. BZ

Bravo Zulu - Wikipedia, the free encyclopedia
 
Just curious is anyone else has a problem compiling the program listing I attached in post #11?

hi Mike,
The OP is sending me the actual hardware, he lives in the next county.

We will update the thread when I have debugged the project.
 
All

I have found the problem that I was experienceing.

Allthough the pic and LCD were wired correctly i found by connecting all the output pins to LED's and implementing a simple on off programme that 1 pin was stuck staying high, in fact this was the case on both the pics I had! DOH!

Needless to say i just threw another pic in place, put nigels original software in and of she went!!

Thanks for your help.

Hugely appreciated.
 
Allthough the pic and LCD were wired correctly i found by connecting all the output pins to LED's and implementing a simple on off programme that 1 pin was stuck staying high, in fact this was the case on both the pics I had! DOH!

My concern here is what have you done to the PIC's?, they are extremely hardy devices, I've never managed to kill one in all my years playing with them. And to kill two, in exactly the same way, looks like you've done something particularly nasty (twice!)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…