Maker Pro
Maker Pro

nested loop delay for 16F84 PIC

A

Ash

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
 
J

JeffM

I am relatively new to PIC programming

If you are going to be messing with PICs,
you need to investigate this mailing list.[1]
http://72.14.207.104/search?q=cache:NdRnbD6tSsIJ:www.piclist.com/+PICLIST-Mailing-List-Archive

The archive is a useful resource so you won't have to ask questions
that have been posed a billion times before.
..
..
[1] The 1st thing you'll learn is that the 16F84 is obsolete.
http://groups.google.com/groups?q=PIC16F84+OR+16F84+modern-PIC+OR+modern-PICs+-jeffm_
 
A

Alexander

Ash said:
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
 
A

Alexander

Anthony Fremont said:
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
Er, umm....yes they do.

You're right, my mistake.
I was thinking of other skip options like carry.
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?
 
A

Ash

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.
 
A

Alexander

Ash said:
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.
If the code placed in the OP worked for a 0.2sec delay, you simply use
the following:

MOVLW, D'50'; 50 times 0.2 should be 10
MOVWF COUNT3 ; make variable first
DELAY10SEC
CALL SECTION
DECFSZ COUNT3
GOTO DELEY10SEC

Then paste the subroutine somewhere outside the main code, but before
"end"!

Alexander

p.s. I have not tested anything
 
Top