list P=16F84A
#include "p16f84A.inc"
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC
errorlevel -302
CounterA equ 0x0C
CounterB equ 0x0D
CounterC equ 0x0E
bsf STATUS,RP0
movlw b'00000000'
movwf TRISB
bcf STATUS,RP0
Main
movlw b'10111111'
movwf PORTB
call Delay
movlw b'01000000'
movwf PORTB
call Delay
goto Main
Delay
movlw D'26'
movwf CounterC
movlw D'119'
movwf CounterB
movlw D'85'
movwf CounterA
loop decfsz CounterA,1
goto loop
decfsz CounterB,1
goto loop
decfsz CounterC,1
goto loop
return
end
-hi? Is your delay program ok? I do need a delay program for my PIC16F84A project.
-tnx
-How did you made your circuit in delay program using PI16F84A? Honestly I don't know what to do. Poor me.
Hi.
Don't get discouraged. It's really very simple.
You see, your Pic is operating, if you're using a 4MHz crystal, at 1 millionth of a second per instruction. For example, if you instruct "bsf PORTB,0", a LED on that pin will light... for one-millionth of a second.
What you have to do is get it to stay on for, say, 500,000 millionths of a second.... a lot of big numbers that represent one-half second, which your eye can see.
This explanation is close but is not it really is.
After one sets a pin to a certain logic level, the level will stay there until it is deliberately changed by the software.
The clock frequency has nothing to do (yet) with how long it remains lit.
Although we can use repeated instructions to set pin to a certain logic level for certain time, we usually do it by another method(s). We set up the logic level, to turn ON the led and then have the PIC doing a certain times of "NOP" in a loop so that it is simply wasting time. The pin level will remain steady while the PIC is doing NOPs. Then we set the logic level to turn off the LED.
The clock frequency now comes into play because the faster the clock, the less time the loop will end. By using different frequency clocks, and using different values for loop counter, we can get the same delay regardless.
However, the best method is to use the timer resources inside the PIC so we don't end up wasting time in a loop.
Main bsf PORTB,0
call Del5M
bcf PORTB,0
call Del5M
goto Main
Del5M movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0
;5 cycles
goto $+1
goto $+1
nop
return
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?