+ Reply to Thread
Results 1 to 9 of 9

Thread: 2 wire LCD with a 74hc164 shift register

  1. #1
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    1,993

    2 wire LCD with a 74hc164 shift register

    I been trying to change this to work on a 16f684 using a 74hc164 for the shift register. With no luck I was using some code that Myke Predko wrote in a book i have 123 pic microcontorller experiments.
    I think the delays are not working right or it's FSR It's driving me crazy.
    Code:
    	list		p=16f684		; list directive to define processor
    	#include	<P16F684.inc>		; processor specific variable definitions
    	
    	__CONFIG    _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _FCMEN_OFF & _IESO_OFF
    
    	cblock 		0x020
    	Dlay                           ;  8 Bit Delay Variable
    	Temp				;  Temporary Value Used When Sending Out Data
    	NOTemp				;  Temporary Value to "NybbleOutput"
    	endc
    #define	Data  PORTC,0
    #define	Clock PORTC,1
    	;  Macros
    ClockStrobe MACRO		;  Strobe the Data Bit
      	bsf	 Clock
      	bcf	 Clock
     	ENDM
    
    EStrobe MACRO			;  Strobe the "E" Bit
      	bsf	 Data
     	bcf	 Data
     	ENDM
    
    
    
    
    
    	ORG			0x000		; processor reset vector
      	goto		init		; go to beginning of program
    
    
    	ORG			0x004	    ; interrupt vector location
    
    init:
    	banksel		PORTC
    	clrf		PORTC
    	movlw		07h
    	movwf		CMCON0
    	banksel		ANSEL
    	clrf		ANSEL
    	banksel		TRISC
    	movlw		b'00000000'
    	movwf		TRISC
    	banksel		PORTC	
    	movlw		b'00000000'
    	movwf		PORTC
    	goto 		Set_LCD
    Set_LCD:
    	
      	call   		Dlay5                  ;  Wait 20 msecs before Reset
      	call  		Dlay5
      	call   		Dlay5
      	call   		Dlay5
    
      	bcf    		STATUS, C              ;  Clear Carry (Instruction Out)
      	movlw  		0x03                   ;  Reset Command
      	call   		NybbleOut              ;  Send the Nybble
      	call	 	Dlay5			;  Wait 5 msecs before Sending Again
    
      	EStrobe
      	call	 	Dlay160		;  Wait 160 usecs before Sending the Third Time
    
      	EStrobe
      	call	 	Dlay160		;  Wait 160 usecs before Sending the Third Time
    
      	bcf    		STATUS, C              
      	movlw  		0x02                   ;  Set 4 Bit Mode
     	call   		NybbleOut              
     	call	 	Dlay160		
    
      	movlw	 	0x028			;  Note that it is a 2 Line Display
      	call	 	SendINS
    
      	movlw	 	0x008			;  Turn off the Display
     	call	 	SendINS
    
      	movlw	 	0x001			;  Clear the Display RAM
      	call	 	SendINS
      	call	 	Dlay5			;  Note, Can take up to 4.1 msecs
    
      	movlw	 	0x006			;  Enable Cursor Move Direction
      	call	 	SendINS
    
      	movlw	 	0x00C			;  Turn the LCD Back On
      	call	 	SendINS
    
      	clrf	 	FSR			;  Output the Message
    OutLoop
      	movf	 	FSR, w			;  Get the Offset to Output
      	incf	 	FSR
      	call	 	Message
      	iorlw		 0			;  At the End of the Message?
      	btfsc	 	STATUS, Z
       	goto	 	Loop			;  Yes - Equal to Zero
      	call	 	SendCHAR		;  Output the ASCII Character
      	goto	 	OutLoop
    
    Loop				;  Loop Forever when Done
      	goto   		Loop
    
    
    ;  Subroutines
    Message				;  Message to Output
      	addwf	 	PCL			;  Output the Characters
      	dt	 		"Hello", 0
    
    SendCHAR			;  Send the Character to the LCD
      	movwf	 	Temp			;  Save the Temporary Value
    
      	swapf	 	Temp, w		;  Send the High Nybble
      	bsf	 		STATUS, C		;  RS = 1
      	call		NybbleOut
    
      	movf	 	Temp, w		;  Send the Low Nybble
      	bsf	 		STATUS, C
      	call	 	NybbleOut
    
      	return
    
    SendINS				;  Send the Instruction to the LCD
      	movwf	 	Temp			;  Save the Temporary Value
    
      	swapf	 	Temp, w		;  Send the High Nybble
      	bcf	 		STATUS, C		;  RS = 0
      	call	 	NybbleOut
    
      	movf	 	Temp, w		;  Send the Low Nybble
      	bcf	 		STATUS, C
      	call	 	NybbleOut
    
      	return
    
    NybbleOut                ; Send a Nybble to the LCD
         movwf     NOTemp    ; Save the Nybble to Shift Out
         swapf     NOTemp    ; Setup to Output to the High Part of the Byte
         movlw     6         ; Clear the Shift Register
         movwf     Dlay
    
    NO2Loop1
         ClockStrobe
         decfsz    Dlay
         goto      NO2Loop1
         movlw     5          ; #### - Now, Shift out the Data with the "RS" Bit
         movwf     Dlay
         bsf       Data       ; Put out the Gate Bit
         ClockStrobe
    
    NO2Loop2
         bcf       Data       ; #### - Clear the Data Bit (which is the Clock)
         btfsc     STATUS, C  ; #### - If the Bit to be output is a "1", Shift it Out
         bsf       Data               
         ClockStrobe
         rlf       NOTemp     ; #### - Shift the Next Bit into the Carry Flag
         decfsz    Dlay
         goto      NO2Loop2
    
         EStrobe              ; Strobe out the LCD Data
    
         return
    
    Dlay160                         ;  Delay 160 usecs
    
      	movlw  		256 - ( 160 / 4 )      ;  Loop Until Carry Set
      	addlw  		1
      	btfss  		STATUS, C
       	goto  		$-2
    
      	return
    
    Dlay5                           ;  Delay 5 msecs
    
      	movlw  		4                      ;  Set up the Delay
      	movwf  		Dlay
      	movlw  		256 - 0x0E8
      	addlw  		1
      	btfsc  		STATUS, Z
       	decfsz		Dlay
        goto	 	$-3
    
      	return
    
    
      end
    
    Thanks for any help


    See i get this when I build the line it points to is the delay
    Warning[202] C:\2WIRE\2WIRE1.ASM 163 : Argument out of range. Least significant bits used.
    Warning[202] C:\2WIRE\2WIRE1.ASM 174 : Argument out of range. Least significant bits used.
    Oh one more thing the lcd comes on and rolls out 8 squares
    Attached Images
    Last edited by be80be; 8th July 2009 at 10:28 PM.
    Burt


  2. #2
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,584

    Oh man i wish this was in C lol if it was i would be able to help more.

    1 question.... can you test the shift registers output to ensure the pins are shifting.


    It seems to be a delay issue tho. Try creating your own delays and see what happens.

    Why use: 256 - ( 160 / 4 )
    why not just use:

    216

    also why: 256 - 0x0E8
    why 0x0E8 ? its the same as 0xE8 and in fact just use:

    24

    try it with those stable values and see if it helps

  3. #3
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    1,993

    I found one for sure error I missed a pin on the 74hc164.
    That sure didn't help.
    I'm going to fix that first
    Burt

  4. #4
    skyhawk Excellent skyhawk Excellent skyhawk Excellent skyhawk Excellent
    Join Date
    Feb 2007
    Location
    Morgantown, WV
    Posts
    192

    What is your default number base?

  5. #5
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    1,993

    I had changed the delay It was where I missed the wire LOL it's alive
    Attached Images
    Burt

  6. #6
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    1,993

    Quote Originally Posted by skyhawk View Post
    What is your default number base?
    six I think It works now
    Atom your delay numbers was closer then mine thanks
    Last edited by be80be; 8th July 2009 at 11:01 PM.
    Burt

  7. #7
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,584

    yay i was almost right close enough lol

  8. #8
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    1,993

    What happen is I missed Q4 on the 74hc and put RS on Q5. That's why i want to start using PCB for my boards. To many jumper for things like this.
    Your delay numbers worked the code as posted worked and the delays i got from here work Microchip PIC, ASM Delay Code, Code Generator
    Burt

  9. #9
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    1,993

    Atom I'm going to try to write the same thing in microC
    Burt

+ Reply to Thread

Similar Threads

  1. 74HC164 Shift Register Doubt
    By Gayan Soyza in forum Micro Controllers
    Replies: 15
    Latest: 18th February 2009, 03:54 AM
  2. Shift register
    By mstechca in forum General Electronics Chat
    Replies: 1
    Latest: 19th December 2005, 12:45 AM
  3. EDO RAM as Shift Register
    By aurosunil in forum General Electronics Chat
    Replies: 0
    Latest: 17th August 2004, 10:25 AM
  4. Using Shift Register
    By toyracer in forum Electronic Projects Design/Ideas/Reviews
    Replies: 5
    Latest: 13th November 2003, 02:19 PM

Tags for this Thread