/* 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);
}
欢迎测试!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
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.
但是这个形参如果输入0,将是错误的;不过也让人很难理解。不会有人需要0ms的延时吧。有些时候要求时序比较严格的情况下,我们可以将总中断关闭。
it is about the (predictable) behavior of the code: delay_ms(2) is 1 ms, delay_ms(1) is 1ms, delay_ms(0) is 256ms (or32kms, depending on the data type).
that kind of behavior is unexpected for most people.
(原文件名:2012-2-26 7-23-49.png)
这个不会啊,但是输入0是错误的。
如果将代码改成while(number--);汇编代码将会增加,须从新计算Tcy。
一周热门 更多>