📄 f340_usb0_mouse.lst
字号:
183 // Return Value - None
184 // Parameters - None
185 //
186 // This top-level initialization routine calls all support routine.
187 //
188 // ----------------------------------------------------------------------------
189 void System_Init (void)
190 {
191 1 PCA0MD &= ~0x40; // Disable Watchdog timer
192 1 Sysclk_Init (); // initialize system clock
193 1 Port_Init (); // configure cross bar
194 1 Timer_Init (); // configure timer
195 1 ADC0_Init ();
196 1 }
197
198 //-----------------------------------------------------------------------------
199 // USB0_Init
200 //-----------------------------------------------------------------------------
201 //
202 // Return Value - None
203 // Parameters - None
204 //
205 // - Initialize USB0
206 // - Enable USB0 interrupts
207 // - Enable USB0 transceiver
208 // - Enable USB0 with suspend detection
209 //
210 // ----------------------------------------------------------------------------
211
212 void USB0_Init (void)
213 {
214 1
215 1 POLL_WRITE_BYTE (POWER, 0x08); // Force Asynchronous USB Reset
216 1 POLL_WRITE_BYTE (IN1IE, 0x07); // Enable Endpoint 0-1 in interrupts
217 1 POLL_WRITE_BYTE (OUT1IE,0x07); // Enable Endpoint 0-1 out interrupts
218 1 POLL_WRITE_BYTE (CMIE, 0x07); // Enable Reset, Resume, and Suspend
219 1 // interrupts
220 1 USB0XCN = 0xE0; // Enable transceiver; select full speed
221 1 POLL_WRITE_BYTE (CLKREC,0x80); // Enable clock recovery, single-step
222 1 // mode disabled
223 1
224 1 EIE1 |= 0x02; // Enable USB0 Interrupts
225 1
226 1 // Enable USB0 by clearing the USB
227 1 POLL_WRITE_BYTE (POWER, 0x01); // Inhibit Bit and enable suspend
228 1 // detection
229 1
230 1 }
231
232
233 //-----------------------------------------------------------------------------
234 // Sysclk_Init
235 //-----------------------------------------------------------------------------
236 //
237 // Return Value - None
238 // Parameters - None
239 //
240 // Initialize system clock to maximum frequency.
241 //
C51 COMPILER V8.05a F340_USB0_MOUSE 10/16/2008 16:50:25 PAGE 5
242 // ----------------------------------------------------------------------------
243 void Sysclk_Init (void)
244 {
245 1 #ifdef _USB_LOW_SPEED_
OSCICN |= 0x03; // Configure internal oscillator for
// its maximum frequency and enable
// missing clock detector
CLKSEL = SYS_EXT_OSC; // Select System clock
CLKSEL |= USB_INT_OSC_DIV_2; // Select USB clock
#else
254 1 OSCICN |= 0x03; // Configure internal oscillator for
255 1 // its maximum frequency and enable
256 1 // missing clock detector
257 1
258 1 CLKMUL = 0x00; // Select internal oscillator as
259 1 // input to clock multiplier
260 1
261 1 CLKMUL |= 0x80; // Enable clock multiplier
262 1 CLKMUL |= 0xC0; // Initialize the clock multiplier
263 1 Delay(); // Delay for clock multiplier to begin
264 1
265 1 while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
266 1 CLKSEL = SYS_INT_OSC; // Select system clock
267 1 CLKSEL |= USB_4X_CLOCK; // Select USB clock
268 1 #endif /* _USB_LOW_SPEED_ */
269 1 }
270
271 //-----------------------------------------------------------------------------
272 // Port_Init
273 //-----------------------------------------------------------------------------
274 //
275 // Return Value - None
276 // Parameters - None
277 //
278 // - Configure the Crossbar and GPIO ports.
279 //
280 // ----------------------------------------------------------------------------
281 void Port_Init(void)
282 {
283 1 P2MDIN = ~(0x20); // Port 2 pin 5 set as analog input
284 1 P0MDOUT |= 0x0F; // Port 0 pins 0-3 set high impedence
285 1 P1MDOUT |= 0x0F; // Port 1 pins 0-3 set high impedence
286 1 P2MDOUT |= 0x0C; // Port 2 pins 0,1 set high empedence
287 1 P2SKIP = 0x20; // Port 2 pin 5 skipped by crossbar
288 1 XBR0 = 0x00;
289 1 XBR1 = 0x40; // Enable Crossbar
290 1 }
291
292 //-----------------------------------------------------------------------------
293 // Timer_Init
294 //-----------------------------------------------------------------------------
295 //
296 // Return Value - None
297 // Parameters - None
298 //
299 // - Timer 2 reload, used to check if switch pressed on overflow and
300 // used for ADC continuous conversion
301 //
302 // ----------------------------------------------------------------------------
303 void Timer_Init (void)
C51 COMPILER V8.05a F340_USB0_MOUSE 10/16/2008 16:50:25 PAGE 6
304 {
305 1 TMR2CN = 0x00; // Stop Timer2; Clear TF2;
306 1
307 1 CKCON &= ~0xF0; // Timer2 clocked based on T2XCLK;
308 1 TMR2RL = 0; // Initialize reload value
309 1 TMR2 = 0xffff; // Set to reload immediately
310 1
311 1 ET2 = 1; // Enable Timer2 interrupts
312 1 TR2 = 1; // Start Timer2
313 1 }
314
315 //-----------------------------------------------------------------------------
316 // ADC0_Init
317 //-----------------------------------------------------------------------------
318 //
319 // Return Value - None
320 // Parameters - None
321 //
322 // - Configures ADC for single ended continuous conversion or Timer2
323 //
324 // ----------------------------------------------------------------------------
325 void ADC0_Init (void)
326 {
327 1 REF0CN = 0x0E; // Enable voltage reference VREF
328 1 AMX0P = 0x04; // switch to potentiometer
329 1 ADC0CF = 0xFC; // place ADC0 in left-adjusted mode
330 1 AMX0N = 0x1F; // Single ended mode(negative input=gnd)
331 1
332 1 ADC0CF = 0xFC; // SAR Period 0x1F, Left adjusted output
333 1
334 1 ADC0CN = 0xC2; // Continuous converion on timer 2
335 1 // overflow with low power tracking
336 1 // mode on
337 1
338 1 EIE1 |= 0x08; // Enable conversion complete interrupt
339 1 }
340
341
342 //-----------------------------------------------------------------------------
343 // Delay
344 //-----------------------------------------------------------------------------
345 //
346 // Return Value - None
347 // Parameters - None
348 //
349 // Used for a small pause, approximately 80 us in Full Speed,
350 // and 1 ms when clock is configured for Low Speed
351 //
352 // ----------------------------------------------------------------------------
353 void Delay (void)
354 {
355 1 int x;
356 1 for (x = 0; x < 500; x)
357 1 x++;
358 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 321 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
C51 COMPILER V8.05a F340_USB0_MOUSE 10/16/2008 16:50:25 PAGE 7
DATA SIZE = 11 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -