acprd_freqout.c

来自「source code for a sample alarm control p」· C语言 代码 · 共 75 行

C
75
字号
//=============================================================================
// File: ACPRD_FREQOUT.C - V1.00
// Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd
//=============================================================================

//-- Includes -----------------------------------------------------------------

#include "datatypes.h"
#include "hcs12dp256.h"
#include "s12_ect.h"
#include "s12_crg.h"					// contains S12_ECLK value
#include "acprd_freqout.h"

//-- Static Vars --------------------------------------------------------------

UINT16 freqout_tticks;

//-- Code ---------------------------------------------------------------------

void initFreqOut(void) {

	// make sure timer is enabled
	TSCR1  |= BM_TEN;
	// prescaler = 2**4 = 16 
	TSCR2 = 0x04;
	// select Output Compare function for channel 2
	TIOS |= BM_2;
	DDRT |= BM_2;
	// enable Interrupt for channel 2
	TIE |= BM_2;
	// timer disconnected from PT2 pin
	TCTL2 &= ~(BM_OM2 | BM_OL2);
	}

//-----------------------------------------------------------------------------

// period is in 祍
//
void setFreqOut(UINT16 period) {

	UINT16 tticks;

	tticks = period * (S12_ECLK / 2000000L);
	tticks /= TIMER_TCNT_PRE;

	if(period == 0) {
		// disconnect PT2 pin
		TCTL2 &= ~(BM_OM2 | BM_OL2);
		}
	else {
		// connect PT2 pin
		TCTL2 |= BM_OL2;
		}
	freqout_tticks = tticks;
	}

//-----------------------------------------------------------------------------

// OC2 toggles buzzer
//
#ifdef METROWERKS_C
interrupt
#endif
#ifdef IMAGECRAFT_C
#pragma interrupt_handler isrOC2
#endif
void isrOC2(void) {

	TC2 += freqout_tticks;
	TFLG1 = BM_2;						// clear Intr flag
	}

//=============================================================================

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?