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

📄 dsareceive.c.bak

📁 7寸TFT电视的源程序
💻 BAK
字号:
//#define DEBUG_MSG
#include "target.h"
#include "dsacomm.h"

#define GetCS()				Get_P1_0()
#define SetCS()				Set_P1_0()
#define GetClk()			Get_P1_1()
#define SetClk()			Set_P1_1()
#define SetData()			Set_P1_2()
#define ClearData()			Clr_P1_2()
#define GetData()			Get_P1_2()

extern bit bNeedSaveTone;
extern bit btPowerKeyPressed;
extern bit btaccswitch;
static unsigned char idata dsaReg;
static unsigned char idata dsaCommon;
static unsigned char idata dsatemp;
static unsigned char idata bitCount = 0;
static unsigned char idata timeOutCommand = 0x6E;
unsigned char idata PowerTimeOutCount = 4;
void PowerTimeOutCommand();
void DealForSetPortCommand();

bit curClk = 1;
bit curCs = 1;

#define WaitClkLow()			\
while(curClk){\
	curClk = GetClk();\
	curCs = GetCS();\
	if(curCs)\
		return;\
}

#define WaitClkHigh()			\
while(curClk==0){\
	curClk = GetClk();\
	curCs = GetCS();\
	if(curCs)\
		return;\
}

void InitDsaPort()
{
	SetData();
	SetClk();
	SetCS();
}

void DealForCommand()
{
	switch(dsaReg){
		case SET_VOL_COMMAND:
			if(dsatemp<=VOL_MAX){
				bNeedSaveTone = 1;
				volume = dsatemp;
			
				
			if(volume!=0 ) {
				HwMuteOff();
				PT2318MuteOff();
			   // MuteOff();
								
				}
				SetVolume(dsatemp);	
				//SetVolume(dsatemp);
				//ShowLcdHex(0x50,dsatemp);
			}
			break;
		case SET_BASS_COMMAND:
			if(dsatemp<=MAX_BASS){
				bNeedSaveTone = 1;
				bass = dsatemp;
				SetBass(dsatemp);
			}
			break;
		case SET_BALANCE_COMMAND:
			if(dsatemp<=MAX_BALANCE){
				bNeedSaveTone = 1;
				balance = dsatemp;
				SetFader();
			}
			break;
		case SET_FADE_COMMAND:
			if(dsatemp<=MAX_FADE){
				bNeedSaveTone = 1;
				fade = dsatemp;
				SetFader();
			}
			break;
		case SET_TREBLE_COMMAND:
			if(dsatemp<=MAX_TREBLE){
				bNeedSaveTone = 1;
				treble = dsatemp;
				SetTreble(dsatemp);
			}
			break;
		case SET_MUTE_COMMAND:
			if(dsatemp||(volume==0)){
				PT2318MuteOn();
				HwMuteOn();
			}
			else{
				PT2318MuteOff();
				HwMuteOff();
			}
			break;
		case SET_POWEROFF_COMMAND:
			ShowLcdString(0x40,"set power off");
			SystemPowerOff();
			break;
		case SET_MODE_COMMAND:
			FPClearLcd();
			GoToSystemMode(TV_MODE,1);
			break;
		case SET_BAND_COMMAND:
			FPClearLcd();
			GoToSystemMode(TUNER_MODE,1);
			break;
		case SET_POWERTIMER_COMMAND:
			PowerTimeOutCount = dsaCommon;
			break;
		case SET_POWERSTART_COMMAND:
			timeOutCommand = dsaCommon;
			SetTimerFunc(TIME_1SEC*((int)PowerTimeOutCount),POWERTIMEOUT_KEY);
			break;
		case SET_PORT_COMMAND:
			DealForSetPortCommand();
			break;	
	}


}

void DealForSetPortCommand()
{
	ShowLcdString(0x40,"SET_PORT_COMMAND:");
	ShowLcdHex(0x40+19,dsaCommon);

	if((dsaCommon&0x10)==0){
		btPowerKeyPressed = 0;
		SystemPowerOff();
		ClearKeyBuf();
	}
	if(dsaCommon&0x01)
		Set_P1_4();
	else
		Clr_P1_4();
	if(dsaCommon&0x02)
#ifdef __EMULATOR_H__
 		pin30 = 1;
#else
		Set_P3_0();
#endif
	else
#ifdef __EMULATOR_H__
 		pin30 = 0;
#else
		Clr_P3_0();
#endif
	if(dsaCommon&0x04)
#ifdef __EMULATOR_H__
 		pin31 = 1;
#else
		Set_P3_1();
#endif
		else
#ifdef __EMULATOR_H__
 		pin31 = 0;
#else
		Clr_P3_1();
#endif

	if(dsaCommon&0x08)
		Set_P3_5();
	else
		Clr_P3_5();

	if(dsaCommon&0x20)
		Set_P3_4();
	else
		Clr_P3_4();

	if(dsaCommon&0x40)
		Set_P3_7();
	else
		Clr_P3_7();
}
void PowerTimeOutCommand()
{
	dsaCommon = timeOutCommand;
	DealForSetPortCommand();
}

void DsaMainHandle()
{
	unsigned char i;
	curCs = GetCS();

	if(curCs)
		return;

	SetData();
	bitCount = 0;
	curClk = 1;
	dsatemp = 0;

	WaitClkLow();

	while(bitCount<7){
		WaitClkHigh();
		dsatemp >>= 1;
		if(GetData())
			dsatemp |= 0x80;
		bitCount++;
		WaitClkLow();
	}

	WaitClkHigh();

	dsatemp >>= 1;
	if(GetData())
		dsatemp |= 0x80;

	bitCount = 0;
	dsaReg = dsatemp;

	if(dsaReg&0x80){
		WaitClkLow();
		//ShowLcdHex(0x4,dsaReg);

		while(bitCount<7){
			WaitClkHigh();
			dsatemp >>= 1;
			if(GetData())
				dsatemp |= 0x80;
			bitCount++;
			WaitClkLow();
		}

		WaitClkHigh();
		curClk = 1;
		dsatemp >>= 1;
		if(GetData())
			dsatemp |= 0x80;

		bitCount = 0;
		dsaCommon = dsatemp;
	//	ShowLcdIntAddr(0x7,dsaCommon);

//do some thing after I had receive the command
		DealForCommand();

		while(1){
			curCs = GetCS();
			if(curCs)
				return;
		}
	}
	else{
		switch(dsaReg){
			case READ_KEY_COMMAND:
				if(btPowerKeyPressed){
					dsatemp = 1;
					btPowerKeyPressed = 0;
				}
				else
				dsatemp = 0;

				if(btaccswitch) dsatemp |=0x2;
				break;

			case READ_VOLUME_COMMAND:
				ShowLcdHex(0x10,volume);
				dsatemp = volume;
				break;
			case READ_BASS_COMMAND:
				dsatemp = bass;
				break;
			case READ_FADE_COMMAND:
				dsatemp = fade;
				break;
			case READ_TREBLE_COMMAND:
				dsatemp = treble;
				break;
			case READ_BALANCE_COMMAND:
				dsatemp = balance;
				break;
		}

		for(i = 0;i<8;i++){
			WaitClkLow();
			if(dsatemp&0x01)
				SetData();
			else
				ClearData();
			dsatemp >>= 1;
			WaitClkHigh();
		}

		while(1){
			curCs = GetCS();
			if(curCs)
				return;
		}
	}
}

⌨️ 快捷键说明

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