Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

74HC164 Shift Register Doubt

Status
Not open for further replies.

Gayan Soyza

Active Member
I have been fine tuning my 5(columns) X 7(rows) matrix system using 74HC164.
But still I'm not getting a smooth display result.I'm doubt with the "Clock_Pulse" routine.

Code:
Do_Show		call	Reset		;reset 74HC
		bsf	Data		;make 74HC data pin high for the first time
		movf	Col1,W
		call	Clock_Pulse
		bcf	Data		;make 74HC data pin low 
		movf	Col2,W
		call	Clock_Pulse
		movf	Col3,W
		call	Clock_Pulse
		movf	Col4,W
		call	Clock_Pulse
		movf	Col5,W
		call	Clock_Pulse
		goto	Do_Show	


Clock_Pulse	movwf	Col_Data	;get the column data
		clrf	PORTB						
		bsf	Clock		;low to high transition
		bcf	Clock		;make low for next transition
		movf	Col_Data,W
		movwf	PORTB														
		return
 
add a single nop between bsf and bcf
Code:
..
		bsf	Clock		;low to high transition
                nop                          ;give shift register time to act
		bcf	Clock		;make low for next transition
...
depending on the clock of your uC and the type of the shift register you might add more then one nop (note that HC is few times slower then HCT especially if you are running it on 3V - if you are using 5V rails only - use HCT .. much faster)
 
Hi arhi thanks for you help.

Crystal is 4Mhz.Supply is 5V.
The letter is displaying but I can see an additional column.Also I can see the off state LEDs also lights very dimly.

I have put an 4.7K pullup resister to the reset pin of 74HC.I think that also better if I can remove and connect that reset pin to direct to PIC.
 
the HC is fast enough for what you need but in general, HCT is faster :) not that it would make many difference .. you need that nop for the clock ...

now, that's what you need to change in the pulse sub ... as for the whole code .. it looks ok ... try with the nop and say if it is ok now
 
Earlier I did my Reset routine like this with tristate condition.

Code:
Reset		bsf	STATUS,RP0
		bcf	TRISA,2		;make RA2 output
		bcf	STATUS,RP0
		;
		bcf	PORTA,2		;reset pulse
		nop			;//
		nop			;//
		bsf	STATUS,RP0
		bsf	TRISA,2		;;make RA2 input
		bcf	STATUS,RP0
		return

After calling this "Reset" Routine that 4.7K pullup resister will hold the reset pin of 74HC high.I don't know why I did like that stupid.
 
Last edited:
IIRC reset pin is active low, so if you push up with 10K (or 4.7K, I prefere 10K) and do what you did it should work ... but .. why would you do it ? if you are reserving a pin for reset pin, you do not need to pull-up .. just connect to pic, bcf reset; nop, nop, bsf reset ... and go forward :)
 
I found what I used to get mine to work
Code:
Dataout macro Var,Var1
	Local 	Loop
	movlw	.8
	movwf	Var1
Loop  rlf	Var,f
	btfss	STATUS,C
	bcf	Data
	btfsc	STATUS,C
	bsf	Data
	bsf	Clock
	nop
	nop
	nop
	nop
	bcf	Clock
	decfsz 	Var1,f
	goto	Loop
	endm
which it the same s arhi I added some nop to get a good clock
 
I have change my shift registers 74hc595n it has a latch thay work alot better and only 19cents each
 
here this shows better the macro sends the data out and this shows how it is loaded
Code:
Main					;main program

	movlw	0x07
	movwf	CMCON			;turn comparators off (make it like a 16F84)
	banksel TRISA
	movlw	b'00011000'		;initializing porta
	movwf	TRISA
	banksel	PORTA
	clrf 	PORTA
Send
	movlw 	b'00000001'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto	Send1
Send1
	movlw 	b'00000010'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto	Send2
Send2
	movlw 	b'00000100'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto	Send3
Send3
	movlw 	b'00001000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto Send4
Send4
	movlw 	b'00010000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto Send5
Send5
	movlw 	b'00010000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto	Send6
Send6
	movlw 	b'00100000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto	Send7
Send7
	movlw 	b'01000000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto Send8
Send8
	movlw 	b'10000000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	goto Send		
Loop
 
Last edited:
Hi Arhi I solved my clock pulse routine.You must waste cycles after clearing the PORTB.
Also I added that nop as well :)
Code:
;**********************************
;Clock pulse routine to SR-74HC164
;**********************************

Clock_Pulse	movwf	Col_Data	;save column data
		clrf	PORTB
		goto	$+1
		goto	$+1
		goto	$+1
		goto	$+1
		goto	$+1												
		bsf	PORTA,0		;low to high transition
		nop				
		bcf	PORTA,0		;make low for next transition
		nop
		movf	Col_Data,W
		movwf	PORTB	
		goto	$+1
		goto	$+1
		return
 
Last edited:
I though you may want to look at the whole code you just remove the Latch part for 74hc164 it takes 3 pins with a 74hc595 so it still worked good with my 12f683
Code:
 #include <p12f683.inc>			; Include pre-defined port/reg labels
	errorlevel  -302          ; suppress message 302 from list file
 __CONFIG   _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT 									
		

	cblock 0x20
	TX           					; Define variable at address 0x20 of
	CountSPI 
	d1
	d2
	endc							; General Purpose Register (GPR) memory.
	
	#define  Data GPIO,0
	#define	 Clock GPIO,1
	#define	 Latch GPIO,2

	org 0x0000						; Processor Reset Vector (code starts here on reset)

	goto Main					; On power-up, begin at label "Main:"

	org 0x0004						; Interrupt Vector (code jumps here on interrupt)
	goto Main							; Applies to midrange parts!

	include "hc595."
	

Main:

	movlw 	07h	 ;set GP<2:0> to
	movfw   CMCON0	 ;digital I/O
	banksel ANSEL;
	clrf	ANSEL;digtal I/O
	banksel TRISIO
	movlw	b'011000'  ;set inputs and outputs
	movwf 	TRISIO ;moves it to TRIS 				; Initialize any ports as inputs/outputs, etc. here
	banksel GPIO
	clrf    GPIO
Loop:
Send
	movlw 	b'00000001'			;fill tx buffer
	movwf	TX
	HC595 TX,CountSPI
	call    delay
	goto	Send1
Send1
	movlw 	b'00000010'			;fill tx buffer
	movwf	TX
	HC595   TX,CountSPI
	call    delay
	goto	Send2
Send2
	movlw 	b'00000100'			;fill tx buffer
	movwf	TX
	HC595   TX,CountSPI
	call    delay
	goto	Send3
Send3
	movlw 	b'00001000'			;fill tx buffer
	movwf	TX
	HC595   TX,CountSPI
	call    delay
	goto    Send4
Send4
	movlw 	b'00010000'			;fill tx buffer
	movwf	TX
	HC595   TX,CountSPI
	call    delay
	goto    Send5
Send5
	movlw 	b'00100000'			;fill tx buffer
	movwf	TX
	HC595   TX,CountSPI
	call    delay
	goto	Send6
Send6
	movlw 	b'01000000'			;fill tx buffer
	movwf	TX
	HC595   TX,CountSPI
	call    delay
	goto	Send7
Send7
	movlw 	b'10000000'			;fill tx buffer
	movwf	TX
	HC595   TX,CountSPI
	call    delay
	goto    Send								; Place Application Code Here.
	goto Loop
delay:
			;149998 cycles
	movlw	0x2F
	movwf	d1
	movlw	0x76
	movwf	d2
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_0

			;2 cycles
	goto	$+1

	return

	end							; Program code stops here
and the macro that I used
Code:
HC595 macro Var,Var1
	
	Local 	Loop		;label
	movlw	.8		;eight bits to send
	movwf	Var1		
Loop
	rlf		Var,f		;rotate Var to the left

	btfss 	STATUS,C	;carry = 1 ?
	bcf		Data		;if not set line to 0
	btfsc	STATUS,C	;is carry = 0 ?
	bsf		Data		;if not set, set data line to 1

	bsf		Clock		; generate 1 clock
	nop
	bcf		Clock
	
	decfsz	Var1,f		;bits been sent ?
	goto	Loop		;if not repeat
	
	bsf     Latch
	nop
	bcf		Latch

	endm
this is just the part for the shifting it works like butter.
 
Status
Not open for further replies.

Latest threads

Back
Top