Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How does this C code work for 20us delay in PIC?

Status
Not open for further replies.

junhao_wu

Newbie level 3
Joined
Oct 15, 2006
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,314
Hi guys! Newbie here need your help....

Can anyone explain to me how the below C code work for a 20us delay?

void delay_20us (void)
{
char count = 0x07;
loop:
if (-- count == 0)
{
return;}
else goto loop;
}

I mean how to i get count = 0x07?? what's the calculation?
I am using the CC5X complier and PIC16F873

Thanks Guys!
 

pıc16f873+pll

That has to do with the frequency your PIC is running from and with the number of cycles it takes to run that routine. Take a look at the assembly code generated by the compiler.

Ric
 

cc5x delay 20mhz

It depends on the frequency of your PIC.

Example:

U use 20MHz crystal, no pll. One program cycle takes 4 clock cycles, so your PIC executes 5.000.000 instructions per cycle (except branching, which takes two inst. cycles).
In above examle, every tcy (instr. cycle) is 200ns long, and for 20us delay, you need to wait for 100 tcy. So you create a loop which takes 100tcy to execute.

For more details, look in data sheet.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top