Some people do POR and the early steps for initialization and function setting by sending only 4 bits to the controller rather than two writes of 4-bits each . The controller defaults in 8-bit mode, so until the controller is in 4-bit mode, two, 4-bit sends might be interpreted as two instructions, not one. To protect against that, it seems that early on, the controller ignores the second write. Thus, you can send either a 4-bit nibble or the two nibbles as is done once in 4-bit mode. The question is, at what point does the 4-bit mode become active, so the user must do two writes of 4 bits each?
I think I found that step, but from reading the Hitachi comments, it was not clear to me until I knew the answer. Then, it was obvious (duh). There are 5 choices. Two are pretty obviously not right. Which one is it? BTW, this is really a question of understanding the DS for me. In reality, it seems you can use the 8-bit codes in 4-bit mode from the very start. You just have to be sure to start 4-bit mode at the right time.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; LCD Subroutines ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PutCmd
bcf RS ; RS = 0, 'command'
goto $+2 ;
PutDat
bsf RS ; RS = 1, 'data'
call PutNib ; clock out the hi nibble
PutNib ; fall thru for lo nibble
swapf WREG,W ; swap nibbles
movwf PORTB ; LCD D7..D4 = RB3..RB0
bsf E ;
bcf E ;
DelayCy (50*usecs) ;
return ;
That's curious. I never saw that in the datasheet. My comments about the controller starting up in 8-bit mode were based on the datasheet description of the power on reset sequence (see attached).To say that the device starts up in 8 bit mode may be a mistake, because according to the data sheet the first three commands are interpreted as 4 bit commands, not 8 bit, so the 4 upper bits are looked at and the 4 lower bits are ignored.
DelayCy (50*usecs) ;
A couple more comments:
I was looking at this line in your code:
Looks like a macro to me, and I was wondering if this is one that you wrote yourself, or if it's part of a library somewhere.Code:DelayCy (50*usecs) ;
cblock 0x70
delayhi ; DelayCy() sub-system timing variable
endc
;==================================================================
; K8LH DelayCy() subsystem macro generates four instructions =
;==================================================================
radix dec
clock equ 32 ; 4, 8, 12, 16, 20 (MHz), etc.
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ usecs*1000 ; cycles/millisecond multiplier
dloop equ 31 ; loop size, 5 to ??? cycles
;
; -- loop -- -- delay range -- -- memory overhead ----------
; 5-cyc loop, 11..327690 cycles, 9 words (+4 each macro call)
; 6-cyc loop, 11..393226 cycles, 10 words (+4 each macro call)
; 7-cyc loop, 11..458762 cycles, 11 words (+4 each macro call)
; 8-cyc loop, 11..524298 cycles, 12 words (+4 each macro call)
; 9-cyc loop, 11..589834 cycles, 13 words (+4 each macro call)
;
DelayCy macro cycles ; range, see above
if (cycles<11)|(cycles>(dloop*65536+10))
error " DelayCy range error "
else
movlw high((cycles-11)/dloop)+1
movwf delayhi
movlw low ((cycles-11)/dloop)
call uLoop-((cycles-11)%dloop)
endif
endm
;******************************************************************
; example code for simulation testing *
;******************************************************************
org 0x000
SimTest
DelayCy(200*msecs) ; <- put simulator PC here
goto $ ; <- put simulator break point here
;******************************************************************
; K8LH DelayCy() subsystem 16-bit 'uLoop' timing subroutine *
;******************************************************************
a = dloop-1
while a > 0
nop ; (cycles-11)%dloop entry points |B0
a -= 1
endw
uLoop addlw -1 ; subtract 'dloop' loop time |B0
skpc ; borrow? no, skip, else |B0
decfsz delayhi,F ; done? yes, skip, else |B0
goto uLoop-dloop+5 ; do another loop |B0
return ; |B0
;******************************************************************
end
My analysis suggests the display comes up in 8-bit mode automatically after its power-up reset. The Datasheet shows you can send a "function set" instruction immediately after the self reset that includes data in the lower (bit 3 & bit 2) data bits.I mentioned that calling the start up mode "8 bit" may not be the best idea because the LCD only sees 4 bits anyway.
Wouldn't that prevent you from sending "set DDRAM address" commands which require bit 7 (D7) = 1?... another trick is to use only 7 bits keeping the most significant bit low (or high as needed).
My analysis suggests the display comes up in 8-bit mode automatically after its power-up reset. The Datasheet shows you can send a "function set" instruction immediately after the self reset that includes data in the lower (bit 3 & bit 2) data bits.
Wouldn't that prevent you from sending "set DDRAM address" commands which require bit 7 (D7) = 1?
Do you mean that you found that you do not have to send the start up sequence for 8 bit mode too then, only for 4 bit mode?
If you mean evidence that the HD44780U comes up in 8-bit interface mode after power-up reset, I would refer you to this section of the Hitachi HD44780U (LCD-II) Datasheet.If you have evidence to the contrary please supply that information.
No, that's not what I said. Please re-read the post.
If you mean evidence that the HD44780U comes up in 8-bit interface mode after power-up reset, I would refer you to this section of the Hitachi HD44780U (LCD-II) Datasheet.
View attachment 95547
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?