Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/28/12 13:32
Read: times


 
#186929 - Problem solved
Responding to: ???'s previous message
Thanks for the reply Jan.

Problem was in the assembly code (new to asem. I come for the C family of languages). I didn't realize that the code flows right into the subroutines - unlike functions.

Here's the revised code for future generations:


EN equ P3.3	
RW equ P3.4	
RS equ P3.5	
DAT equ P1	

lcall init_lcd		;initialize lcd
lcall clear_lcd
	
mov A, #'H'		;send text data to lcd
lcall write_lcd_text	
mov A, #'e'	
lcall write_lcd_text	
mov A, #'l'	
lcall write_lcd_text	
mov A, #'l'	
lcall write_lcd_text	
mov A, #'o'	
lcall write_lcd_text

wait_lcd:
	clr RS			;command
	setb RW		;read command
	setb EN		;start lcd command
	mov P1, #0FFh	
	mov A, P1	
	jb ACC.7, wait_lcd	;if bit 7 high, lcd still busy
	clr EN			;finish command
	clr RW			;turf off RW for future commands
ret	
	
lcd_command:
	clr RS			;low to indicate command
	clr RW			;low to indicate write
	mov DAT, A	
	setb EN		;high to initiate command

	mov R0, #30h	
	loop:			;loops 48 times instead of 4
		nop			; to compensate for the Dallas' speed
		djnz R0, loop	

	clr EN
	lcall wait_lcd		;wait for command to execute
ret	

init_lcd:	
	mov A, #38h		;8-bit data bus, 5x8 font
	lcall lcd_command	
	mov A, #0Eh		;turn on lcd, turn on cursor
	lcall lcd_command	
	mov A, #06h		;turn on cursor auto advance
	lcall lcd_command	
ret	
	
clear_lcd:	
	mov A, #01h	
	lcall lcd_command	
ret
	
write_lcd_text:	
	setb RS		;RS high to indicate text
	clr RW			;RW low to indiacte write
	mov DAT, A	
	setb EN		;high to initiate command

	mov R0, #30h
	loop2:			;loops 48 times instead of 4
		nop			; to compensate for the Dallas' speed
		djnz R0, loop2	

	clr EN	
	lcall wait_lcd		;wait for command to execute
ret

end	



 



List of 4 messages in thread
TopicAuthorDate
Tutorial/Book question about 8052/LCD            01/01/70 00:00      
   reset?            01/01/70 00:00      
   Problem solved            01/01/70 00:00      
      did you            01/01/70 00:00      

Back to Subject List