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.

Clocking a HCF4015B with a pic16f628a

Status
Not open for further replies.

be80be

Well-Known Member
Shifting a HCF4015B with a pic16f628a for 7x 15 led Matrix

I'm trying to use a 4015 shift register to scroll 3 5x7 led blocks. What I have done right now is set up the 4015 with 8 leds to get it to scroll right I don't think I have the clock right
Code:
list      p=16f628A           ; list directive to define processor
	#include <p16F628A.inc>       ; processor specific variable definitions
   
	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT 

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
        
	cblock	0x20			;Ram address
	TX				;the 4015
	CountSPI
	endc 

	#define		Data PORTA,0	;hardware
	#define		Clock PORTA,1
	
	org	0x0000			;reset
	goto	Main			
	org	0x04			;interrupt vector
	goto	Main			;no interrupts
	include "HC40015.inc"	
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
	movlw 	0xcb			;fill tx buffer
	movwf	TX
	HC40015 TX, CountSPI
Loop
	goto Loop			;hang out here


	END                       	; directive 'end of program'
and this is the macro
Code:
HC4015 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
	[COLOR="Red"]
       btfsc	STATUS,C	;is carry = 0 ?
	bsf	Data		;if not set, set data line to 1
        [/COLOR]
	bsf	Clock		; generate 1 clock
	nop
	bcf	Clock
	
	decfsz	Var1,f		;bits been sent ?
	goto	Loop		;if not repeat

	endm
and here is how I have it hooked up. I think I found what I did wrong
I left the part in red out lol should this work thanks for any help
Burt
 

Attachments

  • 4015.png
    4015.png
    18.2 KB · Views: 340
Last edited:
Ok this is the deal if i send out 0xff it should turn on all 8 leds it just turns on the first 4 all
8 leds will come on if I do it with a switch. And would I not have to reset it before i send new code?
 
