Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 8th July 2009, 08:29 PM   #1
Default 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
Quote:
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 Thumbnails
2 wire LCD with a 74hc164 shift register-lcdshift.png  

Last edited by be80be; 8th July 2009 at 10:28 PM.
be80be is offline  
Old 8th July 2009, 10:00 PM   #2
Default

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
AtomSoft is online now  
Old 8th July 2009, 10:32 PM   #3
Default

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
be80be is offline  
Old 8th July 2009, 10:40 PM   #4
Default

What is your default number base?
skyhawk is offline  
Old 8th July 2009, 10:57 PM   #5
Default

I had changed the delay It was where I missed the wire LOL it's alive
Attached Thumbnails
2 wire LCD with a 74hc164 shift register-lcdshift.jpg  
be80be is offline  
Old 8th July 2009, 11:00 PM   #6
Default

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.
be80be is offline  
Old 9th July 2009, 12:50 AM   #7
Default

yay i was almost right close enough lol
AtomSoft is online now  
Old 9th July 2009, 01:03 AM   #8
Default

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
be80be is offline  
Old 9th July 2009, 03:10 AM   #9
Default

Atom I'm going to try to write the same thing in microC
be80be is offline  
Reply

Tags
74hc164, lcd, register, shift, wire

Thread Tools
Display Modes


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



All times are GMT. The time now is 04:07 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker