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

📄 main.c

📁 一个桥接器87ch47仿真器的c的源程序
💻 C
字号:
/******************************************************************************
        Copyright 2003 Freeway electronics Limited,

        COMPANY CONFIDENTIAL

        Filename : main.c

Rev     Date    Author          Comments
_______________________________________________________________________________
001     03-7-7   Jac Fan        original

@module
       This module is main control for CD Changer Bridge
******************************************************************************/
#include <STDLIB.H>
#include "io870.h"
#include "cust_io.h"
#include "global.h"
#include "Main_Bridge.h"
#include "Bridge_Changer.h"
#include "KEYDEF.H"

BYTE CDC_Type;               		/* 0:no CDC,1:6Disc_1,2:6disc_2,3:10disc_1,4:10disc_2 */
BYTE CDC_Mode;						//0:NO CDC,1:PLAY,2:STOP,3:SHFFL,4:SCAN
BYTE CDC_Disc_NO;
BYTE CDC_Music_NO;

BYTE DATA_2_Main[8];           		/* Data to Main player */
BYTE Current_DATA_2_MAIN_Index;     /* Index of current Data to Main player,from 0 to 7 */

BYTE Key_Code;						//code of Pressed Key

BYTE DATA_2_CDC[4];           		/* Data to CDC */
BYTE Total_Bit_2_CDC;      			/* total bit of Data to CDC */
BYTE Current_Bit_2_CDC;      		/* current bit of Data to CDC */

BYTE CDC_Idle;
BYTE CDC_Idle_Counter;
BYTE CDC_Bit_Index;
BYTE CDC_Byte_Index;
BYTE CDC_Parity;
BYTE CDC_Validate_Parity;
BYTE Data_2_CDC_Interrupt_Count;
BYTE DATA_From_CDC[8];           	/* Data From CDC */

BYTE Bit_Read_Bool;					//lable the bit_read status,0/1
BYTE tmp_Data_from_CDC;				//as a buffer for receive every 8 bit data
BYTE BitCount_From_CDC;           	/* Bit Count From CDC. MAX 64bit */

BYTE Got_Byte_Count;
#pragma section area _DBR_ 0x0ff0
unsigned char	DBR1;	/* 0x0ff0: SIO1 Transmit and Receive Data Buffer */
#pragma section area

extern void __interrupt INT_MAIN_DATA();
extern void __interrupt INT_Send_Data_2_Main();
extern void __interrupt INT_TC1_Send_Data_2_CDC();
extern void __interrupt INT_Test_CDC_BUS();
extern void __interrupt INT_CDC_DATA();
extern void __interrupt INT_ReSend_Data_2_Main(void);
extern void Send_Data_2_Main(void);


//#define Main_LED_ON  				//switch Main_LED turn on/off
//#define CDC_LED_ON				//switch Changer_LED turn on/off,show status of Data from CDC

//define map table between main player and CDC
//suit for CDC 6disc_1,6Disc_2,10Disc_1,10Disc_2
//device code:   *101,  *110,    *001,    *010
//array order: _KEY_COUNT * 4 group
const S_Table_DATA_2_CDC Table_DATA_2_CDC[]=
	{//6disc_1
		//_AMFM_KEY				
		//stop CDC 
		//0101,0001;0001,0010;0000,1000(parity)
		{0x51,0x12,0x08,0,24},
		
		//_SEARCH_CDC_KEY		
		//play current disc music
		//0101,0001;0001,0000;0001,0101(parity)
		{0x51,0x10,0x15,0,24},
		
		//_SCAN_KEY				
		//scan CDC
		//0101,0001;0001,0001;0000,0101(parity)
		{0x51,0x11,0x05,0,24},
		
		//_PALY_2_SFL_KEY		
		//Shuffle CDC
		//0101,0001;0100,0000;0010,0000;0000,0011(parity)
		{0x51,0x40,0x20,0x03,32},
		
		//_Query_CDC_Status_KEY	
		//Query_CDC_status
		//0101,0001;0001,1000;0000,1110(parity)
		{0x51,0x18,0x0e,0,24},
		
		//_NEXT_KEY				
		//next music.use Music search code
		//0101,0001;0011,0000;0xA3;0001,0000(parity)
		{0x51,0x30,0xa3,0x1f,32},
		
		//_PREVIOUS_KEY			
		//Previous  music.use Music Search Code
		//0101,0001;0011,0000;0xB3;0001,1111(parity)
		{0x51,0x30,0xb3,0x1f,32},
		
		//_DISC1_KEY 			
		//Search Disc1 Code
		//0101,0001;0011,0001;0x01;0001,0111(parity)
		{0x51,0x31,0x01,0x17,32},
		
		//_DISC2_KEY			
		//Search Disc2 Code
		//0101,0001;0011,0010;0x01;0001,0110(parity)
		{0x51,0x32,0x01,0x16,32},
		
		//_DISC3_KEY			
		//Search Disc3 Code
		//0101,0001;0011,0011;0x01;0001,0101(parity)
		{0x51,0x33,0x01,0x15,32},
		
		//_DISC4_KEY			
		//Search Disc4 Code
		//0101,0001;0011,0100;0x01;0001,0100(parity)
		{0x51,0x34,0x01,0x14,32},
		
		//_DISC5_KEY			
		//Search Disc5 Code
		//0101,0001;0011,0101;0x01;0001,0011(parity)
		{0x51,0x35,0x01,0x13,32},
		
		//_DISC6_KEY			
		//Search Disc6 Code
		//0101,0001;0011,0110;0x01;0001,0010(parity)
		{0x51,0x36,0x01,0x12,32},
		
		//_PLAY_KEY				
		//play CDC(current disc,music)
		//0101,0001;0001,0000;0001,0101(parity)
		{0x51,0x10,0x15,0,24},
		
		//_Query_CDC_Exist_KEY
		//Query CDC Exist or not,that is connection check command
		{0x58,0xe0,0,0,12},
		
		//_RETURN_2_PLAY_KEY				
		//return to play CDC
		//0101,0001;0100,0000;0000,0000;0000,0001(parity)
		{0x51,0x40,0,0x01,32},
		
		//_BACKUP_STATUS_KEY
		//0101,1001;1101(PARITY)
		{0x59,0xd0,0,0,12},
		
	//6disc_2
		//_AMFM_KEY				
		//stop CDC 
		//0110,0001;0001,0010;0000,0101(parity)
		{0x61,0x12,0x05,0,24},
		
		//_SEARCH_CDC_KEY		
		//play current disc music
		//0110,0001;0001,0000;0001,1000(parity)
		{0x61,0x10,0x18,0,24},
		
		//_SCAN_KEY				
		//scan CDC
		//0110,0001;0001,0001;0000,1000(parity)
		{0x61,0x11,0x08,0,24},
		
		//_PALY_2_SFL_KEY		
		//Shuffle CDC
		//0110,0001;0100,0000;0010,0000;0000,0010(parity)
		{0x61,0x40,0x20,0x02,32},
		
		////_Query_CDC_Status_KEY		
		//Query_CDC_status
		//0110,0001;0001,1000;0000,1111(parity)
		{0x61,0x18,0x0f,0,24},
		
		//_NEXT_KEY				
		//next music.use Music search code
		//0110,0001;0011,0000;0xA3;0001,1101(parity)
		{0x61,0x30,0xa3,0x1d,32},
		
		//_PREVIOUS_KEY			
		//Previous  music.use Music Search Code
		//0110,0001;0011,0000;0xB3;0001,1110(parity)
		{0x61,0x30,0xb3,0x1e,32},
		
		//_DISC1_KEY 			
		//Search Disc1 Code
		//0110,0001;0011,0001;0x01;0001,0110(parity)
		{0x61,0x31,0x01,0x16,32},
		
		//_DISC2_KEY			
		//Search Disc2 Code
		//0110,0001;0011,0010;0x01;0001,0111(parity)
		{0x61,0x32,0x01,0x17,32},
		
		//_DISC3_KEY			
		//Search Disc3 Code
		//0110,0001;0011,0011;0x01;0001,1000(parity)
		{0x61,0x33,0x01,0x18,32},
		
		//_DISC4_KEY			
		//Search Disc4 Code
		//0110,0001;0011,0100;0x01;0001,0001(parity)
		{0x61,0x34,0x01,0x11,32},
		
		//_DISC5_KEY			
		//Search Disc5 Code
		//0110,0001;0011,0101;0x01;0001,0010(parity)
		{0x61,0x35,0x01,0x12,32},
		
		//_DISC6_KEY			
		//Search Disc6 Code
		//0110,0001;0011,0110;0x01;0001,0011(parity)
		{0x61,0x36,0x01,0x13,32},
		
		//_PLAY_KEY				
		//play CDC(current disc,music)
		//0110,0001;0001,0000;0001,1000(parity)
		{0x61,0x10,0x18,0,24},		
		
		//_Query_CDC_Exist_KEY
		//Query CDC Exist or not,that is connection check command
		{0x68,0xf0,0,0,12},
		
		//_RETURN_2_PLAY_KEY				
		//return to play CDC
		//0110,0001;0100,0000;0000,0000;0000,1000(parity)
		{0x61,0x40,0,0x08,32},
		
		//_BACKUP_STATUS_KEY
		//0110,1001;1000(PARITY)
		{0x69,0x80,0,0,12},
	//10disc_1
		//_AMFM_KEY
		//_PLAY_KEY
		//_SCAN_KEY
		//_PALY_2_SFL_KEY
		//_Query_CDC_Status_KEY	
		//_NEXT_KEY
		//_PREVIOUS_KEY
		//_DISC1_KEY
		//_DISC2_KEY
		//_DISC3_KEY
		//_DISC4_KEY
		//_DISC5_KEY
		//_DISC6_KEY
		//_SEARCH_CDC_KEY
	//10disc_2
		//_AMFM_KEY
		//_PLAY_KEY
		//_SCAN_KEY
		//_PALY_2_SFL_KEY
		//_Query_CDC_Status_KEY	
		//_NEXT_KEY
		//_PREVIOUS_KEY
		//_DISC1_KEY
		//_DISC2_KEY
		//_DISC3_KEY
		//_DISC4_KEY
		//_DISC5_KEY
		//_DISC6_KEY
		//_SEARCH_CDC_KEY	
	};

#pragma section  code
void  MPU_init(){
	P0=0x04;
    P0CR = 0x04;	    	/* P06 INPUT ACC STATUS,P02 OUTPUT DATA TRANSFER STATUS */

    P6 =   0xff;
    P6CR = 0xff;            /* p65 output HIGH LEVEL ,P64 OUTPUT CHANGER'S LED STATUS*/
        
    P7 =    0;
    P7CR1 = 0x28;           /* p73,75 -- output CLK, DATA ,P70:input IR from main player*/

	IL = 0;                 /* all interrupt latch clear */
    EIR = 0;                /* clear interrupt enable register */
    
    TC1CR = 0x04;   /* TC1 Timer mode, timer resolution 16us for Send Data 2 CDC */
		            /* 0  0   s   s,  0   1  0  0         */
		            /* TC1 stop, Timer mode,           */
		            /* internal clock, fc/2^7 = 16us      */   
	TREG1A = 8;            /* TC1 16us * 8=128us                     */
			            	    
	TC3CR = 0x05;	    /* TC3 start ,timer resolution 128us,capture mode*/

//	EINTCR=INT1NC ;		//noise rejection time:16/fc;	
						   
    TC3CR = 0x15;	    /* TC3 start ,timer resolution 128us,capture mode*/
    
    EIR = IMF +  EF15 + EF6 + EF8 + EF4 + EF14 ;    /* interrupt enable :P20,TBT*/                        
    											/* TC3(P70),TC1,TC2					*/
    __ASM("EI");    		/* open interrupt master   */
    
    TBTCR=0x08;
    return;
}

#pragma section  code
void Get_CDC_Type()
{
	BYTE CDC_Type_test,i,j,k,Key_Order;
	//search all kinds od CDCs,from 6disc_1 to 10disc_2
	for(CDC_Type_test=1;CDC_Type_test<3;CDC_Type_test++)
	{
		CDC_Type=CDC_Type_test;
		Key_Code=_Query_CDC_Exist_KEYCODE;
		Transmit_Main_2_CDC();
		CDC_Type=0;		//set no CDC,to get right CDC_type
		Key_Code = _NO_KEYCODE;
        for(i=0;i<0x02;i++)		//delay for enough time for reply from CDC
        {
        	for(j=0;j<0xff;j++)
        		for(k=0;k<0xff;k++)
        			__asm("NOP");
        }		
		if(CDC_Type==CDC_Type_test)	break;	//get current CDC_Type
	}
	Key_Order=_RETURN_2_PLAY_KEY;
	DATA_2_CDC[0]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[0];
	DATA_2_CDC[1]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[1];
	DATA_2_CDC[2]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[2];
	DATA_2_CDC[3]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[3];
	Total_Bit_2_CDC=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].bitcount;
	Send_Data_2_CDC();	
        	for(j=0;j<0xff;j++)
        		for(k=0;k<0x90;k++)
        			__asm("NOP");
	Key_Order=_BACKUP_STATUS_KEY;
	DATA_2_CDC[0]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[0];
	DATA_2_CDC[1]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[1];
	DATA_2_CDC[2]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[2];
	DATA_2_CDC[3]=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].data_code[3];
	Total_Bit_2_CDC=Table_DATA_2_CDC[Key_Order+(CDC_Type-1)*_KEY_COUNT].bitcount;
	Send_Data_2_CDC();      
        	for(j=0;j<0xff;j++)
        		for(k=0;k<0xff;k++)
        			__asm("NOP");	
}
void system_var_init()
{
	BitCount_From_CDC=0;
	Current_Bit_2_CDC=0;
	Total_Bit_2_CDC=0;
	tmp_Data_from_CDC=0;
	Bit_Read_Bool=0;
	CDC_Byte_Index=0;
	CDC_Idle=0;
	CDC_Idle_Counter=0;
	CDC_Bit_Index=0;
	CDC_Parity=0;
	Data_2_CDC_Interrupt_Count=0;	
	CDC_Type=0;	
	Key_Code = _NO_KEYCODE;
	
	CDC_Disc_NO=1;
	CDC_Music_NO=1;
	
}

void main ()
{
    BYTE i,j,k;
    MPU_init();
    system_var_init();
    Get_CDC_Type();
    while(1)
    {
        for(i=0;i<0xff;i++)
        {
        	for(j=0;j<0xff;j++)
        	__asm("NOP");
        }
    }
}


extern void  _startup(void);

#pragma section code
void  __interrupt int_dummy(void)
{
}

#pragma	section const vect_const 0xffe0
void * const _inttbl[]={
     INT_CDC_DATA,	    		/* 15 int5(P20) 	*/
	 INT_Test_CDC_BUS,   		/* 14 tc2 	*/
	 int_dummy,	    			/* 13 		*/
	 int_dummy,	    			/* 12 int4 	*/
	 int_dummy,	    			/* 11 P70 	*/
	 int_dummy,					/* 10 tc5 	*/
	 int_dummy,	    			/* 9 sio 	*/
	 INT_MAIN_DATA,   			/* 8 tc3 	*/
	 int_dummy,	    			/* 7 int2 	*/
     INT_ReSend_Data_2_Main,    /* 6 inttbt */
	 int_dummy,	    			/* 5 int1 	*/
     INT_TC1_Send_Data_2_CDC,	/* 4 tc1 	*/
     int_dummy,	    			/* 3 P10 	*/
     int_dummy,    	    		/* 2 intwdt */
     int_dummy,    	    		/* 1 intsw 	*/
     _startup,    	    		/* program  start */
};

⌨️ 快捷键说明

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