# Shifting(74LS164) is not working!!

Status
Not open for further replies.

#### MessUpMymind

##### New Member
HI there,

I am currently working on LED dot matrix display by using 16F877A and 74LS164 shift register to shift the data that out from 877A..I face a few problem while doing the shifting..

1) LED Dot Matrix only keep showing the first data that i sent in but the following data doesn't not show up on the display.
2)First data that i sent in , light on all the time and there's no shifting that can be seen on the matrix display.

Code:
#include "P16f877a.inc"
__CONFIG 0x399A

cblock 0x20
d1
d2
d3
endc

shift_count	equ	.5

ORG	0x00
BSF	STATUS,5   ; set bit 5 of STATUS to change to bank 1
BANKSEL TRISD
BANKSEL	TRISC
MOVLW	0x00	   ; clear TRISB to change PORTB as output
MOVWF	TRISD
MOVLW	0x00	   ; clear TRISD to change PORTC as output
MOVWF	TRISC
BCF	STATUS,5
BANKSEL	PORTD
BANKSEL	PORTC
clrf	PORTD
clrf	PORTC
BCF	PORTC,2   ; set shift register clear pin
BSF	PORTC,2	   ; clear shift register clear pin

MOVLW  0A8h
MOVWF  11h

MOVLW  80h
MOVWF  12h

MOVLW  23h
MOVWF  13h

MOVLW  55h
MOVWF  14h

MOVLW  00h
MOVWF  15h

Shift1:	BSF		PORTC,1      ;74LS164 data pin set to high
MOVF 	11h,0		 ;first data 0A8h come in
MOVWF	PORTD	     ; move data to output PORTD
CALL	CLK	         ; call clock to move the data to collumns
BCF		PORTC,1		 ;74LS164 data pin set to low
CLRF	PORTD		 ;clear the first data (0A8h)
CALL	Delay		 ;call delay
DECFSZ	shift_count,1 ; Shift for 5 times and jump to second data
GOTO	Shift1        ;if not continue count
GOTO	Shift2

Shift2:	MOVF	12h,0         ;second data 80h
MOVWF	PORTD         ;move data to output PORTD
BCF		PORTC,1
CALL	CLK
CLRF	PORTD
CALL	Delay
DECFSZ	shift_count,1
GOTO	Shift2
GOTO	Shift3

Shift3:	MOVF 	13h,0
MOVWF	PORTD
CALL	CLK
CLRF	PORTD
CALL	Delay
DECFSZ	shift_count,1
GOTO	Shift3
GOTO	Shift4

Shift4:	MOVF 	14h,0
MOVWF	PORTD
CALL	CLK
CLRF	PORTD
CALL	Delay
DECFSZ	shift_count,1
GOTO	Shift4
GOTO	Shift5

Shift5:	MOVF 	15h,0
MOVWF	PORTD
CALL	CLK
CLRF	PORTD
GOTO	Delay
DECFSZ	shift_count,1
GOTO	Shift5
GOTO	Shift1

Delay:
;499994 cycles
movlw	0x03
movwf	d1
movlw	0x18
movwf	d2
movlw	0x02
movwf	d3
Delay_0:
decfsz	d1, f
goto	$+2 decfsz d2, f goto$+2
decfsz	d3, f
goto	Delay_0

;2 cycles
goto	\$+1

;4 cycles (including call)
return

CLK:	BCF	PORTC,0 ;send in clock pulse
BSF	PORTC,0 ;at PORTC, pin 0
call Delay	;Call Delay to make the character viewable.
return

END
The above is the code that i put into the micro-controller , i compile with MPLAB and it doesn't show any error occur..
can any1 please give me a way how to correct it , any suggestion is most welcome ??

#### Pommie

##### Well-Known Member
You don't appear to be shifting your data out of the data pin (C.1).

Try something like,
Code:
		movlw	8		;output 8 bits
movwf	shift_count	;store in counter
Shift1		bsf	PORTC,1		;74LS164 data pin set to high
btfss	11h,0		;is bit 0 clear
bcf	PORTC,1		;yes so clear data bit
call	CLK		; call clock to move the data to collumns
call	Delay		;call delay
rrf	11h,f		;move next bit to position 0
decfsz	shift_count,f	; Shift for 5 times and jump to second data
goto	Shift1		;if not continue count
goto	Shift2
Mike.

#### MessUpMymind

##### New Member
Thanks pommie for your reply , i will try it now and get back to you how is the progress.

Regards
TK

#### MessUpMymind

##### New Member
Hi,

sorry pommie , i am lack of experience .. where should i insert the data to PORTD for the the code that you posted previously.

Shift1 bsf PORTC,1 ;74LS164 data pin set to high
btfss 11h,0 ;is bit 0 clear
bcf PORTC,1 ;yes so clear data bit
call CLK ; call clock to move the data to collumns
call Delay ;call delay
rrf 11h,f ;move next bit to position 0
decfsz shift_count,f ; Shift for 5 times and jump to second data
goto Shift1 ;if not continue count
goto Shift2
For eg.

1)In the location register of 11h the data is 0A8h
2)Next i should put the data of 0A8h into PORTD so those 8 bit data can display on the matrix display , so that data will be shifted.

#### Pommie

##### Well-Known Member
If you want the value displayed on PortD then do,
Code:
		movlw	8		;output 8 bits
movwf	shift_count	;store in counter
[COLOR="Red"]movfw	11h		;get data
movwf	PORTD		;Place on PortD[/COLOR]
Shift1		bsf	PORTC,1		;74LS164 data pin set to high
btfss	11h,0		;is bit 0 clear
bcf	PORTC,1		;yes so clear data bit
call	CLK		; call clock to move the data to collumns
call	Delay		;call delay
rrf	11h,f		;move next bit to position 0
decfsz	shift_count,f	; Shift for 5 times and jump to second data
goto	Shift1		;if not continue count
goto	Shift2
However, the data shifted out will only match portD after the 8 shifts and 8 delays have taken place.

Mike.

#### MessUpMymind

##### New Member
Thanks mike i am getting clearer picture now , i have tested out the code that you suggested but yet the display only show up first 8 bits of data...and it didnt show shifting effect too.

more than that , i am curious why did you shift the data at PIN C,1 which is the data pin of 74LS164 .

Regards
TK

#### MessUpMymind

##### New Member
would it be my delay routine that actually didnt slow down the clock pulse that sending to 74LS164 and result in the display keep in static mode.

#### MessUpMymind

##### New Member
sorry i forget to mention my crystal is running at 4Mhz

#### MessUpMymind

##### New Member
I think i should make it clearer , this is how i connect my hardware part.

Note that i didnt connect ULN2803 in my board currently , because i have enuff current to run my 5x5 board.

#### colin55

##### Well-Known Member
It would be simpler to use a 4017 and arrange the display as 8x5 so you only need a "run of five."

The coding has already been done in the 5x7 Display on talkingelectronics.com website.

#### MessUpMymind

##### New Member
Hi colin55 , i cant do that..because in my project i must use shift register to run it..

#### colin55

##### Well-Known Member
How are you sinking the columns?

You are not shifting 5 times. You are shifting 8 times.

Last edited:

#### MessUpMymind

##### New Member
hi colin,
i did modified it to shift 5 times , any IC can sink current .. the led is working well just they're not shifting..

#### colin55

##### Well-Known Member
In the circuit you provided, it needs 8 shifts.

You need to deliver 7 "1's" and one "0'" to get one of the columns to illuminate.
This "0" must be shifted. This must be set-up before outputting the highs from the micro to illuminate the column.
How are you shifting the 1 0 0 0 0 0 0 0 pattern

Last edited:

##### Banned
The poster is stating that it successfully shows the first data sent just not ones sent after. Something must be working right the first time around.

Last edited:

#### MessUpMymind

##### New Member
Hi Colin,
Thanks for your advice , i have did those programming at first place ..so i dont think is that problem.

you are right sir, well i have some pieces of advice that stated it not functioning is because of the shift register(74LS164N) IC itself have a memory inside , therefore after the first data go into it , it will keep looping inside the memory which only contain the first 8 bits data , so it will only display the first data..but i have a looked on the data sheet and i cant find any memory storage inside the IC..

#### be80be

##### Well-Known Member
memory storage
It's latch which your chip has none. But are you holding pin 9 high the clear pin your drawing shows clear not hooked up if so it will only load data one time if your not holding clear high which is pin 9 on a p-dip I looked agin you have it going to the pic hook it to vdd and try your code.

Last edited:

#### be80be

##### Well-Known Member
I looked at your code and it's not holding it high a 74ls164 loads data with clear high you do that one time in your code But if it gos low it will not let it load data which is what you have going on here.

#### MessUpMymind

##### New Member
hi be80be,

thanks for your quick reply , i will try it out...but when i put my oscilloscope probe on the microcontroller pin which send out the pulses to the clear pin . i only can see continuous high only...

#### MessUpMymind

##### New Member
hi be80be,

i got stuck in there also because i have a look on other people coding , they did set it low that data pin after the first data and first clock pulse sent into the shift register. for example http://www.electro-tech-online.com/threads/74hc164-shift-register-doubt.89104/ gayan coding set it to low after the first data and first clock pulse. sir , have i miss some important theory behind it??

Note: after i gone through the data sheet of 74LS164N if 0 sent into the data pin it will be reset for all the output pin.

Regards
TK

Status
Not open for further replies.