# DECFSZ command problem

Status
Not open for further replies.

#### MessUpMymind

##### New Member
hi there,

Hey , i got stuck in some problem that i dont understand what is going on actually..

i got the following code:
Code:
Start:	movlw 	b'11111000'
movwf	col1

MOVLW	b'00100000'
MOVWF	col2

MOVLW	b'00100000'
MOVWF	col3

movlw	b'00100000'
movwf	col4

movlw	b'11111000'
movwf	col5
GOTO	Run1

Run4:	bsf		PORTB,1
call	CLK
call	DELAY
bcf		PORTB,1
goto	$+2 Run3: bsf PORTB,1 call CLK call DELAY bcf PORTB,1 goto$+2

Run2:
bsf		PORTB,1
call	CLK
call	DELAY
bcf		PORTB,1
goto	$+8 Run1: bsf PORTB,1 movlw d'2' movwf shift1 movlw d'2' movwf shift2 movlw d'2' movwf shift3 movf col1,w movwf PORTD CALL CLK ; call clock to move the data to collumns call DELAY bcf PORTB,1 movf col2,w movwf PORTD CALL CLK call DELAY movf col3,w movwf PORTD call CLK call DELAY movf col4,w movwf PORTD call CLK call DELAY movf col5,w movwf PORTD call CLK call DELAY bcf PORTB,2 bsf PORTB,2 clrf PORTD call DELAYLONG [COLOR="Red"]decfsz shift1,f GOTO Run2 ;can decfsz shift2,f GOTO Run3 decfsz shift3,f GOTO Run4 GOTO Run1[/COLOR] what i got is , the first time it loop .. it work perfectly fine, but when come to second time it only keep looping on the first decfsz loop and it wont go to second decfsz in short it will only display Run2 forever and wont goes to Run3 and Run4. Help is much appreciated =) #### Pommie ##### Well-Known Member Most Helpful Member That is because the second time shift1 will contain zero and so it will loop 256 times. The goto$+8 jumps over the variable setup. I personally hate to see goto $+x in any code, it is much better to use a label. Maybe you should explain what you are trying to do. Mike. #### kchriste ##### New Member Forum Supporter it will only display Run2 forever and wont goes to Run3 and Run4. Are you sure it is forever and not just a very long time? After the decfsz shift1 instruction has run it's course, shift1 is equal to zero, so that the next time you run the decfsz shift1 instruction, shift1 will be equal to 255. This make the loop much longer than the first pass. The reason for difference in the first run vs the subsequent runs is this section of code: Run2: bsf PORTB,1 call CLK call DELAY bcf PORTB,1 goto$+8

Run1: bsf PORTB,1
movlw d'2' ;This code missed on subsequent runs
movwf shift1 ;because of goto $+8 above so shift1 = 0 movlw d'2' movwf shift2 movlw d'2' movwf shift3 movf col1,w movwf PORTD CALL CLK ; call clock to move the data to collumns call DELAY bcf PORTB,1 #### MessUpMymind ##### New Member hi pommie , when all Run1-4 is done then second loop i did fill back the counter with number and it no longer 0.. therefore , it should come out the same output as the first time it loop. I am trying to shift a character by sending in off for the first row, second row and so on so on. Thanks =) #### MessUpMymind ##### New Member Are you sure it is forever and not just a very long time? After the decfsz shift1 instruction has run it's course, shift1 is equal to zero, so that the next time you run the decfsz shift1 instruction, shift1 will be equal to 255. This make the loop much longer than the first pass. The reason for difference in the first run vs the subsequent runs is this section of code: Run2: bsf PORTB,1 call CLK call DELAY bcf PORTB,1 goto$+8

Run1: bsf PORTB,1
movlw d'2' ;This code missed on subsequent runs
movwf shift1 ;because of goto $+8 above so shift1 = 0 movlw d'2' movwf shift2 movlw d'2' movwf shift3 movf col1,w movwf PORTD CALL CLK ; call clock to move the data to collumns call DELAY bcf PORTB,1 hi kc , hmm you got some misunderstanding in that code , sorry for the mess =(. for the$+8 is only true
after the first loop Run1
and this following is my structure how the program works
First loop:Run1
Second loop:Run1+Run2 together
Third loop: Run1+Run2+Run3 together
Fourth loop: Run1+Run2+Run3+Run4

all this run by sending in more 0, after the fourth loop done , i will go back to Run1 and fill back the counter value so it no longer 0 inside those shift register doesnt it?? and it will go back to the same looping structure again.

Thanks

Last edited:

#### kchriste

##### New Member
Forum Supporter
Both Pommie and I have told you what the problem is. Look at your code again or run it in MPLAB SIM to see how it loops and what happens to the shift1 variable.

Last edited:

#### MessUpMymind

##### New Member
hi kc ,

thanks for your help , i will look into the MPlab sim...i understand what you all mean now , so if the shift1=0 then it will loop 256times only goes to shift 2 right?? therefore actually is there anyway i can program to make it such a way that after the shift1=0 i can goes to shift2 immediately to check the condition??

#### kchriste

##### New Member
Forum Supporter
this following is my structure how the program works
First loop:Run1
Second loop:Run1+Run2 together
Third loop: Run1+Run2+Run3 together
Fourth loop: Run1+Run2+Run3+Run4

It's a little crude, but a simple way to do this would be to turn Run1 through Run4 into subroutines:
Code:
Run4:
bsf     PORTB,1
call    CLK
call    DELAY
bcf     PORTB,1
return
And then simply do this:
Code:
call Run1

call Run1
call Run2

call Run1
call Run2
call Run3

call Run1
call Run2
call Run3
call Run4

Last edited:

#### Pommie

##### Well-Known Member
And then simply do this:
Code:
call Run1

call Run1
call Run2

call Run1
call Run2
call Run3

call Run1
call Run2
call Run3
call Run4

The simplest solutions are often the the way to go.

Mike.

#### Wond3rboy

##### Member
Another thing a noticed from the code is that(may be i am wrong) but arent you supposed to output on the LATx register rather then the PORTx register itself? I know it shouldnt be causing a problem but it did when i tried it.

#### kchriste

##### New Member
Forum Supporter
Yes, that is correct. Don't know which PIC MessUpMymind is using so it may, or may not, have a LATx register for the port.

#### MessUpMymind

##### New Member
hi kc, mike and wonderboy

Thanks a lot!!you guys just great..i solved the problem now and i am using 16F877A, so is there use LATx Register will be better??? or if i follow to send direct to PORT will be fine too?? thanks for sparing time with me =)

Best regards,
TK

#### Wond3rboy

##### Member
Hi TK,

From the data sheet i dont see any latch registers for the 16F877a and also in the example(in the datasheet) they are clearing it directly so guess it will work for this chip.

PS: Shows that you should tell the Chip being used or you can end up getting wrong solutions to your problems(like i did this time).

#### MessUpMymind

##### New Member
hi syed ,

Thanks!! yea i should but i too desperate , therefore i got trap into mess =D

Best Regards
TK

#### blueroomelectronics

##### Well-Known Member
The LATx commands are only available on 16bit or higher cores ie: 18F, 24F, 30F, 33F. There are a couple of new 16F series PICs that may have it too.

#### Wond3rboy

##### Member
Hi Bill apparently the new 16f18x series does have latch registers. Just browsed the datasheet.

#### blueroomelectronics

##### Well-Known Member
That's them. I've got to get a couple someday.

Status
Not open for further replies.

Replies
4
Views
1K
Replies
7
Views
3K
Replies
8
Views
2K
Replies
0
Views
2K
Replies
2
Views
2K