/* PIC18 software interface header */
#define Fosc 11059200 //XTAL = 11.0592MHz
#define Fcy (Fosc/4) //2764800Hz
void
User_Delay_Ms(uchar number) //delay=((((num1*4)+4)*num2+6)*number+13)/Fcy
{
static unsigned char num1,
num2;
do
{
num2 = 10;
do
{
num1 = Fcy/40322;
while(--num1);
}while(--num2);
}while(--number);
}
欢迎测试!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
即——继
进来后才明白。
(原文件名:2012-2-18 17-41-27.png)
(原文件名:2012-2-18 18-28-47.png)
plus, if you have interrupt, your delay routines will produce different actual delays.
"num1 = Fcy/40322; "
I would redefine 40322 so that it can be easily changed when you move the routine to a different chip / architecture.
" while(--num1); "
this will create a problem when num1 is calculated to be 0 - from very low Fcy for example. I would use "while (num1--) continue;" instead.
I use a similar approach, except that mine was built up, from delay(cycles); to delay_us(us) which calls delay() and then delay_ms(ms) which calls delay_us(), all of which is based on pre-defined F_CPU.
this allows the code to be fairly easily ported.
一周热门 更多>