⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acprd_freqout.c

📁 source code for a sample alarm control panel system using Freescale MC9S12DP256 . The project was im
💻 C
字号:
//=============================================================================
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -