www.pudn.com > HT1621Control.rar > dts_task.c


/*C************************************************************************** 
* NAME:         dts_task.c 
*---------------------------------------------------------------------------- 
* Copyright (c) 2006 Atmel. 
*---------------------------------------------------------------------------- 
* RELEASE:      C51 Sample       
* REVISION:     1.00      
*---------------------------------------------------------------------------- 
* 
*****************************************************************************/ 
 
/*_____ N O T E _____________________________________________________________ 
	The DTS radio ststem is user SANYO LC72131 
									 
	IN1 Mode have 32 bit data 
	1 byte address + 3 byte data 
	The address is 14H(bit0 to bit7) 
	P0~P16 is divider value(bit8 to bit23) 
 
	Ferquency range setup 
	SNS is bit24 
	DVS is bit25 
	SNS=*,DVS=1 is FM 10MHz to 180MHz 
	SNS=1,DVS=0 is AM 2MHz to 40MHz 
	SNS=0,DVS=0 is AM 0.5MHz to 10MHz 
 
	IF counter control data (CET) 
	CET is bit26 
	CET=0 is counter reset 
	CET=1 is counter Start 
 
	Crystal resonator selection(XS) 
	XS is bit27 
	XS=0 is selection 4.5MHz 
	XS=1 is selection 7.2MHz 
	The 7.2MHz frequecy is selection after the power-on reset 
 
	Reference divider data R0 to R3(bit28 to bit31) 
	RS0=0, RS1=0,RS2=0,RS3=0 is 100KHz,FM is user 
	RS0=0, RS1=0,RS2=0,RS3=1 is 50KHz,FM is user 
	RS0=1, RS1=0,RS2=0,RS3=0 is 10KHz,AM is user 
	RS0=1, RS1=0,RS2=0,RS3=1 is 9KHz,AM is user 
		 
	 
	IN2 Mode have 32 bit data 
	1 byte address + 3 byte data 
	The address is 94H(bit0 to bit7) 
	3 byte  is value(bit8 to bit23) 
 
	IOC0,IOC1 is direction of serial data(bit8 to bit9) 
	IOC0 is LC72131 pin10 to  
	IOC1 is LC72131 pin11 to  
 
	Io0,IO1 is out states(bit10 to bit11) 
	IOC0 is LC72131 pin10 
	IOC1 is LC72131 pin11 
  
	B01 to B04 is Dedicated(bit12 to bit15) 
	DNS is do not care(bit16) 
 
	DOC0 to DOC2 is DO pin control data(bit17 to bit19) 
 
	UL0 to UL1 is selects the phase error detection widthfor checking PLL lock(bit20to bit21) 
 
	DZ0,DZ1 is phase comparatorcontrol data(bit22 to bit23) 
 
	GT0,GT1 is IF counter time setup(bit24 to bit25) 
 
	TBC is clock time base(bit26) 
 
	DLC is charge pump control data(bit27) 
 
	IFS is IF counter control data(bit28) 
 
	TEST0 to TEST3 is test data, set to 0(bit29 to bit31) 
 
	DO0 Mode is data output ,have 32 bit data 
	1 byte address + 3 byte data 
	The address is 54H(bit0 to bit7)	 
___________________________________________________________________________*/ 
 
 
/*_____ I N C L U D E S ____________________________________________________*/ 
 
#include "system\reg51.h" 
#include "system\compiler.h" 
#include "system\config.h" 
#include "driver\io_def.h" 
#include "dts_task.h"                      /* displayer task definition */ 
#include "driver\dts_drv.h" 
/*_____ M A C R O S ________________________________________________________*/ 
 
 
/*_____ D E F I N I T I O N ________________________________________________*/ 
 
 
 
/*F************************************************************************** 
* NAME: disp_task_init 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task initialization 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_task_init (void) 
{ 
	DTS_DIN = 1; 
	DTS_DOUT = 1;  
	DTS_CLK = 1; 
	DTS_CE = 0; 
	Mem_add = Mem_StartAdd; /* DTS setp at 24c02 start address */ 
	DtsMen_flag = Low;		/* DTS mem pointer flag initializtion */ 
	dts_frequency = DTS_FreStart;		/* DTS frequency value initializtion */ 
	dts_MemInit(); 
	dts_GetFer(); 
 
} 
 
