M16延時(shí)函數(shù)
#ifndef _DELAY_H_
#define _DELAY_H_
#define uint unsigned int
#define uchar unsigned char
void delay_1us( void ); //延時(shí)1us
void delay_1ms( void ); //延時(shí)nms
void delay_nus( uint n );//延時(shí)1ms
void delay_nms( uint n );//延時(shí)nms
void delay_ns( uchar n );
#endif
#define _DELAY_C_
#include "DELAY.H" //用戶自己定義的頭文件
//1us延時(shí)函數(shù)
void delay_1us( void )
{
uint i = 1;
while( i-- )
{
asm("nop");
}
}
//nus延時(shí)函數(shù)
void delay_nus( uint n )
{
uint i = 0;
for (i = 0; i < n; i++)
delay_1us();
}
//1ms延時(shí)函數(shù)
void delay_1ms( void )
{
uint i;
for (i = 0; i < 1140; i++)
{;}
}
//nms延時(shí)函數(shù)
void delay_nms( uint n )
{
uint i = 0;
for (i = 0; i < n; i++)
delay_1ms();
}
//延時(shí)1S
void delay_ns( uchar n )
{
uchar i;
for( i = 0; i < n; i++ )
{
delay_nms( 1000 );
}
}