下面以这个简单程序为例,测试k变量在不同数据类型下的IO切换速率,晶振统一采用12M
#include <stc12c.h>
void main(void)
{
u8 k;
while(1)
{
P3=0x0;
k=255;
while(k--);
P3=0xff;
k=255;
while(k--);
}
}
当k为u8类型时(unsigned char):
file:///C:/Users/Administrator/AppData/Roaming/Tencent/Users/1716094642/QQ/WinTemp/RichOle/%7BPJBJW689VRKZU1)FCT%60%60(N.png
IO翻转周期为0.4907ms;
当k为unsigned short(16位)类型时:
[img]file:///C:/Users/Administrator/AppData/Roaming/Tencent/Users/1716094642/QQ/WinTemp/RichOle/TB)BKAY7[DJ5MX%25H4CGA(2N.png[/img]
IO翻转周期为0.7043ms;
当k为unsigned int(32位)类型时:[img]file:///C:/Users/Administrator/AppData/Roaming/Tencent/Users/1716094642/QQ/WinTemp/RichOle/Z5RS$9LV[QKGZFSJFS]W4%7DJ.png[/img]
IO翻转周期为2.922ms;
由此可见不同的数据宽度对8位机的执行速度有着很大的影响,所以在实际使用中应当合理选择变量类型
|