Searching \ for 'Delay Output!' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Delay Output!'.

Truncated match.
PICList Thread
'Delay Output!'
1998\03\09@154117 by George Kranis

picon face
How can i program the PIC16F84 to delay for 1 sec before make a RA
output equal to 1?
With best regards

1998\03\09@180937 by Mike Keitz

picon face
On Mon, 9 Mar 1998 22:30:32 +0200 George Kranis <.....gkranisKILLspamspam@spam@USA.NET> writes:
>How can i program the PIC16F84 to delay for 1 sec before make a RA
>output equal to 1?

The two operations are entirely seperate.  First you make the program do
nothing for 1 second.  The easiest way to do this is to use a loop that
decrements a RAM location until it is zero:

       movlw   startval        ;Get constant initial value
       movwf   delayv          ;Store in RAM
       decfsz  delayv,f        ;Count RAM down, skip when done
       goto    delaylp         ;Not done, loop again.

This can delay up to 769 instruction cycles (using startval=0).  At most
PIC clock rates this isn't enough cycles to take anywhere near a second.
With a 4 MHz crystal, you need to delay 1000000 instruction cycles.  The
solution is to nest multiple loops, using several RAM locations to keep
track of them all:

       movlw   startval
       movwf   delayv
       clrf    delayv1
       clrf    delayv2
       decfsz  delayv2,f
       goto    delaylp
       decfsz  delayv1,f
       goto    delaylp
       decfsz  delayv,f
       goto    delaylp

Approximately this takes (772 * 256 * startval) cycles.  So for a delay
of *approximately* 1 second with a 4 MHz PIC crystal, use startval = 5.
If a delay of *exactly* 1 second is needed, delayv1 and maybe even
delayv2 would need to be set to computed initial values other than 0.

Once the delay is done, the next instruction would just be a conventional
setting of the PORTA bit.

If the PIC needs to do something else during the 1 second interval, then
it gets much more complicated.  But it is still possible.  Exactly how
depends on what else it needs to do.

You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at
Or call Juno at (800) 654-JUNO [654-5866]

1998\03\09@195358 by TONY NIXON 54964

picon face
This routine is pretty crude, but it's a starting point.
RA0 will change state approx every second with a 4MHz crystal.

list p=16f84,c=140    ; processor type
TimerH equ 0ch
TimerM equ 0dh
TimerL equ 0eh
PAData equ 0fh
Status equ 03h
PortA  equ 05h
rp0    equ 5h
       org 0h
       movlw 5h
       movwf TimerH
       clrf TimerM
       clrf TimerL
       clrf PAData
       bsf Status,rp0
       clrf PortA        ; all outputs
       bcf Status,rp0
       clrf PortA
Timer   decfsz TimerL     ; time wasting loop
       goto Timer
       decfsz TimerM
       goto Timer
       decfsz TimerH
       goto Timer
       movf PAData,w     ; send new data to PortA
       movwf PortA
       xorlw 1h          ; alternate bit 0
       movwf PAData
       movlw 5h
       movwf TimerH
       goto Timer

PicNPoke Multimedia 16F84 Beginners PIC Tools.

PicNPoke - PicNPlay - PicNPlan - PicNPrep - PicNPost
Plus DT type saver.
New addition - PicNPort I/O Tutor.

1998\03\09@210624 by Ron Kreymborg

On Mon, 9 Mar 1998, George Kranis wrote:

> How can i program the PIC16F84 to delay for 1 sec before make a RA
> output equal to 1?
> With best regards

Well there are many ways. Here's one that uses timer0 in a 10Mhz 16X84.
The constants are clock frequency dependant of course. An include file
called that automatically computes the <prescl> and <tmrval>
constants is listed at


dval    equ     0x0c
; Constants for a ~20Msec delay
prescl  equ     7       ; 6   for 4Mhz
tmrval  equ     61      ; 128 for 4Mhz

       bsf     STATUS,RP0
       movlw   b'11010000' | prescl    ; prescaler to TMR0
       movwf   OPTION_REG
       bcf     STATUS,RP0
       movlw   50                      ; wait for 1 second
       call    delay
delay   movwf   dval                    ; save cycle count
dly1    clrf    TMR0                    ; clear timer0
       bcf     INTCON,T0IF             ; clear t0if flag
       movlw   tmrval                  ; load timer
       movf    TMR0
dly2    btfss   INTCON,T0IF             ; flag set yet?
       goto    dly2                    ; no
       decfsz  dval                    ; all cycles?
       goto    dly1                    ; no

Ron Kreymborg                   Computer Systems Manager
Monash University               CRC for Southern Hemisphere Meteorology
Wellington Road
Clayton, VIC 3168               Phone     : 061-3-9905-9671
Australia                       Fax       : 061-3-9905-9689

1998\03\13@172728 by Alex Torres

> How can i program the PIC16F84 to delay for 1 sec before make a RA
> output equal to 1?
> With best regards

George, there are two ways to do timedelays - using RTCC or program delay.
1) You mau set RTCC and it's pre-scaller to make 1 sec timer period. and
then explore RTCC value or use RTCC interrupt. With 1st method your program
will be like that:
        bsf        PORTA,0              ;  set RA0=1
        call    RTCC_START     ;  start timer
        call    WAIT_RTCC           ; wait for the end of the timer period
        bcf    PORTA,0               ;  set RA0=0
With 2nd -
        call    SET_RTCC_Interrupt_parametr
        bsf     PORTA,0    ; set RA0=1
        bsf     STATUS,GIE  ; enable interrupt  // suppose that RTCC
interrupt was enabled before
       ....... do something ......

Interrupt subroutine:
       bcf   PORTA,0    ; set RA0=0
      clear interrupt flag end exit.

2) Programming delay
        bsf PORTA,0   ; set RA0=1
        call WAIT_1S  ; time delay
        bcf PORTA,0  ; set RA0=0

WAIT_1S   movlw  C1  ; 1st constant
                    movwf  loop1
WAIT_1S_  movlw  C2 ; 2nd constant
                    movwf  loop2
                    decfsz  loop2,f
                    goto $-1
                    decfsz loop1,f
                    goto    WAIT_1S_

Your constants (C1 & C2) depends of PIC clock frequency.

Alex Torres, Kharkov, Ukraine (exUSSR)

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...