單片機(jī)C語(yǔ)言延時(shí)分析
unsigned char delay(unsigned char i,unsigned char j,unsigned char k)
{unsigned char b,c;
b="j";
c="k";
do{
do{
do{k--};
while(k);
k="c";
j--;};
while(j);
j=b;
i--;};
while(i);
}
這精確延時(shí)子程序就被C51編譯為有下面的指令組合完成
delay延時(shí)子程序如下:
MOV R6,05H
MOV R4,03H
C0012: DJNZ R3, C0012
MOV R3,04H
DJNZ R5, C0012
MOV R5,06H
DJNZ R7, C0012
RET
假設(shè)參數(shù)變量i的初值為m,參數(shù)變量j的初值為n,參數(shù)變量k的初值為l,則總延時(shí)時(shí)間為:l×(n×(m×T+2T)+2T)+3T,其中T為DJNZ和MOV指令執(zhí)行的時(shí)間。當(dāng)m=n=l時(shí),精確延時(shí)為9T,最短;當(dāng)m=n=l=256時(shí),精確延時(shí)到16908803T,最長(zhǎng)。
c語(yǔ)言相關(guān)文章:c語(yǔ)言教程
評(píng)論