|
////////////////////////////////////////////////////// // config.h ///////////////////////////////////////////////////// #ifndef __CONFIG_H #define __CONFIG_H #i nclude <reg52.h> #i nclude <intrins.h> //This segment should not be modified #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif // 數(shù)據(jù)類型定義 typedef unsigned char uint8; /* defined for unsigned 8-bits integer variable 無(wú)符號(hào)8位整型變量 */ typedef char int8; /* defined for signed 8-bits integer variable 有符號(hào)8位整型變量 */ typedef unsigned int uint16; /* defined for unsigned 16-bits integer variable 無(wú)符號(hào)16位整型變量 */ typedef int int16; /* defined for signed 16-bits integer variable 有符號(hào)16位整型變量 */ typedef unsigned long uint32; /* defined for unsigned 32-bits integer variable 無(wú)符號(hào)32位整型變量 */ typedef long int32; /* defined for signed 32-bits integer variable 有符號(hào)32位整型變量 */ typedef float fp32; /* single precision floating point variable (32bits) 單精度浮點(diǎn)數(shù)(32位長(zhǎng)度) */ // 以下用戶的包含文件 #i nclude "si4133.h" #endif ///////////////////////////////////////////////// // SI4133.h ///////////////////////////////////////////////// #ifndef _SI4133_H #define _SI4133_H //Address Define #define Addr_MainConfiguartion 0x0 #define Addr_PhaseDetectorGain 0x1 #define Addr_PowerDown 0x2 #define Addr_RF1_N_Divider 0x3 #define Addr_RF2_N_Divider 0x4 #define Addr_IF_N_Divider 0x5 #define Addr_RF1_R_Divider 0x6 #define Addr_RF2_R_Divider 0x7 #define Addr_IF_R_Divider 0x8 //Command Define //register 0 #define AUXSEL 3 // 1 = AUX force to low // 3 = AUX Lock Detect #define IF_OUT_DIVIDER 0 // 0 = IFout = IFVco Frequency // 1 = IFout = IFVco Frequency / 2 // 2 = IFout = IFVco Frequency / 4 // 3 = IFout = IFVco Frequency / 8 #define LPWR 1 // 0 = Rload < 500 normal power mode // 1 = Rload >= 500 low power mode #define AUTOPDB 1 // 0 = Software powerdown is controlled by register 2 // 1 = All on #define AUTOKP 1 // 0 = auto kp defined by user // 1 = auto kp defined auto #define Cmd_MainConfig ((AUXSEL << 12) + (IF_OUT_DIVIDER << 10) + (LPWR << 5) + \ (AUTOPDB << 3) + (AUTOKP << 2)) //register 1 // N value Kpi #define IF_PHASE_DETECT 0 // <2048 00 // 2048 - 4095 01 // 4096 - 8191 10 // >8191 11 #define RF2_PHASE_DETECT 0 // <4096 00 // 4096 - 8191 01 // 8192 - 16388 10 // >16388 11 #define RF1_PHASE_DETECT 0 // <8192 00 // 8192 - 16383 01 // 16384 - 32767 10 // >32767 11 #define Cmd_PhaseDetect ((IF_PHASE_DETECT << 4) + (RF2_PHASE_DETECT << 2) + RF1_PHASE_DETECT) //register 2 #define PDIB_IF 1 // 0 = IF synthesizer power down // 1 = IF synthesizer on #define PDRB_RF 1 // 0 = RF synthesizer power down // 1 = RF synthesizer on #define Cmd_PowerDown ((PDIB_IF << 1) + PDRB_RF) /************************************************************* *函數(shù)名稱:Si4133_Locked *函數(shù)功能:檢測(cè)鎖定位 *參 數(shù):無(wú) *返 回:TRUE ,鎖定; FALSE ,丟失 *************************************************************/ extern bit Si4133_Locked(void); /************************************************************* *函數(shù)名稱:Si4133_SendData *函數(shù)功能:向Si4133發(fā)送數(shù)據(jù) *參 數(shù):dat,數(shù)據(jù);addr,地址 *返 回:無(wú) *************************************************************/ extern void Si4133_SendData(uint32 dat,uint8 addr); #endif ////////////////////////////////////////////////// // SI4133.c ////////////////////////////////////////////////// /************************************************************* * 公司名稱: * 模 塊 名:SI4133驅(qū)動(dòng)程序 * 創(chuàng) 建 人: * 創(chuàng)建日期:2006/04/26 * 修 改 人: * 修改日期: * 功能描述: * 其他說(shuō)明: * 版 本: *************************************************************/ #i nclude "config.h" #define _Nop() _nop_() //口線定義 sbit SENB = P2^7; // 芯片使能 sbit SCLK = P1^0; // 時(shí)鐘 sbit SDATA = P1^1; // 數(shù)據(jù) sbit AUXOUT = P0^5; // 鎖定測(cè)試 /************************************************************* *函數(shù)名稱:Si4133_Locked *函數(shù)功能:檢測(cè)鎖定位 *參 數(shù):無(wú) *返 回:TRUE ,鎖定; FALSE ,丟失 *************************************************************/ bit Si4133_Locked(void) { AUXOUT = 1; // 斷開(kāi)OC _Nop(); return ((AUXOUT == 0)?TRUE:FALSE); // 返回AUXOUT } /************************************************************* *函數(shù)名稱:Si4133_SendData *函數(shù)功能:向Si4133發(fā)送數(shù)據(jù) *參 數(shù):dat ,數(shù)據(jù) * addr,地址 *返 回:無(wú) *************************************************************/ void Si4133_SendData(uint32 dat,uint8 addr) { uint32 sedata; uint8 i; sedata = ((dat << 4) | (addr & 0x0f)); // 數(shù)據(jù) + 地址 sedata <<= 10; // 左移10位 SENB = 1; SCLK = 0; SDATA = 0; SENB = 0; for(i = 0;i < 22;i++) { SDATA = ((sedata & 0x80000000)?1:0); // 輸出數(shù)據(jù) SCLK = 1; // 上升沿?cái)?shù)據(jù)鎖存 SCLK = 0; sedata <<= 1; } SENB = 1; } |