The 4015 is two separate 4 bit shift registers. You need to connect them up separately (2 clock pins, namely #1 and #9) and if you're shifting right make sure you move the "right-hand" one before the "left-hand" one,

1234 5678
move the right one
1234 -567
move the left one
-123 4567
grab the new data
n123 4567

otherwise "4" would overwrite "5" before you had a chance to save it.

Also:

Code:
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

You can save a line by doing this,
Code:
bsf	Data		;set data line to 1
btfss 	STATUS,C	;carry = 1 ?
bcf	Data		;if not set line to 0

i.e. assume the data is 1 and correct it if it isn't.

Hope that helps,

ahydra
 
The data sheet said you can hook them up with the same clock line. That you feed Q4a to data b and clock a to clock b
 
Last edited:
I think I'll change chips to 74ls164. the 4015 don't work to good
 
The data sheet said you can hook them up with the same clock line. That you feed Q4a to data b and clock a to clock b

Interesting. I can't remember whether I tried that when I built a similar circuit, but I've never had any problems when connecting the two clocks separately and clocking them in the right order.

ahydra
 
What I think is happening is the clock is wrong see when it loads the first data in it doesn't shift it right and when I check the clock line its low that's why ask if I had it right. The clock should be faster then the data like 2 to 1. I no the data is going out right. Some thing is making my clock line low.
 
I can scroll 4 pins of the 4015 but not all 8 here my new code
Code:
list      p=16f628A           ; list directive to define processor
	#include <p16F628A.inc>       ; processor specific variable definitions
   
	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT 

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
        
	cblock	0x20			;Ram address
	TX				;the 4015
	CountSPI
	count1 			;used in delay routine
	counta 			;used in delay routine 
	countb 			;used in delay routine
	endc 

	#define		Data 	PORTA,0	;hardware
	#define		Clock 	PORTA,1
	#define		Clock0	PORTA,2
	org	0x0000			;reset
	goto	Main			
	org	0x04			;interrupt vector
	goto	Main			;no interrupts
	include "HC4015.inc"	
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
	call	Delay
	goto	Send1
Send1
	movlw 	b'00000010'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	call	Delay
	goto	Send2
Send2
	movlw 	b'00000100'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	call	Delay
	goto	Send3
Send3
	movlw 	b'00001000'			;fill tx buffer
	movwf	TX
	call	Delay
	HC4015 TX,CountSPI
	goto Send4
Send4
	movlw 	b'00010000'			;fill tx buffer
	movwf	TX
	call	Delay
	HC4015 TX,CountSPI
	goto Send5
Send5
	movlw 	b'00010000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	call	Delay
	goto	Send6
Send6
	movlw 	b'00100000'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	call	Delay
	goto	Send7
Send7
	movlw 	b'01000000'			;fill tx buffer
	movwf	TX
	call	Delay
	HC4015 TX,CountSPI
	goto Send8
Send8
	movlw 	b'10000000'			;fill tx buffer
	movwf	TX
	call	Delay
	HC4015 TX,CountSPI
	goto Send		
Loop
	goto Loop			;hang out here
Delay	
	movlw	d'250'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00


	END                       	; directive 'end of program'
maybe some 1 can tell me what I'm doing wrong the micro is the same
thanks
 
Last edited:
Not sure what to suggest. Check your 4015 connections (particularly that you have both resets held low and the Q4A linked to DATA B), then try adding a couple more NOPs in your macro to slow the clock down a bit, this may give the 4015 a bit more time to respond.

If that doesn't work I recommend you try my separate clock method.

ahydra
 
Hay Ahydra I can load data 4 bits on side A or 4 bits on B side How would I added it in the micro
Code:
HC4015 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	Loop1		;if not repeat
       
Loop1	
	Local 	Loop1		;label
	movlw	.8		;eight bits to send
	movwf	Var1		

	rlf	Var,f		;rotate Var to the left

	btfss 	STATUS,C	;carry = 1 ?
	bcf	Data1		;if not set line to 0
	
       btfsc	STATUS,C	;is carry = 0 ?
	bsf	Data1		;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

	
	endm
 
Last edited:
That doesn't work lol. But I now have it shifting in the left side It turns on all 4 of B side and scrolls the A side I need it to scroll all 8 here is my new code
Code:
	list      p=16f628A           ; list directive to define processor
	#include <p16F628A.inc>       ; processor specific variable definitions
   
	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT 

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
        
	cblock	0x20			;Ram address
	TX				;the 4015
	TX0
	CountSPI
	count1 			;used in delay routine
	counta 			;used in delay routine 
	countb 			;used in delay routine
	endc 

	#define		Data 	PORTA,0	;hardware
	#define		Clock 	PORTA,1
	#define		Data0	PORTA,2
	org	0x0000			;reset
	goto	Main			
	org	0x04			;interrupt vector
	goto	Main			;no interrupts
	include "HC4015.inc"
	include "SHC4015.inc"
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
	call	Delay
	goto	Send1
Send1
	movlw 	b'00000010'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	call	Delay
	goto	Send2
Send2
	movlw 	b'00000100'			;fill tx buffer
	movwf	TX
	HC4015 TX,CountSPI
	call	Delay
	goto	Send3
Send3
	movlw 	b'00001000'			;fill tx buffer
	movwf	TX
	call	Delay
	HC4015 TX,CountSPI
	goto Send4
Send4
	movlw 	b'00001000'			;fill tx buffer
	movwf	TX
	call	Delay
	HC4015 TX,CountSPI
	goto Send5
Send5
	movlw 	b'00000001'			;fill tx buffer
	movwf	TX0
	call	Delay
	SHC4015 TX0,CountSPI
	goto Send			
Loop
	goto Loop			;hang out here
Delay	
	movlw	d'250'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00


	END                       	; directive 'end of program'
and the macro I added I'm using both macro
Code:
SHC4015 macro Var,Var2
	
	Local 	Loop		;label
	movlw	.8		;eight bits to send
	movwf	Var2		
Loop
	rlf	Var,f		;rotate Var to the left

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

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

	endm
Thanks 4 any help
Burt
 
Here is what I'm working on
 

Attachments

  • shiftJPG.jpg
    shiftJPG.jpg
    258.8 KB · Views: 197
Well I found why it wasn't sending the clock to the shift register It wasn't going to the Loop Maybe tomorrow I'll get it right thanks for all help
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top