📄 f34x_init.lst
字号:
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE F34X_INIT
OBJECT MODULE PLACED IN F34x_Init.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.exe F34x_Init.c DB OE
line level source
1 //-----------------------------------------------------------------------------
2 // F34x_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 F340.
10 //
11 // FID:
12 // Target: C8051F34x
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 //-----------------------------------------------------------------------------
34 // 16-bit SFR Definitions for 'F34x
35 //-----------------------------------------------------------------------------
36 sfr16 TMR2RL = 0xca; // Timer2 reload value
37 sfr16 TMR2 = 0xcc; // Timer2 counter
38 sfr16 TMR3RL = 0x92; // Timer3 reload value
39 sfr16 TMR3 = 0x94; // Timer3 counter
40
41 //-----------------------------------------------------------------------------
42 // Local Constants
43 //-----------------------------------------------------------------------------
44
45 sbit AB4_RST = P1^0;
46
47 //-----------------------------------------------------------------------------
48 // Local Global Variables
49 //-----------------------------------------------------------------------------
50
51 static unsigned int timeout;
52
53 //-----------------------------------------------------------------------------
54 // Exported Function Prototypes
55 //-----------------------------------------------------------------------------
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 2
56 void Reset_Init(void);
57 void SYSCLK_Init (void);
58
59 void wait_ms(int ms);
60 void init_timer3(void);
61 void CP220x_RST_Low(void);
62 void CP220x_RST_High(void);
63 extern UINT volatile event_word;
64 extern ULONG idata initial_sequence_nr;
65
66 #if(UART_ENABLED)
67 char _getkey ();
68 char putchar (char c);
69 #endif
70
71 //-----------------------------------------------------------------------------
72 // Local Function Prototypes
73 //-----------------------------------------------------------------------------
74
75 void PORT_Init (void);
76
77 void EMIF_Init (void);
78
79 #if(UART_ENABLED)
80 void UART0_Init (void);
81 #endif
82
83 //-----------------------------------------------------------------------------
84 // Exported Functions
85 //-----------------------------------------------------------------------------
86
87 //-----------------------------------------------------------------------------
88 // Reset_Init
89 //-----------------------------------------------------------------------------
90 void Reset_Init(void)
91 {
92 1
93 1 // Disable Watchdog timer
94 1 PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer
95 1 // enable)
96 1 // Initialize the MCU
97 1 PORT_Init();
98 1 SYSCLK_Init();
99 1 EMIF_Init();
100 1 init_timer3();
101 1
102 1
103 1 EX0 = 1; // Enable External Interrupt 0
104 1
105 1 #if(UART_ENABLED)
106 1 UART0_Init();
107 1 puts("\n*** Reset ***\nC8051F34x MCU Initialized\n");
108 1 #endif
109 1
110 1 }
111
112 //--------------------------------------------------------------------------
113 // Timer 3 interrupt service routing. Intr vector location is
114 // address 0x002B. The timer generates an interrupt every 25 msec
115 // It is set to auto reload so do not need to reload it.
116 //--------------------------------------------------------------------------
117 void timer3_interrupt(void) interrupt 14
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 3
118 {
119 1 static UINT count1 = 0;
120 1 static UINT count2 = 0;
121 1
122 1 TMR3CN |= 0x80; // Clear interrupt flag
123 1
124 1
125 1 // Advance the initial sequence number
126 1 initial_sequence_nr += 6250;
127 1 // Keep it some distance from rolling over
128 1 if (initial_sequence_nr & 0x10000000L) initial_sequence_nr = 1;
129 1
130 1 count1++;
131 1 // These events happens every 0.50 seconds, not simultaneously
132 1 if (count1 == 5) event_word |= EVENT_ARP_RETRANSMIT;
133 1
134 1 if (count1 == 10) event_word |= EVENT_TCP_INACTIVITY;
135 1
136 1 if (count1 == 15) event_word |= EVENT_READ_ANALOG;
137 1
138 1 if (count1 == 20)
139 1 {
140 2 count1 = 0;
141 2 event_word |= EVENT_TCP_RETRANSMIT;
142 2 }
143 1
144 1 count2++;
145 1 if (count2 == 2401)
146 1 {
147 2 count2 = 0;
148 2 event_word |= EVENT_AGE_ARP_CACHE;
149 2 }
150 1 }
151
152
153
154
155
156 //--------------------------------------------------------------------------
157 // 将定时器2设置为模式1自动重载
158 // rate = 4 MHz /(12 * (65536 - reload value))
159 // 25 毫秒 reload value = 19456 = 0x4C00
160 //--------------------------------------------------------------------------
161 void init_timer3(void)
162 {
163 1 TMR3CN = 0x00; // Stop Timer3; Clear TF3;
164 1 // use SYSCLK/12 as timebase
165 1 CKCON &= ~0xC0; // Timer2 clocked based on T2XCLK;
166 1
167 1 // Initialize Reload Value
168 1 TMR3RL = -(SYSCLK/12/40);
169 1 TMR3 = TMR3RL;
170 1 // EIE1 |= 0x80;
171 1 TMR3CN |= 0x04; // Start Timer 3 (TR3 = 1)
172 1 }
173
174 //-----------------------------------------------------------------------------
175 // External Interrupt 0
176 //-----------------------------------------------------------------------------
177 //
178 // This interrupt service routine is routed to the ethernet interrupt
179 //
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 4
180 void INT0_ISR(void) interrupt 0
181 {
182 1 Ethernet_ISR();
183 1 }
184
185
186
187 //-----------------------------------------------------------------------------
188 // wait_ms
189 //-----------------------------------------------------------------------------
190 //
191 // This routine inserts a delay of <ms> milliseconds.
192 //
193 void wait_ms(int ms)
194 {
195 1 TMR2CN = 0x00; // Stop Timer2; Clear TF2;
196 1 // use SYSCLK/12 as timebase
197 1 CKCON &= ~0x30; // Timer2 clocked based on T2XCLK;
198 1
199 1 TMR2RL = -(SYSCLK/1000/12); // Timer 2 overflows at 1 kHz
200 1 TMR2 = TMR2RL;
201 1
202 1 ET2 = 0; // Disable Timer 2 interrupts
203 1
204 1 TR2 = 1; // Start Timer 2
205 1
206 1 while(ms){
207 2 TF2H = 0;
208 2 while(!TF2H); // wait until timer overflows
209 2 ms--; // decrement ms
210 2 }
211 1
212 1 TR2 = 0; // Stop Timer 2
213 1
214 1 }
215
216
217 //-----------------------------------------------------------------------------
218 // reset_timout
219 //-----------------------------------------------------------------------------
220 //
221 // This routine resets the global timeout.
222 //
223 void reset_timeout(unsigned int ms)
224 {
225 1 timeout = ms;
226 1 start_ms_timer();
227 1
228 1 }
229
230
231 //-----------------------------------------------------------------------------
232 // timeout_expired
233 //-----------------------------------------------------------------------------
234 //
235 // This routine manages the timeout and returns TRUE if timeout expired.
236 //
237 unsigned char timeout_expired(void)
238 {
239 1 if(get_ms_timer_flag()){
240 2 clear_ms_timer_flag();
241 2 if(timeout > 0){
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 5
242 3 timeout--;
243 3 }
244 2 }
245 1
246 1 return (timeout == 0);
247 1
248 1
249 1 }
250
251
252 //-----------------------------------------------------------------------------
253 // start_ms_timer
254 //-----------------------------------------------------------------------------
255 //
256 // This routine starts a timer with a 1kHz overflow rate (1ms period).
257 //
258 void start_ms_timer()
259 {
260 1
261 1 TMR2CN = 0x00; // Stop Timer2; Clear TF2;
262 1 // use SYSCLK/12 as timebase
263 1 CKCON &= ~0x30; // Timer2 clocked based on T2XCLK;
264 1
265 1 TMR2RL = -(SYSCLK/1000/12); // Timer 2 overflows at 1 kHz
266 1 TMR2 = TMR2RL;
267 1
268 1 ET2 = 0; // Disable Timer 2 interrupts
269 1
270 1 TR2 = 1; // Start Timer 2
271 1
272 1 }
273
274 //-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -