📄 72131-c51.txt
字号:
//------------------------------------------------------------------------ /**************************************************************************
// Tuner, VER 1.0
//
// COPYRIGHT (C) 2002, Enbia Technology Inc.
// Target: 89C5X, PLL IC: LC72130/LC72130M
// AUTHOR: STEVEN LUO
//
// Revision History:
// 2000/12/16 - Original Version
// 2001/4/3 - V2.0, ported to RTX51TNY
//
//------------------------------------------------------------------------
#include <reg51.h>
#include <types.h>
#include <intrins.h>
#include <rtx51tny.h>
#include "tuner_int.h"
#include "dspenm.h"
//---------------------------------------------------------------------------
// Tuner_Initialize
//---------------------------------------------------------------------------
void Tuner_Initialize(void){
b_amstep = Read_EEPROM(EE_AMSTEP) & 0x01;
band = Read_EEPROM(EE_BAND) & 0x01;
cur_count[band] = Read_EEPROM(EE_CURCNT_LOW) + Read_EEPROM(EE_CURCNT_HIGH) * 0x100;
Tuner_Set_Frequency_Int();
dwPLL_Shadow_IN2 |= BO2_ON; // Unmute
Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
}
//---------------------------------------------------------------------------
// Tuner_Shutdown
//---------------------------------------------------------------------------
void Tuner_Shutdown(BOOL bonoff){
if (bonoff){
Write_LC72131(MODE_IN1, (dwPLL_Shadow_IN1 & 0x0fffff) | PLL_OFF_REF);
}
else{
Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
}
}
//---------------------------------------------------------------------------
// Tuner_Set_AMStep
//---------------------------------------------------------------------------
BOOL Tuner_Set_AMStep(BYTE ctrl){
if (ctrl != INQUIRE){
b_amstep = ! b_amstep;
Write_EEPROM(EE_AMSTEP, b_amstep);
}
return b_amstep;
}
//---------------------------------------------------------------------------
// Tuner_Set_FMStep
//---------------------------------------------------------------------------
BOOL Tuner_Set_FMStep(BYTE ctrl){
if (ctrl != INQUIRE){
b_fmstep = ! b_fmstep;
}
return b_fmstep;
}
//---------------------------------------------------------------------------
// Tuner_Set_Band
//---------------------------------------------------------------------------
BYTE Tuner_Set_Band(BYTE ctrl, WORD *freq){
if (ctrl != INQUIRE){
Temp_Mute(1);
if (band != BAND_AM) band = BAND_AM; else band = BAND_FM; // 0: am, 1: fm
Write_EEPROM(EE_BAND, band);
Tuner_Set_Frequency_Int();
dwPLL_Shadow_IN2 |= BO2_ON; // Unmute
Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
Temp_Mute(0);
}
*freq = (Count_To_Freq());
return band;
}
//---------------------------------------------------------------------------
// Tuner_Set_Mono
//---------------------------------------------------------------------------
BOOL Tuner_Set_Mono(BYTE ctrl){
if (ctrl != INQUIRE){
Temp_Mute(1);
bST_MONO = ! bST_MONO;
dwPLL_Shadow_IN2 &= ~BO3_ON;
if (bST_MONO) {dwPLL_Shadow_IN2 |= BO3_ON;} // Stereo
// Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
Temp_Mute(0);
}
return bST_MONO;
}
//---------------------------------------------------------------------------
// Tuner_Save_Station
//---------------------------------------------------------------------------
void Tuner_Save_Station(BYTE station){
BYTE ee_addr;
if (station > MAX_PRESET_NUMBER) station = MAX_PRESET_NUMBER;
ee_addr = EE_PRESET_BASE + band * (MAX_PRESET_NUMBER + 1) * 2 + station *2;
Write_EEPROM(ee_addr, cur_count[band]/0x100); Write_EEPROM(ee_addr +1, cur_count[band]&0xff);
}
//---------------------------------------------------------------------------
// Tuner_Restore_Station
//---------------------------------------------------------------------------
WORD Tuner_Restore_Station(BYTE station){
BYTE ee_addr;
Temp_Mute(1);
if (station > MAX_PRESET_NUMBER) station = MAX_PRESET_NUMBER;
ee_addr = EE_PRESET_BASE + band * (MAX_PRESET_NUMBER + 1) * 2 + station *2;
cur_count[band]= Read_EEPROM(ee_addr) * 0x100 + Read_EEPROM(ee_addr +1);
Tuner_Set_Frequency_Int();
dwPLL_Shadow_IN2 |= BO2_ON; // Unmute
Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
// save the current count
Write_EEPROM(EE_CURCNT_LOW, cur_count[band] & 0xff); Write_EEPROM(EE_CURCNT_HIGH, cur_count[band] >> 8);
Temp_Mute(0);
return (Count_To_Freq());
}
//---------------------------------------------------------------------------
// Tuner_Set_Frequency
//---------------------------------------------------------------------------
WORD Tuner_Set_Frequency(BYTE ctrl, WORD freq){
BAND_INFO code *pBInfo;
switch(band){
case BAND_AM:
if (b_amstep) pBInfo = &BandInfo_AM_10KHz; else pBInfo = &BandInfo_AM_9KHz; break;
case BAND_FM:
if (b_fmstep) pBInfo = &BandInfo_FM_100KHz; else pBInfo = &BandInfo_FM_50KHz; break;
case BAND_SW:
break;
}
switch (ctrl){
case INQUIRE:
return (Count_To_Freq()); break;
case UP:
cur_count[band] += pBInfo -> CntStep; break;
case DOWN:
cur_count[band] -= pBInfo -> CntStep; break;
case SET:
if ((band == BAND_AM) || (band == BAND_SW)){
//return cur_count[band] * pBInfo -> FRef - 450;
cur_count[band] = (freq + 450) / (pBInfo -> FRef);
}
else {
//return cur_count[band] * ((FM_FREF *100)/1000) - 1070;
cur_count[band] = ((freq + 1070) * 1000) / (FM_FREF *100);
}
break;
}
Tuner_Set_Frequency_Int();
dwPLL_Shadow_IN2 |= BO2_ON; // Unmute
Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
// save the current count
Write_EEPROM(EE_CURCNT_LOW, cur_count[band] & 0xff); Write_EEPROM(EE_CURCNT_HIGH, cur_count[band] >> 8);
return (Count_To_Freq());
}
//---------------------------------------------------------------------------
// Tuner_Step
//---------------------------------------------------------------------------
WORD Tuner_Step(BYTE ctrl){
if (ctrl != SET)return Tuner_Set_Frequency(ctrl, 0);
}
//---------------------------------------------------------------------------
// Tuner_Scan
//---------------------------------------------------------------------------
int Tuner_Scan(BYTE ctrl){
BAND_INFO code *pBInfo;
WORD temp;
register BYTE j;
switch(band){
case BAND_AM:
if (b_amstep) pBInfo = &BandInfo_AM_10KHz; else pBInfo = &BandInfo_AM_9KHz; break;
case BAND_FM:
if (b_fmstep) pBInfo = &BandInfo_FM_100KHz; else pBInfo = &BandInfo_FM_50KHz; break;
case BAND_SW:
break;
}
if (ctrl == INQUIRE){
return (Count_To_Freq());
}
else if (ctrl == UP){
cur_count[band] += pBInfo -> CntStep;
}
else if (ctrl == DOWN){
cur_count[band] -= pBInfo -> CntStep;
}
// Temp_Mute(1);
Tuner_Set_Frequency_Int();
Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
// Wait PLL Lock -----------------------------------------------------------
Pause(1); //
for (j=0; j<255; j++){
if (PIN_TUNER_DO)break;
}
dwPLL_Shadow_IN2 &= DO_MODE_MASK; // set DO mode, end uc
dwPLL_Shadow_IN2 |= DO_MODE_END_UC;
dwPLL_Shadow_IN1 |= CTE_ON; // IF count start
Write_LC72131(MODE_IN1, dwPLL_Shadow_IN1);
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
// Wait Gate over -----------------------------------------------------
for (j=0; j<10; j++){
if (!PIN_TUNER_DO) break; // break when gate ends
os_wait2(K_TMO, 1);
}
// Gate time over
temp = Read_72131() & 0x0fffff;
dwPLL_Shadow_IN2 |= BO2_ON; // Unmute
Write_LC72131(MODE_IN2, dwPLL_Shadow_IN2);
// save the current count
Write_EEPROM(EE_CURCNT_LOW, cur_count[band] & 0xff); Write_EEPROM(EE_CURCNT_HIGH, cur_count[band] >> 8);
if ((temp >= pBInfo -> IFCntMin) && (temp <= pBInfo -> IFCntMax)){
return -(Count_To_Freq());
}
else {
return (Count_To_Freq());
}
}
//---------------------------------------------------------------------------
// Tuner_Get_Stereo
//---------------------------------------------------------------------------
BOOL Tuner_Get_Stereo(void){
if (band == BAND_FM) {
return (!(Read_72131() & 0x800000));
}
else
return 0;
}
//---------------------------------------------------------------------------
// Tuner_Set_Frequency_Int
//---------------------------------------------------------------------------
static void Tuner_Set_Frequency_Int(void){
BAND_INFO code *pBInfo;
switch(band){
case BAND_AM:
if (b_amstep) pBInfo = &BandInfo_AM_10KHz; else pBInfo = &BandInfo_AM_9KHz; break;
case BAND_FM:
if (b_fmstep) pBInfo = &BandInfo_FM_100KHz; else pBInfo = &BandInfo_FM_50KHz; break;
case BAND_SW:
break;
}
dwPLL_Shadow_IN1 = 0; dwPLL_Shadow_IN2 = 0;
// Check Boundary -----------------------------------------------------
if (cur_count[band] > pBInfo -> CntMax){
cur_count[band] = pBInfo -> CntMin; // Cycling
}
else if (cur_count[band] < pBInfo -> CntMin){
cur_count[band] = pBInfo -> CntMax; // Cycling
}
// IN2 Mode -----------------------------------------------------------
dwPLL_Shadow_IN2 |= GATE_TIME_32MS; // Gate Time = 4ms
dwPLL_Shadow_IN2 |= 0x100000; // IFS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -