nested loop delay for 16F84 PIC

A

Ash

Guest
hello

I am relatively new to PIC programming, I have written a short sequence
with a nested loop delay that last about 0.2 seconds
------------------------------------------------------------------------------------------
;SUBROUTINE SECTION.

DELAY MOVLW D'255' ;LOAD 255
MOVWF COUNT1 ;IN COUNT1

LOAD2 MOVLW D'255'
MOVWF COUNT2


DEC2 DECFSZ COUNT2,F
GOTO DEC2

DECFSZ COUNT1,F
GOTO LOAD2


RETURN
------------------------------------------------------------------------------------------------
I need to create a delay of 10 seconds though and have tried to add
another loop to the code by creating a COUNT3 and decrementing it. I
could not get this to work.

I also tried creating another subroutine that called DELAY by simply
going

DELAY2 GOTO DELAY
GOTO DELAY
RETURN

This did not work either. I finally turned to the delay code generator
http://www.piclist.com/techref/piclist/codegen/delay.htm but this also
did not work, and I didn't understand what the command $+2 meant

Can someone help with code for the 10 second delay?

Cheers

Ash
 
"Ash" <ashleyyouett@hotmail.com> schreef in bericht
news:1142009591.253634.117830@p10g2000cwp.googlegroups.com...
hello

I am relatively new to PIC programming, I have written a short
sequence
with a nested loop delay that last about 0.2 seconds
------------------------------------------------------------------------------------------
;SUBROUTINE SECTION.

DELAY MOVLW D'255' ;LOAD 255
MOVWF COUNT1 ;IN COUNT1

LOAD2 MOVLW D'255'
MOVWF COUNT2


DEC2 DECFSZ COUNT2,F
GOTO DEC2

DECFSZ COUNT1,F
GOTO LOAD2


RETURN
------------------------------------------------------------------------------------------------
I need to create a delay of 10 seconds though and have tried to add
another loop to the code by creating a COUNT3 and decrementing it. I
could not get this to work.

I also tried creating another subroutine that called DELAY by simply
going

DELAY2 GOTO DELAY
GOTO DELAY
RETURN

This did not work either. I finally turned to the delay code
generator
http://www.piclist.com/techref/piclist/codegen/delay.htm but this
also
did not work, and I didn't understand what the command $+2 meant

Can someone help with code for the 10 second delay?

Cheers

Ash
OK, I can give you some help.
1st: You probably have another chip than the 16F84.
2nd the $ means the current PC
3rd don't use instructions that are for another family PIC's, the
16FXXX don't support DECFSZ. Look at the instruction set in the
manual.

Somhow RTFM (of the right chip) pops into my mind.

Alexander
 
"Anthony Fremont" <spam@anywhere.com> schreef in bericht
news:x7yQf.6991$733.4023@tornado.texas.rr.com...
"Alexander" <electricdummy@hotmail.com> wrote in message
news:dusjmc$4gd$1@news5.zwoll1.ov.home.nl...

OK, I can give you some help.
1st: You probably have another chip than the 16F84.

Why would you say that? They are still quite available.
The 16F84 is like the 16C84 obsolete!
The chip in question is more likely to be a 16F84A
2nd the $ means the current PC
3rd don't use instructions that are for another family PIC's, the
16FXXX don't support DECFSZ. Look at the instruction set in the
manual.

Er, umm....yes they do.
You're right, my mistake.
I was thinking of other skip options like carry.

Somhow RTFM (of the right chip) pops into my mind.

I heard that. ;-)

Looks to me like the OP needs to use CALL instead of GOTO.

That's for the whole routine.

Maybe the OP can give more information, does it wait forever or
doesn't it wait at all?
Does the PIC run at all?
 
"Alexander" <electricdummy@hotmail.com> wrote in message
news:duuds8$ssv$1@news4.tilbu1.nb.home.nl...
"Anthony Fremont" <spam@anywhere.com> schreef in bericht
news:x7yQf.6991$733.4023@tornado.texas.rr.com...

"Alexander" <electricdummy@hotmail.com> wrote in message
news:dusjmc$4gd$1@news5.zwoll1.ov.home.nl...

OK, I can give you some help.
1st: You probably have another chip than the 16F84.

Why would you say that? They are still quite available.
The 16F84 is like the 16C84 obsolete!
The chip in question is more likely to be a 16F84A

2nd the $ means the current PC
3rd don't use instructions that are for another family PIC's, the
16FXXX don't support DECFSZ. Look at the instruction set in the
manual.

Er, umm....yes they do.

You're right, my mistake.
I was thinking of other skip options like carry.
SKPC, SKPZ, SETC, SETZ, MOVFW filereg and the like are also available on
the 16Fs since they are basically built-in macros that substitute for
"BTFSS STATUS,C", "BTFSS STATUS,Z", "BSF STATUS,C", "BSF STATUS,Z", and
"MOVF filereg, W" respectively. Too bad microchip won't change the
SUBLW mnemonic by switching it to SUBWL as it should have been.

Somhow RTFM (of the right chip) pops into my mind.

I heard that. ;-)

Looks to me like the OP needs to use CALL instead of GOTO.

That's for the whole routine.

Maybe the OP can give more information, does it wait forever or
doesn't it wait at all?
Does the PIC run at all?
I think the OP got the short delay routines to work, but couldn't figure
out how to extend it. He indicated that he'd made another routine to
"call" the working delay routines, but his pasted code shows that he has
GOTO statements. That will never work. He's probably underflowing the
stack.
 
Unfortunately I am using the 16F84A chip and cannot change that, I do
not have a manual for it as such but a few pieces of paper defining the
35 commands it supports (which include decfsz) and overview of what the
chip is capable of.

The code I quoted before does work, giving an 0.2 sec delay so the PIC
is functioning fine and successfully decrements counters, my question
was how can I extend this delay to 10 seconds as I have tried and
failed at numerous attempts loops.

I have tried using the CALL command but it did not work when I
programmed the chip. On the simulation in MPLAB it never seemed to exit
the second subroutine despite the RETURN command at the end of the
routine with all the different variations of coding I tried.
 

Welcome to EDABoard.com

Sponsor

Back
Top