shamone
Electrical
- Jun 8, 2005
- 30
Hi guys, got a brain teaser for you. I am trying to write code for a delay routine. Could someone tell me for a PIC16f84 @ 4MHz how long the lenght it takes to execute one line of code. I just used a "for" loop for the dealy and 1us for each instruction and put in the appropriate value but it is when longer than calculated. THis is what i have done:
-@ 4MHz (time for one instruction= 1/(4MHz/4)= 1us
-for one second delay--> 1sec/1us= 1000000 cycles
-1000000/2= 500000-->7A120hex
void deley(void)
{
int i;
for(i=0;, i<7A120
{
i++;
}
return;
}
but this ends up being like 10+ seconds. COould someone please point out the error?
Thanks
-@ 4MHz (time for one instruction= 1/(4MHz/4)= 1us
-for one second delay--> 1sec/1us= 1000000 cycles
-1000000/2= 500000-->7A120hex
void deley(void)
{
int i;
for(i=0;, i<7A120
{
i++;
}
return;
}
but this ends up being like 10+ seconds. COould someone please point out the error?
Thanks