📄 config.h
字号:
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "C8051F120.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Reset_Sources_Init()
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Timer_Init()
{
SFRPAGE = TMR3_PAGE;
TMR3CN = 0x04;
TMR3CF = 0x08;
RCAP3L = 0x90;
RCAP3H = 0xf7; //40k
TMR3H = 0x00;
}
void Port_IO_Init()
{
// P0.0 - TX0 (UART0), Push-Pull, Digital
// P0.1 - RX0 (UART0), Push-Pull, Digital
// P0.2 - INT0 (Tmr0), Push-Pull, Digital
// P0.3 - Unassigned, Push-Pull, Digital
// P0.4 - Unassigned, Push-Pull, Digital
// P0.5 - Unassigned, Push-Pull, Digital
// P0.6 - Unassigned, Push-Pull, Digital
// P0.7 - Unassigned, Push-Pull, Digital
// P1.0 - Unassigned, Push-Pull, Digital
// P1.1 - Unassigned, Push-Pull, Digital
// P1.2 - Unassigned, Push-Pull, Digital
// P1.3 - Unassigned, Push-Pull, Digital
// P1.4 - Unassigned, Push-Pull, Digital
// P1.5 - Unassigned, Push-Pull, Digital
// P1.6 - Unassigned, Push-Pull, Digital
// P1.7 - Unassigned, Push-Pull, Digital
// P2.0 - Unassigned, Push-Pull, Digital
// P2.1 - Unassigned, Push-Pull, Digital
// P2.2 - Unassigned, Push-Pull, Digital
// P2.3 - Unassigned, Push-Pull, Digital
// P2.4 - Unassigned, Push-Pull, Digital
// P2.5 - Unassigned, Push-Pull, Digital
// P2.6 - Unassigned, Push-Pull, Digital
// P2.7 - Unassigned, Push-Pull, Digital
// P3.0 - Unassigned, Push-Pull, Digital
// P3.1 - Unassigned, Push-Pull, Digital
// P3.2 - Unassigned, Push-Pull, Digital
// P3.3 - Unassigned, Push-Pull, Digital
// P3.4 - Unassigned, Push-Pull, Digital
// P3.5 - Unassigned, Push-Pull, Digital
// P3.6 - Unassigned, Push-Pull, Digital
// P3.7 - Unassigned, Push-Pull, Digital
SFRPAGE = CONFIG_PAGE;
P0MDOUT = 0x7F;
P1MDOUT = 0xFF;
P2MDOUT = 0x00;
P3MDOUT = 0x00;
P4MDOUT = 0xFF;
P5MDOUT = 0x7f;
P6MDOUT = 0x00;
P7MDOUT = 0xFF;
XBR0 = 0x04;
XBR1 = 0x04;
XBR2 = 0x40;
}
void Oscillator_Init()
{
int i = 0;
SFRPAGE = CONFIG_PAGE;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
OSCICN = 0x83;
PLL0CN = 0x04;
CCH0CN &= ~0x20;
SFRPAGE = LEGACY_PAGE;
FLSCL = 0xB0;
SFRPAGE = CONFIG_PAGE;
CCH0CN |= 0x20;
PLL0CN |= 0x01;
PLL0DIV = 0x01;
PLL0FLT = 0x01;
PLL0MUL = 0x04;
for (i = 0; i < 15; i++); // Wait 5us for initialization
PLL0CN |= 0x02;
while ((PLL0CN & 0x10) == 0);
CLKSEL = 0x02;
}
void Interrupts_Init()
{
IE = 0x81;
EIE2 = 0x01;
IP = 0x01;
EIP2 = 0x00;
IT0 = 1;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Reset_Sources_Init();
Timer_Init();
Port_IO_Init();
Oscillator_Init();
Interrupts_Init();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -