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 12:10
Read: 1430 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      Sean O Mara      03/22/12 12:10      
   I am no sherlock Holmes, but ...      Erik Malund      03/22/12 13:31      
      LCD      Sean O Mara      03/22/12 13:56      
         Did you think about accesses using DATA1?      Per Westermark      03/22/12 15:41      
            lcd      Sean O Mara      03/22/12 17:18      
               So you found a solution ...      Andy Neil      03/22/12 18:02      
                  LCD 4 BIT      Sean O Mara      03/23/12 06:49      
                     where did you get that idea?      Erik Malund      03/23/12 06:57      
                        Using Read Cycle to LCD      Michael Karas      03/23/12 10:33      
                           of course, you can not use a signal that is not there      Erik Malund      03/23/12 10:45      
                        busy flad check      Sean O Mara      03/23/12 16:02      
                           Why not solve your problem BEFORE trying to save pins?        Richard Erlacher      03/24/12 08:16      
                              Premature optimisation      Andy Neil      03/24/12 09:48      

Back to Subject List