/*F************************************************************************** 
* NAME: dts_task 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task handling display of clock and scrolling of file name 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_task (void) 
{ 
	; 
} 
 
/*F************************************************************************** 
* NAME: dts_divider 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task handling display of clock and scrolling of file name 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_divider (void) 
{ 
	int temp; 
 
	if(!DtsMen_flag) temp = (dts_frequency + 107); 
		else temp = (Mem_frequency + 107); 
	DTS_buffer[0] = temp&0x0ff; 
	DTS_buffer[1] = temp>>=8&0x0ff; 
} 
 
/*F************************************************************************** 
* NAME: dts_FerInc 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task handling display of clock and scrolling of file name 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_FerInc (void) 
{ 
	if(dts_frequency < DTS_FreEnd){ 
		dts_frequency ++; 
		} 
} 
 
/*F************************************************************************** 
* NAME: dts_FerDec 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task handling display of clock and scrolling of file name 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_FerDec (void) 
{ 
	if(dts_frequency > DTS_FreStart){ 
		dts_frequency --; 
		} 
} 
/*F************************************************************************** 
* NAME: dts_GetFer 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task initialization 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_GetFer (void) 
{ 
	dts_divider(); 
	DTS_buffer[2] = 0x12; 
	DTS_buffer[3] = 0xa3; 
	DTS_buffer[4] = 0xf4; 
	DTS_buffer[5] = 0x10; 
 
	dts_In1mode(); 
	dts_In2mode(); 
 
} 
 
 
 
/*F************************************************************************** 
* NAME: dts_MemWriteFer 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task initialization 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_MemWriteFer (void) 
{ 
	int temp; 
 
	if(Mem_add < Mem_EndAdd){ 
		temp = dts_frequency; 
		temp = 	temp&0x0ff;		/* sent low byte */ 
		Mem_add = Mem_add + 1; 
		I2c_WriteByte (Mem_add, temp); 
		temp = dts_frequency; 
		temp = (temp>>=8 &0x0ff);	/* sent high byte */ 
		Mem_add = Mem_add + 1; 
		I2c_WriteByte (Mem_add, temp); 
		} 
} 
 
/*F************************************************************************** 
* NAME: dts_MemWriteFer 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task initialization 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_MemReadFer (void) 
{ 
	char temp; 
 
	if(Mem_add > Mem_StartAdd){ 
		Mem_add = Mem_add-1; 
		temp = I2c_ReadByte(Mem_add); 
		Mem_frequency =temp &0x0ff; 
		Mem_frequency <<= 8; 
		Mem_add = Mem_add-1; 
		temp = I2c_ReadByte(Mem_add); 
		Mem_frequency |= (temp &0x0ff); 
		//if((Mem_frequency>1080)||(878>=8&0x0ff; 
	I2c_WriteByte (address, DTS_buffer[0]); 
	I2c_WriteByte (address, DTS_buffer[1]); 
} 
/*F************************************************************************** 
* NAME: AutoScan 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Display task initialization 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
*****************************************************************************/ 
void dts_AutoScan (void) 
{ 
 
	dts_divider(); 
	DTS_buffer[2] = 0x16;//0x12//0x16 
	DTS_buffer[3] = 0xa3;//0xa3//0x83 
	DTS_buffer[4] = 0xf4;//0xf4//0xf2 
	DTS_buffer[5] = 0x10;//0x10//0x18(IFS) 
 
	dts_In1mode(); 
	dts_In2mode(); 
	 
	//DTS_CE = 0; 
	//getByteLSB(0x2a); 
	//DTS_CE = 1; 
	DelayX1ms(20); 
	//for(i=0;i<2;i++){ 
	DTS_CE = 1; 
	//DelayX1ms(20); 
	//DTS_CE = 1; 
	//DTS_DIN = 1; 
	//while(!DTS_DIN){;} 
 
	//DTS_CLK = High; 
	//DTS_CE = 0; 
	getByteLSB(0x2a); 
	//DTS_CE = 1; 
	DTS_DIN = 1; 
	DTS_buffer[3] = dts_scanByte(); 
	DTS_buffer[4] = dts_scanByte(); 
	DTS_buffer[5] = dts_scanByte(); 
	DTS_CE = 0; 
	//DTS_DIN = 1; 
	//} 
	dts_GetFer(); 
	//temp0 >>= 3; 
	DTS_buffer[3] &= 0x0f;  
	//ht1621disp_Buffer[1] = ht1621disp_Map[DTS_buffer[3]/10]; 
	//ht1621disp_Buffer[2] = ht1621disp_Map[DTS_buffer[3]%10]; 
	//HT1621_getdata(HT1621SEC_ADDH,ht1621disp_Buffer[1]); 
	//HT1621_getdata(HT1621SEC_ADDL,ht1621disp_Buffer[2]); 
	HT1621_getdata(HT1621SEC_ADDH,ht1621disp_Map[DTS_buffer[3]/10]); 
	HT1621_getdata(HT1621SEC_ADDL,ht1621disp_Map[DTS_buffer[3]%10]); 
}