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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/22/12 18:10
Read: times


 
#186818 - 4 Bit LCD
I need help interfacing an LCD With an 8051 in 4 bit mode. I have it working using P1.4 1.5 1,5 p1.7 but need to use p1.0-p1.3. any help would be much appreciated
...$MOD51	; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.



; Please insert your code here.

DB4     EQU   P1.4
 DB5     EQU   P1.5
 DB6     EQU   P1.6
 DB7     EQU   P1.7
 EN      EQU   P3.4
	 RS      EQU   P3.5
 RW      EQU   P3.6
 DATA1    EQU   P1



INIT_LCD:
 CLR   RS
 CLR   RW
 CLR   EN
 SETB  EN
 MOV   DATA1,#28h
 CLR   EN
 LCALL WAIT_LCD
 MOV   A,#28h
 LCALL WRITE_2_NIBBLES
 LCALL WAIT_LCD
 MOV   A,#0Eh
 LCALL WRITE_2_NIBBLES
 LCALL WAIT_LCD
 MOV   A,#06h
 LCALL WRITE_2_NIBBLES
 LCALL WAIT_LCD


		



          ;program////////////////////////////////////////////////////
main:  	

	     			
          LCALL CLEAR_LCD		;clearing lcd.
          MOV A,#'W'
          LCALL WRITE_TEXT
          MOV A,#'E'
          LCALL WRITE_TEXT
          MOV A,#'L'
          LCALL WRITE_TEXT		;sending welcome msg to lcd.
          MOV A,#'C'
          LCALL WRITE_TEXT
          MOV A,#'O'
          LCALL WRITE_TEXT
          MOV A,#'M'
          LCALL WRITE_TEXT
          MOV A,#'E'
           LCALL WRITE_TEXT
			 		;Calling delay.
		  jmp main
		

		


		


	
          ;////////////////////////////////////////////////////////////


WRITE_TEXT:
 SETB  RS
 LCALL WRITE_2_NIBBLES
 LCALL WAIT_LCD
 RET




WAIT_LCD: 	ret				;;  Something wrong with this sub
          CLR  EN            ;bring EN low after every instruction
          CLR  RS            ;It's a command
          SETB RW            ;it's a read command
        ;;  MOV  dta, #0FFH   ;Set all pins(P1) High initially
          SETB EN            ;Clock Out Command To LCD
        ;;  MOV  A, dta       ;Read the return value
        ;;  JB   ACC.7, WAIT_LCD     ;if bit 7 high, LCD Still busy
          CLR  EN            ;Finish the command
          CLR  RW            ;turn off RW for future commands
          RET                ;return



WRITE_2_NIBBLES:
 PUSH  ACC           ;Save A for low nibble
 ORL   DATA1,#0F0h    ;Bits 4..7 <- 1
 ORL   A,#0Fh        ;Don't affect bits 0-3
 ANL   DATA1,A        ;High nibble to display
 SETB  EN 
 CLR   EN 
 POP   ACC           ;Prepare to send
 SWAP  A             ;...second nibble
 ORL   DATA1,#0F0h    ; Bits 4...7 <- 1
 ORL   A,#0Fh       ; Don't affect bits 0...3
 ANL   DATA1,A        ;Low nibble to display
 SETB  EN 
 CLR   EN 
 RET

CLEAR_LCD:
 CLR   RS
 MOV   A,#01h
 LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
 LCALL WAIT_LCD
 RET

READ_2_NIBBLES:
 ORL   DATA1, #0F0h     ;Be sure to release datalines (set outputlatches 
                     ;to '1') so we can read the LCD
 SETB  EN
 MOV  A,DATA1 			;Read first part of the return value (high nibble)
 CLR   EN
 ANL  A,#0F0h         ;Only high nibble is usable
 PUSH  ACC
 SETB  EN
 MOV   A,DATA1       ;Read second part of the return value (low nibble)
 CLR   EN 
 ANL   A,#0F0h       ;Only high nibble is usable
 SWAP  A             ;Last received is actually low nibble, so put it in place
 MOV   R7,A 
 POP   ACC 
 ORL   A,R7          ;And combine it with low nibble
 RET



line1:		CLR   RS
 MOV   A,#80h
 LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
 LCALL WAIT_LCD
 RET


line2:	CLR   RS
 MOV   A,#0C0h
 LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
 LCALL WAIT_LCD
 
			ret









END
 



List of 13 messages in thread
TopicAuthorDate
4 Bit LCD            01/01/70 00:00      
   I am no sherlock Holmes, but ...            01/01/70 00:00      
      LCD            01/01/70 00:00      
         Did you think about accesses using DATA1?            01/01/70 00:00      
            lcd            01/01/70 00:00      
               So you found a solution ...            01/01/70 00:00      
                  LCD 4 BIT            01/01/70 00:00      
                     where did you get that idea?            01/01/70 00:00      
                        Using Read Cycle to LCD            01/01/70 00:00      
                           of course, you can not use a signal that is not there            01/01/70 00:00      
                        busy flad check            01/01/70 00:00      
                           Why not solve your problem BEFORE trying to save pins?            01/01/70 00:00      
                              Premature optimisation            01/01/70 00:00      

Back to Subject List