📄 main.c
字号:
/* ************************************************************************************************
*
* LV2400x Evaluation Kit (LV2400x-EVK)
* File name: main.c
* Authors: Hung van Le
*
* ************************************************************************************************
* Cooperation SANYO Electric Co., Ltd. and Semiconductor Ideas to the Market (ItoM) B.V.
* Copyright(c) 2004. All rights reserved.
* ************************************************************************************************ */
#include <string.h>
//#include <stdio.h> // for sprintf
#include "common.h"
#define _MAIN_MODULE
#include "Lv24Ekit.h"
#include "KeypadDef.h"
#include "LcdDef.h"
#ifdef USE_PRESET
#include "LCFLS.H"
#endif //USE_PRESET
/* Prototype definitions */
void main(void);
// LC87F1564/EVK specific
void InitLc87Clock(void);
void InitLv24EvkSoftware(void);
/* External Functions */
#ifdef USE_USB
extern void USBInitialSetting(void);
extern void EndpointAck(void);
#endif //USE_USB
extern void BusActive(void);
extern void BusReset(void);
extern void BaseTimer(void);
//-----------------------------------------------------------------------------
// Interrupt vectors
//-----------------------------------------------------------------------------
// 0x03 - INT0: keypad row 0 interrupt
void _interrupt(0x03) Int_0x03(void)
{
// HLE added: INT0 interrupt (keypad)
if (_I01CR & (1<<1)) // Check INT0IF bit (interrupt flag)
{
KeypadIrq(KB_ROW_0); // Clear interrupt is done in this routine
}
} // End Int_0x03
// 0x0B - INT1: keypad row 1 interrupt
void _interrupt(0x0B) Int_0x0B(void)
{
// HLE added: INT1 interrupt (keypad)
if (_I01CR & (1<<5)) // Check INT1IF bit (interrupt flag)
{
KeypadIrq(KB_ROW_1); // Clear interrupt is done in this routine
}
} // End Int_0x0B
// 0x13 - BusActive and INT2: keypad row 2 interrupt
void _interrupt(0x13) Int_0x13(void)
{
#ifdef USE_USB
if (_BACEN & _BACFG)
{
BusActive();
}
#endif //USE_USB
// HLE added: INT2 interrupt (keypad)
if (_I23CR & (1<<1)) // Check INT2IF bit (interrupt flag)
{
KeypadIrq(KB_ROW_2); // Clear interrupt is done in this routine
}
#ifdef USE_IRQSCRIPT // External interrupt
if (_I45CR & (1<<1)) // Check INT4IF bit (interrupt flag)
{
ExtRdsIntHandler();
_putbit(0, _I45CR, 1); // Clear interrupt
}
#endif //USE_IRQSCRIPT
} // End Int_0x13
// 0x1B - BaseTimer interrupt
// - INT3: keypad row 3 interrupt
// - INT5: 3-wire 1 interrupt
void _interrupt(0x1b) Int_0x1b(void)
{
#ifdef USE_USB
if (_BTIE1 & _BTIF1)
{
BaseTimer();
}
#endif //USE_USB
// HLE added: INT3 interrupt (keypad)
if (_I23CR & (1<<5)) // Check INT3IF bit (interrupt flag)
{
KeypadIrq(KB_ROW_3); // Clear interrupt is done in this routine
}
// HLE added: INT5 interrupt (3-wire 1 interface)
if (_I45CR & (1<<5)) // Check INT5IF bit (interrupt flag)
{
#ifdef USE_IRQSCRIPT
if (g_byLvIrqFlg & IFL_USBIRQ_INSTALLED) // IRQ meant for USB script
{
// Only handle the interrupt when it's still enabled (ie no suspend-call is done in between)
if ( _I45CR & (1<<4) ) // Bit 4: INT5 is enabled if 1
UsbLvIrqProcess(g_byaIrqScript);// USB mode IRQ
}
else
#endif //USE_IRQSCRIPT
g_byLvIrqFlg |= IFL_CHIP_IRQ_OCC; // Stand alone mode IRQ
_putbit(0, _I45CR, 5); // Clear interrupt
}
} // End Int_0x1b
// 0x33 - BusReset
void _interrupt(0x33) Int_0x33(void)
{
#ifdef USE_USB
BusReset();
#endif //USE_USB
} // End Int_0x33
// 0x3B - EndpointAck
void _interrupt(0x3b) Int_0x3b(void)
{
#ifdef USE_USB
if ( _ENPEN )
{
EndpointAck();
}
#endif //USE_USB
} // End Int_0x3b
// ------- HLE added -----
// 0x23 - Timer 0 interrupt
void _interrupt(0x23) Int_0x23(void)
{
// if (_T0CNT & (1<<3)) // Check T0HCMP bit (High byte matched interrupt flag)
// HandleTimer0Done();
// Counting done when Timer 0 high byte match interrupt
#pragma asm
EXTERN _HandleTimer0Done
BN 0fe10h, 03h, NoTmr0DoneIrq
RCALL _HandleTimer0Done
NoTmr0DoneIrq:
#pragma endasm
} // End Int_0x23
/*=======================================================================
|
| Name: main
| Function:
| Input: None
| Output: None
| Ref.:
| Notice:
|
=======================================================================*/
void main(void)
{
BYTE byTxCnt;
// Init the LC87F1564 clocks
InitLc87Clock();
#ifdef USE_PRESET
// Initialize LC87F1564 flash for W/R settings
InitLcFls();
#endif //USE_PRESET
// ------- Configure the GPIO for LV24-series evalution board (IO map is defined in LV24Ekit.h)
// --- Port 0: not used
//_P0DDR = 0x03; // All bits Output
//_P0 = 0x00; // All lines low
// --- Port 1: LCD and keypad column output
_P1FCR = 0x00; // Port 1 function select: all pins are IO
_P1DDR = 0xFF; // All bit Output
_P1 = 0x00; // All lines low
// --- Port 2: 3-wires bus 1/2 and external RDS
Init3wHardwareIo();
// --- Port 7: Keypad row (input + pullup + Interrupt), disable keypad interrupt
_P7 = 0x0F; // P70..P73: input with pull-up (for using INT0/INT1/INT2/INT3 as row)
// Vector for INT0/INT1/INT2/INT3 is 03h/0Bh/13h/1Bh)
_I01CR = 0x00; // INT0/INT1: interrupt disabled
_I23CR = 0x00; // INT2/INT3: interrupt disabled
// ------ GPIO configuration ----------
// Software init.
InitLv24EvkSoftware();
// Init LCD module
#ifdef USE_LCD
InitLcd();
// Show sign on strings
PrintString(CURS_HOME, STR_SIGNON1);
PrintString(CURS_1_0, STR_VERSION);
PrintString(CURS_CURPOS, STR_SIGNON2);
#endif //USE_LCD
// Enable Interrupt
_IE = 0x80;
// Init USB hardware
#ifdef USE_USB
USBInitialSetting();
#endif //USE_USB
// Some settings must be retrieved before chip initialization
#ifdef USE_PRESET
// Retrieve external clock setting as it's used by calibrating IF/Stereo decoder clock
RetrieveSettingsFromFlash(IHCAP_EXTCLK);
#endif //USE_PRESET
// ---- Radio device initialisation ----
InitLv2400xChip(); // Init Radio chip for stand alone mode
// The following statements are part of the initialisation. For LV24-EVK we do it in SetOperateMode
//SetFrequency(g_wDisplayBandLow); // Set the default FM frequency
//SetHwFeatureValue(IHCAP_AMUTE, 0); // The LV2400x is ready, un-mute audio
// LV24-EVK only
g_wLastSetRF = DisplayFreqToRf(g_wDisplayBandLow); // Just fill the default RF value, SetOperateMode will set it
// ---- End Radio init.
// Retrieve all settings from last run
#ifdef USE_PRESET
RetrieveSettingsFromFlash(RSFF_ALL);
#endif //USE_PRESET
// Set operation mode - default is stand alone
SetOperateMode(OPM_STAND_ALONE);
// Main loop
for(;;)
{
// ------ USB handling
#ifdef USE_USB
if (g_byUsbRxCnt != 0) // Something received from USB-3W host
{
// Disable the chip interrupt before doing anything else
//if (g_byLvIrqFlg & IFL_CHIP_IRQ_EN)
// DisableLv2400xIrq();
// Dispatch the command
byTxCnt = UsbProcess3wCmd(g_byUsbRxCnt);
g_byUsbRxCnt = 0; // Indicate command is processed
// Send reply if necessary
if (byTxCnt != 0)
{
SendReply(USB_REPLY_PACKET_SIZE); //@@@ TEMP. Always send 32 byte to keep USB-3W host happy
//SendReply(byTxCnt);
}
// Re-enable chip interrupt if it was enabled
//if (g_byLvIrqFlg & IFL_CHIP_IRQ_EN)
// EnableLv2400xIrq();
} // End USB handling
if ( g_bySwFlag1 & SF1_USB_HOST_CON )
continue; // Skip checking keypad/LV2400x interrupt (NA in USB-mode)
#endif //USE_USB
// ------ Keypad handling
if (g_byPressedKey != KP_NO_KEY)
{
// Disable the chip interrupt before doing anything else
if (g_byLvIrqFlg & IFL_CHIP_IRQ_EN)
DisableLv2400xIrq();
// Save new key
byTxCnt = g_byPressedKey;
// Mark key is handled
g_byPressedKey = KP_NO_KEY;
// Process new key
ProcessKey(byTxCnt);
// Re-enable chip interrupt if it was enabled
if (g_byLvIrqFlg & IFL_CHIP_IRQ_EN)
EnableLv2400xIrq();
} // End keypad handling
// ------ Chip interrupt handling
if (g_byLvIrqFlg & IFL_CHIP_IRQ_OCC)
{
// Disable the chip interrupt before doing anything else
DisableLv2400xIrq();
// Handle the interrupt
HandleLv2400xIrq();
// Handling done - clear the interrupt flag
g_byLvIrqFlg &= (~IFL_CHIP_IRQ_OCC);
// Re-enable the chip interrupt
EnableLv2400xIrq();
} // End chip interrupt handling
/*
// let the uC enter halt-mode for power saving
if ( (g_bySwFlag1 & SF1_USB_HOST_CON) == 0 )
{
//_PCON = 0x06; // Set bit 2 (XTIDLE) and bit 1 (PDN) to enter Xtal hold mode
// // Xtal hold mode here
//_PCON = 0x00; // Clear bit 2 (XTIDLE) and bit 1 (PDN) to exit Xtal hold mode
_PCON = 0x01; // Set bit 0 (IDLE) to enter halt-mode
}
*/
} // End ForEver
}// End main
void SetOperateMode(BYTE byMode)
{
if (byMode == OPM_STAND_ALONE)
{
#ifdef USE_USB
// Do quick chip init (just restore the shadow registers)
RestoreShadowReg();
// Turn on device power and un-mute the audio because these were turned off by DeInitLv2400xChip
SetHwFeatureValue(IHCAP_TUNERPWR, 1); // turn on tuner's power
SetFrequency(RfToDisplayFreq(g_wLastSetRF)); // Set last used frequency
SetHwFeatureValue(IHCAP_AMUTE, 0); // un-mute audio
#endif //USE_USB
#ifdef USE_LCD
// Show stand alone mode screen
ShowStandAloneScreen();
// Show menu
InitKeypadMenu();
#endif //USE_LCD
// Enable LV2400x interrupt for stand alone mode
EnableLv2400xIrq();
// Enable keypad interrupt for stand alone mode
_I01CR = 0x11; // INT0/INT1: falling edge - interrupt enabled
_I23CR = 0x55; // INT2/INT3: falling edge - interrupt enabled
}
else // USB_MODE
{
g_wLastSetRF = g_wLastMsrRF; //@@@ TEMP. for restore frequency when switch back to stand alone!!!
// De-init the chip
DeInitLv2400xChip();
//DisableLv2400xIrq(); this is done in DeInit
//g_byLvIrqFlg &= (~IFL_CHIP_IRQ_EN);
// Disable keypad interrupt
_I01CR = 0;
_I23CR = 0;
// Show USB screen
#ifdef USE_LCD
ShowUsbModeScreen();
#endif //USE_LCD
}
} // End SetOperateMode
void InitLc87Clock(void)
{
// Config several clocks of the LC87F1564
BYTE i;
// Config the CF-clock
#ifdef CF8MHZ
_PLLCNT = 0x00; // 8MHz oscillation (as stated by Kaori - 14-May-2004)
#endif //CF8MHZ
#ifdef CF12MHZ
_PLLCNT = 0x80; // 12MHz oscillation ES2
#endif //CF12MHZ
for (i = 0; i < 100; i++)
{
// wait for OSC stable
}
// Program the OCR
_OCR = 0x90;
// BaseTimer setting
// 1Tcyc(ns.) 2048Tcyc(us.)
// - 6MHz : 500 1024
// - 8MHz : 375 768
// - 12MHz : 250 512
_BTIMC0 = 1;
_BTC11 = 1;
_BTC10 = 1;
// BaseTimer starts
_BTON = 1;
_BTIE1 = 1;
_putbit(1,_UOUT,2); // 僆乕僨傿僆僋儘僢僋敪怳
} // End InitLc87Clock
void InitLv24EvkSoftware(void)
{
#ifdef USE_EXTCLK
g_bySwFlag1 = EXTCLK_12MHz; // Use 12MHz external measuring clock as default
#else //USE_EXTCLK
g_bySwFlag1 = 0; // Reset our software flags
#endif //USE_EXTCLK
g_byLvIrqFlg = 0; // Clear all LV24xxx IRQ flags
g_byPressedKey = KP_NO_KEY; // Mark no key pressed yet
g_byMenu = 0; // Default keypad menu
g_byNrPressed = 0; // Last numeric key
g_byInpPos = 0; // Current frequency input position
/*
g_byaInp[0] = 0; // Default input frequency 088.00 MHz
g_byaInp[1] = 8;
g_byaInp[2] = 8;
g_byaInp[3] = 0;
g_byaInp[4] = 0;
*/
g_byCurPreset = 0; // Current preset location for scrolling preset
} // End InitLv24EvkSoftware
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -