请大神解析下这个延时程序,比如说 DELAY_100US,怎么计算出延时100US的???小弟刚学不久,看不懂
#ifndef __APP_STM8S_DELAY_US_H
#define __APP_STM8S_DELAY_US_H
//可以延时5个时钟的整数倍,最大值T/5=65535,延时最少5个周期的整倍数+1;去掉中间的两个nop就是3个周期的整倍数
//输入值为需要延迟的时钟数,例如,1600对应100us,时钟数需要是5的整数倍
#define Delay_clk(T) _asm("$N:\ndecw x\nnop\nnop\njrne $L\n",(unsigned int)(T/5)); //@cosmic CxSTM8 4.2.4
#define DELAY_1US _asm("$N:\ndecw x\nnop\nnop\njrne $L\n",(unsigned int) 3); //@Cosmic CxSTM8 4.2.4
#define DELAY_10US _asm("$N:\ndecw x\nnop\nnop\njrne $L\n",(unsigned int) 32); //@Cosmic CxSTM8 4.2.4
#define DELAY_100US _asm("$N:\ndecw x\nnop\nnop\njrne $L\n",(unsigned int) 320); //@Cosmic CxSTM8 4.2.4
#define DELAY_1MS _asm("$N:\ndecw x\nnop\nnop\njrne $L\n",(unsigned int) 3200); //@Cosmic CxSTM8 4.2.4
#define DELAY_10MS _asm("$N:\ndecw x\nnop\nnop\njrne $L\n",(unsigned int) 32000); //@Cosmic CxSTM8 4.2.4
#define DELAY_20MS _asm("$N:\ndecw x\nnop\nnop\njrne $L\n",(unsigned int) 64000); //@Cosmic CxSTM8 4.2.4
#endif |