📄 f12x_init.lst
字号:
C51 COMPILER V8.08 F12X_INIT 11/04/2008 15:15:23 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE F12X_INIT
OBJECT MODULE PLACED IN F12x_Init.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.exe F12x_Init.c DB OE
line level source
1 //-----------------------------------------------------------------------------
2 // F12x_Init.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2006 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // Contains Initialization Routines for the F120.
10 //
11 // FID:
12 // Target: C8051F12x
13 // Tool chain: Keil C51 7.20 / Keil EVAL C51
14 // Silicon Laboratories IDE version 2.72
15 // Command Line: See Readme.txt
16 // Project Name: CP220x_Ethernet_Routines
17 //
18 //
19 //
20 // Release 1.1
21 // - Configures C8051F120 SYSCLK to 98 MHz
22 //
23 // Release 1.0
24 // -Initial Release (FB)
25 // -30 MAY 2006
26 //
27
28 //-----------------------------------------------------------------------------
29 // Includes
30 //-----------------------------------------------------------------------------
31 #include "global.h"
32
33 #if(MCU == F120)
//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F12x
//-----------------------------------------------------------------------------
sfr16 DP = 0x82; // data pointer
sfr16 ADC0 = 0xbe; // ADC0 data
sfr16 ADC0GT = 0xc4; // ADC0 greater than window
sfr16 ADC0LT = 0xc6; // ADC0 less than window
sfr16 RCAP2 = 0xca; // Timer2 capture/reload
sfr16 RCAP3 = 0xca; // Timer3 capture/reload
sfr16 RCAP4 = 0xca; // Timer4 capture/reload
sfr16 TMR2 = 0xcc; // Timer2
sfr16 TMR3 = 0xcc; // Timer3
sfr16 TMR4 = 0xcc; // Timer4
sfr16 DAC0 = 0xd2; // DAC0 data
sfr16 DAC1 = 0xd2; // DAC1 data
sfr16 PCA0CP5 = 0xe1; // PCA0 Module 5 capture
sfr16 PCA0CP2 = 0xe9; // PCA0 Module 2 capture
sfr16 PCA0CP3 = 0xeb; // PCA0 Module 3 capture
sfr16 PCA0CP4 = 0xed; // PCA0 Module 4 capture
sfr16 PCA0 = 0xf9; // PCA0 counter
C51 COMPILER V8.08 F12X_INIT 11/04/2008 15:15:23 PAGE 2
sfr16 PCA0CP0 = 0xfb; // PCA0 Module 0 capture
sfr16 PCA0CP1 = 0xfd; // PCA0 Module 1 capture
//-----------------------------------------------------------------------------
// Local Constants
//-----------------------------------------------------------------------------
#define SYSCLK 73500000 // System Clock in Hz
//-----------------------------------------------------------------------------
// Local Global Variables
//-----------------------------------------------------------------------------
static unsigned int timeout;
//-----------------------------------------------------------------------------
// Exported Function Prototypes
//-----------------------------------------------------------------------------
void Reset_Init(void);
void wait_ms(int ms);
void clear_ms_timer_flag(void);
char get_ms_timer_flag(void);
void start_ms_timer();
void CP220x_RST_Low(void);
void CP220x_RST_High(void);
unsigned char AB4_RST_State(void);
#if(UART_ENABLED)
char _getkey ();
char putchar (char c);
#endif
//-----------------------------------------------------------------------------
// Local Function Prototypes
//-----------------------------------------------------------------------------
void PORT_Init (void);
void SYSCLK_Init (void);
void EMIF_Init (void);
#if(UART_ENABLED)
void UART1_Init (void);
#endif
//-----------------------------------------------------------------------------
// Exported Functions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Reset_Init
//-----------------------------------------------------------------------------
void Reset_Init(void)
{
// Enable the VDD Monitor as a reset source
// Do not use read-modify write instruction on this register
RSTSRC = 0x02;
// Disable Watchdog Timer
WDTCN = 0xde;
WDTCN = 0xad;
C51 COMPILER V8.08 F12X_INIT 11/04/2008 15:15:23 PAGE 3
// Initialize the MCU
PORT_Init();
SYSCLK_Init();
EMIF_Init();
EX0 = 1; // Enable External Interrupt 0
#if(UART_ENABLED)
UART1_Init();
puts("\n*** Reset ***\nC8051F12x MCU Initialized\n");
#endif
}
//-----------------------------------------------------------------------------
// External Interrupt 0
//-----------------------------------------------------------------------------
//
// This interrupt service routine is routed to the ethernet interrupt
//
void INT0_ISR(void) interrupt 0
{
Ethernet_ISR();
}
//-----------------------------------------------------------------------------
// wait_ms
//-----------------------------------------------------------------------------
//
// This routine inserts a delay of <ms> milliseconds.
//
void wait_ms(int ms)
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
SFRPAGE = TMR2_PAGE;
TMR2CN = 0x00; // Stop Timer2; Clear TF2;
TMR2CF = 0x00; // use SYSCLK/12 as timebase
RCAP2 = -(SYSCLK/1000/12); // Timer 2 overflows at 1 kHz
TMR2 = RCAP2;
ET2 = 0; // Disable Timer 2 interrupts
TR2 = 1; // Start Timer 2
while(ms){
TF2 = 0;
while(!TF2); // wait until timer overflows
ms--; // decrement ms
}
TR2 = 0; // Stop Timer 2
SFRPAGE = SFRPAGE_SAVE; // Restore SFRPAGE
}
//-----------------------------------------------------------------------------
// reset_timout
C51 COMPILER V8.08 F12X_INIT 11/04/2008 15:15:23 PAGE 4
//-----------------------------------------------------------------------------
//
// This routine resets the global timeout.
//
void reset_timeout(unsigned int ms)
{
timeout = ms;
start_ms_timer();
}
//-----------------------------------------------------------------------------
// timeout_expired
//-----------------------------------------------------------------------------
//
// This routine manages the timeout and returns TRUE if timeout expired.
//
unsigned char timeout_expired(void)
{
if(get_ms_timer_flag()){
clear_ms_timer_flag();
if(timeout > 0){
timeout--;
}
}
return (timeout == 0);
}
//-----------------------------------------------------------------------------
// start_ms_timer
//-----------------------------------------------------------------------------
//
// This routine starts a timer with a 1kHz overflow rate (1ms period).
//
void start_ms_timer()
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
SFRPAGE = TMR2_PAGE;
TMR2CN = 0x00; // Stop Timer2; Clear TF2;
TMR2CF = 0x00; // use SYSCLK/12 as timebase
RCAP2 = -(SYSCLK/1000/12); // Timer 2 overflows at 1 kHz
TMR2 = RCAP2;
ET2 = 0; // Disable Timer 2 interrupts
TR2 = 1; // Start Timer 2
SFRPAGE = SFRPAGE_SAVE; // Restore SFRPAGE
}
//-----------------------------------------------------------------------------
// get_ms_timer_flag()
//-----------------------------------------------------------------------------
//
// This routine returns the state of the ms_timer overflow flag.
//
C51 COMPILER V8.08 F12X_INIT 11/04/2008 15:15:23 PAGE 5
char get_ms_timer_flag(void)
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
SFRPAGE = TMR2_PAGE;
return TF2;
SFRPAGE = SFRPAGE_SAVE; // Restore SFRPAGE
}
//-----------------------------------------------------------------------------
// clear_ms_timer_flag()
//-----------------------------------------------------------------------------
//
// This routine returns the state of the ms_timer overflow flag.
//
void clear_ms_timer_flag(void)
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
SFRPAGE = TMR2_PAGE;
TF2 = 0;
SFRPAGE = SFRPAGE_SAVE; // Restore SFRPAGE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -