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

📄 acprd_encoder.c

📁 source code for a sample alarm control panel system using Freescale MC9S12DP256 . The project was im
💻 C
字号:
//=============================================================================
// File: ACPRD_ENCODER.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 "acprd_encoder.h"

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

INT16 encoder_count;

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

void initEncoder(void) {

	// make sure timer is enabled
	TSCR1  |= BM_TEN;
	// select Input Capture function for channels 0 and 1
	TIOS &= ~(BM_1 | BM_0);
	DDRT &= ~(BM_3 | BM_1 | BM_0);
	// TC0,TC1: detect both edges
	TCTL4 =  BM_EDG1B | BM_EDG1A | BM_EDG0B | BM_EDG0A;
	// enable pulse filter on ICx inputs
	DLYCT = 0x03;
	// enable Interrupts for channels 0 and 1
	TIE |= BM_1 | BM_0;
	encoder_count = 0;
	}

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

INT16 hasEncoder(void) {

	return encoder_count;
	}

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

INT16 getEncoder(void) {

	INT16 enc;

	enc = encoder_count;
	encoder_count = 0;
	return enc;
	}

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

// Encoder channel "B" input edge interrupt
//
#ifdef METROWERKS_C
interrupt
#endif
#ifdef IMAGECRAFT_C
#pragma interrupt_handler isrIC0
#endif
void isrIC0(void) {

	// actually not much to do in this kind of implementation...
	TFLG1 = BM_0;						// clear Intr flag
	}

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

// Encoder channel "A" input edge interrupt
//
#ifdef METROWERKS_C
interrupt
#endif
#ifdef IMAGECRAFT_C
#pragma interrupt_handler isrIC1
#endif
void isrIC1(void) {

	switch(PTT & (BM_1 | BM_0)) {
		case 0:
		case 3:
			encoder_count--;
			break;
		default:
			encoder_count++;
			break;
		}
	TFLG1 = BM_1;						// clear Intr flag
	}

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

⌨️ 快捷键说明

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