本帖最后由 为了labview 于 2017-6-20 10:29 编辑
这个延时函数在其他程序中可以正常运行,但在我自己编的程序中出错了,
错误原因附在图片上,代码中红 {MOD}部分时出错所在位置
函数代码如下,
求助懂得人给我解答一下,
/********************Delay_MS()*******************/
void Cpu_Delay100US(word us100)
{
/* Total irremovable overhead: 16 cycles */
/* ldhx: 5 cycles overhead (load parameter into register) */
/* jsr: 5 cycles overhead (jump to subrou
tine) */
/* rts: 6 cycles overhead (return from subroutine) */
/* aproximate irremovable overhead for each 100us cycle (counted) : 8 cycles */
/* aix: 2 cycles overhead */
/* cphx: 3 cycles overhead */
/* bne: 3 cycles overhead */
/* Disable MISRA rule 19 checking - Octal constant used */
/*lint -esym( 960, 19) */
/* Disable MISRA rule 55 checking - Non-case label used */
/*lint -esym( 961, 55) */
asm {
loop:
/* 100 us delay block begin */
/*
* Delay
* - requested : 100 us @ 16MHz,
* - possible : 1600 c, 100000 ns
* - without removable overhead : 1592 c, 99500 ns
*/
pshh /* (2 c: 125 ns) backup H */
pshx /* (2 c: 125 ns) backup X */
ldhx #$00C5 /* (3 c: 187.5 ns) number of iterations */
label0:
aix #-1 /* (2 c: 125 ns) decrement H:X */
cphx #0 /* (3 c: 187.5 ns) compare it to zero */
bne label0 /* (3 c: 187.5 ns) repeat 197x */
pulx /* (3 c: 187.5 ns) restore X */
pulh /* (3 c: 187.5 ns) restore H */
nop /* (1 c: 62.5 ns) wait for 1 c */
nop /* (1 c: 62.5 ns) wait for 1 c */
nop /* (1 c: 62.5 ns) wait for 1 c */
/* 100 us delay block end */
aix #-1 /* us100 parameter is passed via H:X registers */
cphx #0
bne loop /* next loop */
rts /* return from subroutine */
}
/* Restore MISRA rule 19 checking - Octal constant used */
/*lint +esym( 960, 19) */
/* Restore MISRA rule 55 checking - Non-case label used */
/*lint +esym( 961, 55) */
}
void DELAY_MS(word x)
{ unsigned int WF;
WF=x/2;
while(WF--)
{
Cpu_Delay100US(20);
}
}
-
可以直接转换啊,int是32位,word是16位,应该不是这个问题,,,
一周热门 更多>