i have attached the code, in this the counter 'count3' and 'count4' is counting down till zero, but the 'count5' and 'count6' will count only if the counter value is 0x01, other than this value (0x00,0x02,0x03 ...) the register value is not decrementing, what will be the reason, i am very much confused about it, hi friends please clarify.
Start
BTFSC portA,1
goto set_counter
BTFSS portA,0
goto clear_all
set_counter
bsf portB,1
bcf portB,0
bcf portB,4
;BTFSC counter_status,0
;goto wait_0
movlw 0x01 ;--- to enable counter
movwf counter_status
movlw 0xFF
movwf count3
movlw 0x0f
movwf count4
movlw 0x02
movwf count5
movlw 0x02
movwf count6
goto delay12
clear_all
BTFSC portA,1
goto set_counter
bcf portB,0
bcf portB,1
bcf portB,4
bcf portB,5
bcf portB,6
bcf portB,7
movlw 0x00 ;--- to enable counter
movwf counter_status
delay12
BTFSS counter_status,0
goto Start
decfsz count3,f
goto Start
decfsz count4,f
goto Start
bsf portB,5
decfsz count5,f
goto Start
bsf portB,6
decfsz count6,f
goto Start
bsf portB,7
goto Start
end
counter malfunction
-
- Posts: 61
- Joined: Thu Dec 20, 2007 4:23 pm
- Location: singapore
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: counter malfunction
Hello
Thats one of the major problems with assembler its very hard to read and even harder to debug, If you are just getting into programming I advise you to stop learning assembler and learn C instead as assembler is a rapidly dying language and C is so much easier to read, debug and understand. Alternativly there is Flowcode which is even better
If however you must use assembler then the problem you are having is due to the following lines.
BTFSS counter_status,0 ;if counter bit 0 is set then skip goto instruction - if only bit 0 is set the counter_status = 1.
goto Start
decfsz count3,f ;decrement and skip goto if equal to zero
goto Start
decfsz count4,f ;decrement and skip goto if equal to zero
goto Start
Thats one of the major problems with assembler its very hard to read and even harder to debug, If you are just getting into programming I advise you to stop learning assembler and learn C instead as assembler is a rapidly dying language and C is so much easier to read, debug and understand. Alternativly there is Flowcode which is even better

If however you must use assembler then the problem you are having is due to the following lines.
BTFSS counter_status,0 ;if counter bit 0 is set then skip goto instruction - if only bit 0 is set the counter_status = 1.
goto Start
decfsz count3,f ;decrement and skip goto if equal to zero
goto Start
decfsz count4,f ;decrement and skip goto if equal to zero
goto Start
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel