📄 system_init.bak
字号:
void hdwinit( void ) //PM == 0 output
{
DI();
IMS = MEMORY_IMS_SET;
IXS = MEMORY_IXS_SET;
// Clock operation port mode (OSCCTL register)
AMPH = 0; // select the external Clock frequency range(4MHz < fXH <= 10MHz)
EXCLK = 0; //select the externa High-speed system clock operation mode(fX or fEXCLK or STOP)
OSCSEL = 1; // External resonator connected to fX1 and fX2 input
EXCLKS = 0; //(fXT or fEXCLKS or STOP)
OSCSELS = 0; // XT1 stop working
// (permit) High-speed input clock operating (X1)
MOC = 0x00;
// 00000000 = 0x00
// |------- High-speed input clock operation
// |------- --------------------------------
// |------- fXH input clock | External clock input
// |------- ----------------------------+-------------------------
// 0 -------- fXH input clock oscillating | External clock operating
// 1 -------- fXH input clock stopped | External clock stopped
// Check Oscillation stabilization time status
//waiting for the X1 clock oscillation stabilization time
//--------------------------------------------
// The necessary oscillation stabilization time must be known beforehand.
// Pls. refer to the DS or UM of the oscillator manufacturer.
while(OSTC < 0x1f) // Wait until fXH clock stabilization
{ // time has been elapsed
//----------------------------------------------------------
// During X1 oscillation stabilization time status check
// some other initializations, e.g. ports, can be done,
// dependent on the needed X1 oscillation stabilization time
// 102.4祍...3.28ms @ 20MHz
//----------------------------------------------------------
NOP();
}
//Oscillation stabilization time after STOP mode release
//The wait time set by OSTS is valid only after the STOP mode is released with the X1 clock selected as the CPU clock.
OSTS = 0x01; // 512us@4MHz wait after STOP mode release (RESET value)
// 00000101 = 0x05
// -----||| Osc. stabilization time
// -----||| -----------------------
// -----001 - 2^11/fx
// -----010 - 2^13/fx
// -----011 - 2^14/fx
// -----100 - 2^15/fx
// -----101 - 2^16/fx
// -----other settings prohibited
//This register is used to select the CPU clock and the division ratio
//---------------------------------------------
PCC = 0x00; // Use high speed mode fCPU = 4MHz
// 00000000 = 0x00
// -----||| CPU clock selection fCPU
// -----||| ------------------------
// -----000 - fx
// -----001 - fx/2
// -----010 - fx/2^2
// -----011 - fx/2^3
// -----100 - fx/2^4
// -----other settings prohibited
// selects the main system clock supplied to CPU clock and clock supplied to peripheral hardware clock.
//-----------------------------------------------------------------
// The maximum time required to switch between ring oscillator clock and
// fXH clock is 2 clocks
// fXH clock supplied to the peripherals
XSEL = 1;
do
{
MCM0 = 1; // fXH clock supplied to CPU
// 00000001 = 0x01
// -----||| CPU clock status
// -----||| ----------------
// -----||0 - Operates with ring oscillator clock
// -----||1 - Operates with X1 input clock
// -----||
// -----|| Selection of clock supplied to CPU and peripherals
// -----|| --------------------------------------------------
// -----00 -- fCPU = fRH / fPRS = fRH
// -----01 -- fCPU = fRH / fPRS = fRH
// -----10 -- fCPU = fRH / fPRS = fXH
// -----11 fCPU = fXH / fPRS = fXH <---
// |
// +---- XSEL
}
while(MCS != 1); // Check if CPU operates with fXH clock( bit MCS IS read-only)
// If no => Retry to switch CPU clock
// If yes => continue
// Switch off the high-speed and the low-speed Ring-OSC
//-----------------------------------------------------
// select the operation mode of internal oscillator (all stop)
RCM = 0x01; // High-speed Ring-OSC oscillating
// High-speed Ring-OSC low accuracy (stop)
// Low-speed Ring-OSC oscillating (stop)
// 00000000 = 0x00
// |-----|| High-speed Ring-OSC operation
// |-----|| -----------------------------
// |-----|0 - High-speed Ring-OSC oscillating
// |-----|1 - High-speed Ring-OSC stopped
// |-----|
// |-----| Low-speed Ring-OSC operation
// |-----| ----------------------------
// |-----0 -- Low-speed Ring-OSC oscillating
// |-----1 -- Low-speed Ring-OSC stopped
// |
// | High-speed Ring-OSC accuracy status
// | -----------------------------------
// 0 -------- High-speed Ring-OSC low accuracy
// 1 -------- High-speed Ring-OSC high accuracy
EI();
}
void Lvi_Init( void )
{
LVIMK = 1; //disable LVI interrupt
LVISEL = 0; //Detect level of supply voltage
LVIS = 0X02; //detection voltage level:3.93V
//LVIIF = 0;
//LVIMK = 0;
//LVIPR = 1;
LVIMD = 0; //generates intenal reset when the level is detected
LVION = 1; //enable LVI operation
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -