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

📄 vrctr_m04_c2.c

📁 sircs decoder, for amplifier.. this is to decode
💻 C
字号:
/****************************************************************************************************/
/*$Header	: 																						
/* AUTHOR 	: TC PUI															
/* FILE NAME: VRCTR.C																				
/* PURPOSE	: VR CONTROL																			
/* MODEL	:2CH AMP														    
/* Copyright (c) 2002 Sony Corporation All Rights Reserved											
/****************************************************************************************************/
#define	_VRCNT_C

#include "_main_M04_C2.h"
/****************************************************************************************************/
/* local variables definition which are refered only this file										
/****************************************************************************************************/
#define _VRCHATOK  	2
#define _VRACT		0x01
#define	_NOACT		0xff
#define ADGAP		3

/****************************************************************************************************/
/* static variable definition											  							
/****************************************************************************************************/
static unsigned char GetVRId(unsigned char vrsts);
static unsigned char GetVRAct(unsigned char vro, unsigned char vrsts);

/****************************************************************************************************/
/* FUNCTION		:	IniKey																			
/* PURPOSE		:	key initialize 							  										
/* INPUT		:	None																			
/* RETURN VALUE	:	None																			
/****************************************************************************************************/
void VR_Initialize(void)
{	
	unsigned char i;
	
	for (i=0; i<_VR_NUM; i++) {
		_vr[i].buff		= CLEAR;			/* vr buffer				*/
		_vr[i].stat		= CLEAR;			/* vr state					*/
		_vr[i].time		= CLEAR;			/* vr timer					*/
		_vr[i].fgchat	= CLEAR;			/* vr chattering check flag	*/
		_vr[i].fgreq	= CLEAR;			/* vr request flag 			*/
	}

	vrsts = CLEAR;
	VRRead[0] = CLEAR;
	VRRead[1] = CLEAR;

	return;
}

/****************************************************************************************************/
/* FUNCTION		:	KeyControl																		
/* PURPOSE		:	key control 							  										
/* INPUT		:	None																			
/* RETURN VALUE	:	None																			
/****************************************************************************************************/
void VR_Control(void)
{
	
	unsigned char id, act;
	
	if ((PowWork.Pw1s == ON)/* && Is10msAInterval()*/) {
		if (vrsts < _VR_NUM){					
		
			id = GetVRId(vrsts);							/* get vr id 					*/

			act = GetVRAct(id, vrsts);						/* get vr action 				*/

			if (act == _VRACT) {							/* action? 						*/					
				_vr[vrsts].fgreq = SET;						/* set vr change request flag 	*/
			} else {
				_vr[vrsts].fgreq = CLEAR;	
			}
			
			if (_vr[vrsts].fgreq == SET){
				if (vrsts){
					EventExecute(EV_VRCOMINGRIGHT, id);		
				} else {
					EventExecute(EV_VRCOMINGLEFT, id);		 
				}
				_vr[vrsts].fgreq = CLEAR;
			}
		}	
		
		if (++vrsts >= _VR_NUM){
			vrsts = CLEAR;		
		}

	}
	return;
}

/****************************************************************************************************/
/* FUNCTION		:	GetVRId																		
/* PURPOSE		:	get vr id							  										
/* INPUT		:	vr status																		
/* RETURN VALUE	:	None																			
/****************************************************************************************************/
static unsigned char GetVRId(unsigned char vrsts)
{
	const static unsigned char	adc1_tbl[] = {

		0x01,	/* AD ch 0 */
		0x11,	/* AD ch 1 */
		0x21,	/* AD ch 2 */
		0x31,	/* AD ch 3 */
		0x41,	/* AD ch 4 */
		0x51,	/* AD ch 5 */
		0x61,	/* AD ch 6 */
		0x71,	/* AD ch 7 */

	};		
	
	unsigned char	id, ch;
	unsigned int cal;
	
	id = CLEAR;
	if (vrsts >= _VR_NUM){
		vrsts = 0;
	}
	ch = vrsts + 2; 										/* VR use channel 2 & 3 		*/
	ADC2.BYTE = 0x01;
	ADC1.BYTE = adc1_tbl[ch];								/* start AD Conversion 			*/
			
	while( !(ADC1.BYTE & 0x08) );							/* finish convert? 				*/
	ADC1.BYTE = 0x00;						
	
	cal = (unsigned int)((ADDH.BYTE<<8)|(ADDL.BYTE));		/* 10 bit resolution 			*/
	if(cal > VRRead[vrsts]){
		if( (cal - VRRead[vrsts]) > ADGAP){					/* c/m for VR noise 			*/ 
			id = SET;
		}
	}else{
		if( (VRRead[vrsts] - cal) > ADGAP){
			id = SET;
		}
	}
	if (id == SET){
		VRRead[vrsts] = cal;
		id = (unsigned char)(cal >> 2);						/* change to 8bit resolution 	*/
	}else{
		id = (unsigned char)(VRRead[vrsts]>>2);
	}

	return id;
}

/****************************************************************************************************/
/* FUNCTION		:	GetVRAct																		
/* PURPOSE		:	get vr action						  										
/* INPUT		:	adkey id, channel																
/* RETURN VALUE	:	action																			
/****************************************************************************************************/
static unsigned char GetVRAct(unsigned char vrout, unsigned char vrsts)
{
	unsigned char result = _NOACT;

	if( _vr[vrsts].buff != vrout){							/* vr change? 					*/
		_vr[vrsts].buff = vrout;
		_vr[vrsts].fgchat = SET;							/* set chattering flag 			*/
		_vr[vrsts].stat = CLEAR;
	} 
	
	if (_vr[vrsts].fgchat == SET){			
		_vr[vrsts].stat++;									/* state count up 				*/
		if (_vr[vrsts].stat	>= _VRCHATOK){					/* chattering check o.k			*/
			_vr[vrsts].stat = CLEAR;
			_vr[vrsts].fgchat = CLEAR;
			result = _VRACT;								/* action: change vr value 		*/	
		} else {
			result = _NOACT;								/* no action 					*/
		}
	} else {
		result = _NOACT;
	} 
	
	return result;
}



⌨️ 快捷键说明

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