?? upsd_timer.c
字號:
/*------------------------------------------------------------------------------
uPSD_TIMER.C
uPSD Timer0 Device Driver Functions
06/2002 Ver 0.1 - Initial Version
Copyright 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.
------------------------------------------------------------------------------*/
#pragma CODE // include assembler listing in .lst file
#pragma NOAREGS
#include "upsd3200.h"
#include "upsd_timer.h"
/*------------------------------------------------------------------------------
Local Macro and Manifest Constant Declarations
------------------------------------------------------------------------------*/
//#define TIMER0_COUNT 0xFACA // ((10000h-TC)*(Period*12)) - 17)= 10mS
#define TIMER0_COUNT 0xF448 // for DK3200 (36MHz board)
// 16Mhz = 0xcbfc, (0xfaca=1mS)
// 12mHZ = 0xd8ff
// 11.059Mhz = 0xdb62
// 36.00 Mhz = 0x8ae0 (0xf448=1mS)
/*------------------------------------------------------------------------------
Local Variable Declarations
------------------------------------------------------------------------------*/
static data unsigned int timer0_tick;
/*------------------------------------------------------------------------------
static void timer0_isr (void);
This function is an interrupt service routine for TIMER 0. It should never
be called by a C or assembly function. It will be executed automatically
when TIMER 0 overflows.
------------------------------------------------------------------------------*/
static void timer0_isr (void) interrupt TF0_VECTOR using 1 // 10mS Timer Interrupt Update
{
TR0 = 0; // stop timer 0
TL0 = TL0 + (TIMER0_COUNT & 0x00FF); // Update LSB
TH0 = TH0 + (TIMER0_COUNT >> 8); // Update MSB
TR0 = 1; // start timer 0
timer0_tick++; // Increment the timer tick.. every 1mS
}
/*------------------------------------------------------------------------------
void timer0_initialize (void);
This function enables TIMER 0. TIMER 0 will generate a synchronous interrupt
once every 100Hz (10mS).
------------------------------------------------------------------------------*/
void timer0_initialize (void) // Enable TMR0 for 10mS interrupts
{
EA = 0; // disable interrupts
timer0_tick = 0; // initialize tick value
TR0 = 0; // stop timer 0
TMOD &= 0xF0; // clear timer 0 mode bits
TMOD |= 0x01; // put timer 0 into 16-bit no prescale
TL0 = (TIMER0_COUNT & 0x00FF); // set LSB timeout
TH0 = (TIMER0_COUNT >> 8); // set MSB timeout
PT0 = 0; // set low priority for timer 0
ET0 = 1; // enable timer 0 interrupt
TR0 = 1; // start timer 0
EA = 1; // enable interrupts
}
/*------------------------------------------------------------------------------
unsigned timer0_count (void);
This function returns the current timer0 tick count.
------------------------------------------------------------------------------*/
unsigned int timer0_count (void)
{
data unsigned int t;
EA = 0;
t = timer0_tick;
EA = 1;
return(t);
}
/*------------------------------------------------------------------------------
void timer0_delay (
unsigned count);
This function waits for 'count' timer ticks to pass.
------------------------------------------------------------------------------*/
void timer0_delay (unsigned int count)
{
data unsigned int start_count;
start_count = timer0_count (); /* get the start count */
while ((timer0_count () - start_count) <= count) /* wait for count "ticks" */
{
}
}
void delay_10ms()
{
timer0_delay(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -