📄 timer_func.c
字号:
/*---------------------------------------------------------------------------
Copyright (c) 2002 ST Microelectronics
This example demo code is provided as is and has no warranty,
implied or otherwise. You are free to use/modify any of the provided
code at your own risk in your applications with the expressed limitation
of liability (see below) so long as your product using the code contains
at least one uPSD products (device).
LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
--------------------------------------------------------------------------*/
#include "upsd_cfg.h"
#include "general.h"
#include "timer.h"
//Timer functions are ready for 1ms interval
#define TIMER0_SCALE TIMER0_PERIOD/1000
int counter;
/*------------------------------------------------------------------------------
This function extend Timer0 operation in every timer0 interrupt
------------------------------------------------------------------------------*/
void do_timer0(void) {
// put your extended functions for timer0 interrupt
counter++;
}
/*------------------------------------------------------------------------------
// Following are a collection of timer routines.
------------------------------------------------------------------------------*/
void delay_ms(count)
uint count;
{
if(count <= TIMER0_SCALE)
timer0_wait(count);
else
{
count /= TIMER0_SCALE;
timer0_wait(count);
}
}
/*
void delay_1sec(void)
{
timer0_wait(1000);
}
void delay_2sec(void)
{
timer0_wait(200);
}
void delay_10sec(void)
{
timer0_wait(1000);
}
void delay_0_5sec(void)
{
timer0_wait(50);
}
void delay_0_1sec(void)
{
timer0_wait(10);
}
void delay_46us(void) // Delay of 44.8 usec. measured
{
delay_14us();
delay_14us();
delay_14us();
}
void delay_14us(void) // Delay of 14.8us w/16Mhz 8031 measured
{
uchar a;
uchar b;
data uint c;
a=1;
b=2;
c=a+b;
a=3;
b=c;
c=4;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -