I have the same question. According to what other people adviced me, you use TMR0.
TMR0 with prescale 256. So we have 256*256 = 65536 Ms or 65.5 ms
if you loop it 15 times, so 65.5ms * 15 = 0.9825 sec
correct me If I am wrong.
Thanks
Try this if you not short of memory, use MPLAB stopwatch to test it.
Code:
del EQU 0X74
delf1 EQU 0x75
delf2 EQU 0x76
main call DEL1sec
goto main
DEL1sec movlw .6 ;Delay start here,
movwf del ;1.000001 sec
movlw .19
movwf delf2
movlw .174 ;fine tune with this number
movwf delf1 ;173=999.99800 s
;174=1.000001 s
;175=1.000004 s
decfsz delf1 ;Start decrementing the file registers.
goto $-1
decfsz delf2
goto $-3
decfsz del
goto $-5
return ;Go back if is done
Hi, can you please tell me what else do I need to add for the code to make it work, I mean such things as specifying which PIC, including inc file... I am a nuewbie.
Thanks
Hi, can you please tell me what else do I need to add for the code to make it work, I mean such things as specifying which PIC, including inc file... I am a nuewbie.
Thanks
If you check my tutorials you will see everything you need, Tutorial 1 introduces timing delays and the reasons for them - an easy way to generate the code for a specific delay is to use the Delay Code Generator on the PICList at http://www.piclist.com.
Thanks for your advices.
I tried to get a delay of 1 sec by using busy loop. I think as follow:
1 sec = 1,000,000 instructions = 256 * 256 *15 = FF * FF * 0F
And I have the code:
Oh, this code I got from the piclist code generator. It does with d1 = 0x08
d2=0x2F d3=0x03. I modified according to what I think: d1=0xFF, d2=0xFF d3=0x0F
As it reduce d1, it goto ... goto.... goto..., that is, it takes 2 + 2 + 2 cycles to do this loop. And it takes d1* ( 1 + 2 + 2+2) cycles to decrease d1 to zero. It's not only d1 cycles. So to d2. Therefore, you get a so long loop.
I've never used
d1 equ 20h.. so I don't remember, but if it's a const, how can you change it? I usually use variable in form that
d1 res 1
d2 res x
....
And as I need a preset value, I set in on Initialize fuctions. I do this because I made a standard form for all of my programs. As I more register, I add it to that block.
d1 equ 20 ; means d1 has an address of 20, which is a general purpose reg.
I think I can change it, cant I? Because it is just a general purpose reg, and therefore, it is a var, not const.
In a loop. I noticed:
1. goto <-> 2 instructions cycle
2. decfsz <-> 1 cycle if we dont skip, and 2 cycles if we skip....
Wow, this is so complicated. How come we calculate to get 1 sec delay by usign busy loop? Can someone give a sample code with explanation?
Thanks :?
Hi kemo
I'm also a student in the faculty of engineering. I need your help in microcontroller specially for smart card projects. I'm also from Egypt (Alex). I think we could be parteners in a very good workshops. We can alter experiences. I wish to have contact with you as soon as possible