/* 延时函数，由STC-ISP软件生成
   Dealy Functions. Generated by STC-ISP Software*/

#include "delay.h"

void delay_ms(unsigned int ms)
{
    unsigned int i;
    do{
        i = MAIN_Fosc / 10000;
        while(--i);   //10T per loop
    }while(--ms);
}

void Delay3us() //@35.000MHz
{
    unsigned char i;

    i = 33;

    while (--i);
}

//For scaleH 500ms with ADC_SPEED_512 20ms-26us-3us
void Delay19971us() //@35.000MHz
{
    unsigned char i, j, k;

    i = 4;
    j = 139;
    k = 196;

    do
    {
        do
        {
            while (--k);
        } while (--j);
    } while (--i);
}

//For scaleH 200ms with ADC_SPEED_512 8ms-26us-3us
void Delay7971us() //@35.000MHz
{
    unsigned char i, j, k;

    i = 2;
    j = 107;
    k = 77;

    do
    {
        do
        {
            while (--k);
        } while (--j);
    } while (--i);
}

//For scaleH 100ms with ADC_SPEED_512 4ms-26us-3us
void Delay3971us() //@35.000MHz
{
    unsigned char i, j;

    _nop_();
    i = 181;
    j = 125;

    do
    {
        while (--j);
    } while (--i);
}

//For scaleH 50ms with ADC_SPEED_512 2ms-26us-3us
void Delay1971us() //@35.000MHz
{
    unsigned char i, j;

	_nop_();
	_nop_();
    i = 90;
    j = 148;

    do
    {
        while (--j);
    } while (--i);
}

//For scaleH 20ms with ADC_SPEED_512 800us-26us-3us
void Delay771us() //@35.000MHz
{
    unsigned char i, j;

	_nop_();
	_nop_();
    i = 36;
    j = 8;

    do
    {
        while (--j);
    } while (--i);
}

//For scaleH 10ms with ADC_SPEED_512 400us-26us-3us
void Delay371us() //@35.000MHz
{
    unsigned char i, j;

	_nop_();
	_nop_();
    i = 17;
    j = 218;

    do
    {
        while (--j);
    } while (--i);
}

//For scaleH 5ms with ADC_SPEED_512 200us-26us-3us
void Delay171us() //@35.000MHz
{
    unsigned char i, j;

    _nop_();
    i = 8;
    j = 195;

    do
    {
        while (--j);
    } while (--i);
}

//For scaleH 2ms with ADC_SPEED_512 80us-26us-3us
void Delay51us() //@35.000MHz
{
    unsigned char i, j;

    _nop_();
	_nop_();
    i = 3;
    j = 78;

    do
    {
        while (--j);
    } while (--i);
}

//For scaleH 1ms with ADC_SPEED_352 40us-19us-3us
void Delay18us() //@35.000MHz
{
    unsigned char i;

    i = 208;

    while (--i);
}

//For scaleH 500us with ADC_SPEED_192 20us-11us-3us
void Delay6us() //@35.000MHz
{
    unsigned char i;

    i = 68; //微调/Fine tuning 52->44

    while (--i);
}
