?? timer.c
字號:
/*
*******************************************************************************
**
** This device driver was created by Applilet for the 78K0/KB2, 78K0/KC2,
** 78K0/KD2, 78K0/KE2 and 78K0/KF2 8-Bit Single-Chip Microcontrollers.
**
** Copyright(C) NEC Electronics Corporation 2002 - 2005
** All rights reserved by NEC Electronics Corporation.
**
** This program should be used on your own responsibility.
** NEC Electronics Corporation assumes no responsibility for any losses
** incurred by customers or third parties arising from the use of this file.
**
** Filename : timer.c
** Abstract : This file implements a device driver for the timer module
** APIlib: NEC78K0KX2.lib V1.01 [09 Aug. 2005]
**
** Device : uPD78F0513(44-pin)
**
** Compiler: NEC/CC78K0
**
*******************************************************************************
*/
/*
*******************************************************************************
** Include files
*******************************************************************************
*/
#include "macrodriver.h"
#include "timer.h"
/*
*******************************************************************************
** MacroDefine
*******************************************************************************
*/
/*TM00 pulse width measure*/
extern ULONG tm00_pos_width;
extern ULONG tm00_neg_width;
/*TM01 pulse width measure*/
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function initializes TM00_module.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TM00_Init( )
{
TMC00=0x00;
/* internal count clock */
PRM00 |= TM_TM00_CLOCK;
/* TM00 pulse measurement funciton */
SetIORBit(PM0,0x1); /* TI000(P00) input */
ClrIORBit(ISC,0x1);
SetIORBit(PRM00, 0x10); /* specifies raising edge of TI000 */
CRC00 = 0x07; /* CR001 and CR000 used as capture register */
ClrIORBit(IF0H,0x80);
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function starts the TM00 counter.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TM00_Start()
{
ClrIORBit(MK0H,0x80);
TMC00 = 0x4; /* pulse width measure start */
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function stops the TM00 counter and clear the count register.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TM00_Stop()
{
TMC00=0x0;
SetIORBit(MK0H,0x80);
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function is TM00 pulse width calculation.
**
** Parameters:
** ULONG *activerwidth : activewidth clock number
** ULONG *inactivewidth : inactivewidth clock nubmer
** enum TMChannel channel : channel to get pulse width
**
** Returns:
** MD_ARGERROR
** MD_OK
**
**-----------------------------------------------------------------------------
*/
MD_STATUS TM00_GetPulseWidth(ULONG *activewidth, ULONG *inactivewidth,enum TMChannel channel)
{
if(channel == TMChannel0){
*inactivewidth = tm00_neg_width;
*activewidth = tm00_pos_width;
}
else{
return MD_ARGERROR;
}
return MD_OK;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function can initialize TM50_module.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TM50_Init( void )
{
ClrIORBit(TMC50, 0x80);
TCL50 = TM_TM50_CLOCK; /* internal countclock */
/* TM50 PWM output */
ClrIORBit(P1, 0x80);
ClrIORBit(PM1, 0x80); /* TO50 output */
SetIORBit(TMC50, 0x1);
SetIORBit(TMC50, 0x40);
/* init high */
SetIORBit(TMC50, 0x8);
SetIORBit(TMC50, 0x2); /* active low */
CR50 = TM_TM50_PWMACTIVEVALUE;
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function can start the TM50 counter.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TM50_Start( void )
{
/* TM50 PWM output */
ClrIORBit(TMC50, 0x4);
SetIORBit(TMC50, 0x8);
SetIORBit(TMC50, 0x80);
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function can stop the TM50 counter and clear the count register.
**
** Parameters:
** None
**
** Returns:
** None
**
**-----------------------------------------------------------------------------
*/
void TM50_Stop( void )
{
ClrIORBit(TMC50, 0x80);
}
/*
**-----------------------------------------------------------------------------
**
** Abstract:
** This function can change TM50 condition.
**
** Parameters:
** UCHAR : value
** Returns:
** MD_OK
** MD_ERROR
**
**-----------------------------------------------------------------------------
*/
MD_STATUS TM50_ChangeTimerCondition(UCHAR value)
{
CR50 =value;
return MD_OK;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -