📄 f34x_init.lst
字号:
275 // get_ms_timer_flag()
276 //-----------------------------------------------------------------------------
277 //
278 // This routine returns the state of the ms_timer overflow flag.
279 //
280 char get_ms_timer_flag(void)
281 {
282 1 return TF2H;
283 1 }
284
285 //-----------------------------------------------------------------------------
286 // clear_ms_timer_flag()
287 //-----------------------------------------------------------------------------
288 //
289 // This routine returns the state of the ms_timer overflow flag.
290 //
291 void clear_ms_timer_flag(void)
292 {
293 1 TF2H = 0;
294 1 }
295
296 //-----------------------------------------------------------------------------
297 // CP220x_RST_Low
298 //-----------------------------------------------------------------------------
299 //
300 // Drives the CP220x's Reset Pin Low.
301 //
302 void CP220x_RST_Low(void)
303 {
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 6
304 1 AB4_RST = 0; // Set P1.0 Low
305 1 }
306
307 //-----------------------------------------------------------------------------
308 // CP220x_RST_High
309 //-----------------------------------------------------------------------------
310 //
311 // Allows the CP220x's Reset Pin to be pulled up.
312 //
313 // Waits until the reset pin rises.
314 //
315 void CP220x_RST_High(void)
316 {
317 1 AB4_RST = 1; // Set P1.0 High
318 1
319 1 while(!AB4_RST);
320 1 }
321
322
323 //-----------------------------------------------------------------------------
324 // AB4_RST_State
325 //-----------------------------------------------------------------------------
326 //
327 // Returns the state of the AB4's reset pin.
328 //
329 unsigned char AB4_RST_State(void)
330 {
331 1 char rst_pin_state;
332 1
333 1 rst_pin_state = AB4_RST; // Get P4.5 State
334 1
335 1 return rst_pin_state;
336 1 }
337 //-----------------------------------------------------------------------------
338 // Local Initialization Routines
339 //-----------------------------------------------------------------------------
340
341
342 //-----------------------------------------------------------------------------
343 // PORT_Init
344 //-----------------------------------------------------------------------------
345 //
346 // Configure the Crossbar and GPIO ports.
347 //
348 // P0.3 - /INT
349 // P0.4 - UART TX
350 // P0.5 - UART RX
351 //
352 // P1.0 - AB4-/RST
353 // P1.1 - AB4-SW1
354 // P1.2 - AB4-SW2
355 // P1.3 - AB4-LED1
356 // P1.4 - AB4-LED2
357 // P1.5 -
358 // P1.6 - /RD
359 // P1.7 - /WR
360 //
361 // P2.2 - LED - shared with address line
362 //
363 // P2 - Address High
364 // P3 - Address Low
365 // P4 - Data Bus
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 7
366 //
367
368 void PORT_Init (void)
369 {
370 1
371 1 IT01CF = 0x03; // Enable Interrupt 0 on P0.3
372 1 TCON &= ~0x01; // Make /INT0 level triggered
373 1
374 1 XBR0 = 0x01; // Enable UART on P0.4(TX) and P0.5(RX)
375 1 XBR1 = 0x40; // Enable Crossbar and weak pull-ups
376 1
377 1 P0MDOUT |= 0x10; // Enable TX0 as push-pull output
378 1 P1MDOUT |= 0xC0; // /WR and /RD are push-pull
379 1 P1MDOUT |= 0x18; // AB4 LEDs are push-pull
380 1 P1MDOUT &= ~0x01; // /RST is open-drain
381 1
382 1 // Configure External Memory Interface Pins to push-pull except for
383 1 // P2.0 and P2.1 which are used for target board switches.
384 1 P2MDOUT |= 0xFC; // ADDR[15:8]
385 1 P3MDOUT |= 0xFF; // ADDR[7:0]
386 1 P4MDOUT |= 0xFF; // DATA[7:0]
387 1
388 1 // Set initial values of External Memory Interface Pins
389 1 P1 = 0xFE; // /WR, /RD, are high, RESET is low
390 1 P1 &= ~0x18; // LEDs off
391 1 P2 = 0xFF; // ADDR[15:8] initially high
392 1 P3 = 0xFF; // ADDR[7:0] initially high
393 1 P4 = 0xFF; // DATA[7:0] intially high
394 1 }
395
396
397 //-----------------------------------------------------------------------------
398 // SYSCLK_Init
399 //-----------------------------------------------------------------------------
400 //
401 // This routine initializes the system clock to use the internal oscillator
402 // multiplied by 4 as the system clock. The resulting frequency is 48 MHz.
403 // Also enables the Missing Clock Detector and VDD monitor.
404 //
405
406 void SYSCLK_Init (void)
407 {
408 1 int i;
409 1
410 1 OSCICN |= 0x03; // Configure internal oscillator for
411 1 // its maximum frequency
412 1
413 1 CLKMUL = 0x00; // Reset Clock Multiplier and select
414 1 // internal oscillator as input source
415 1
416 1 CLKMUL |= 0x80; // Enable the Clock Multiplier
417 1
418 1 for(i = 0; i < 256; i++); // Delay at least 5us
419 1
420 1 CLKMUL |= 0xC0; // Initialize the Clock Multiplier
421 1
422 1 while(!(CLKMUL & 0x20)); // Wait for MULRDY => 1
423 1
424 1 RSTSRC = 0x06; // Enable missing clock detector
425 1 // and VDD monitor
426 1
427 1 FLSCL |= 0x10; // Set Flash Scale for 48MHz
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 8
428 1
429 1 CLKSEL |= 0x03; // Select output of clock multiplier
430 1 // as the system clock.
431 1
432 1 }
433
434 //-----------------------------------------------------------------------------
435 // EMIF_Init
436 //-----------------------------------------------------------------------------
437 //
438 // Configure the external memory interface to use upper port pins in
439 // non-multiplexed mode to a mixed on-chip/off-chip configuration without
440 // Bank Select.
441 //
442 void EMIF_Init (void)
443 {
444 1
445 1 EMI0CF = 0x1B; // non-muxed mode; split mode
446 1 // with bank selec
447 1
448 1 EMI0TC = 0xFF; // slowest timing (4-cycle MOVX)
449 1
450 1 EMI0CN = 0x20; // Off-chip
451 1 }
452
453 //===============
454 // CONDITIONAL
455 //===============
456 #if(UART_ENABLED)
457
458 //-----------------------------------------------------------------------------
459 // UART0_Init
460 //-----------------------------------------------------------------------------
461 //
462 // Configure the UART0 using Timer1, for <BAUDRATE> and 8-N-1.
463 //
464 void UART0_Init (void)
465 {
466 1 SCON0 = 0x10; // SCON0: 8-bit variable bit rate
467 1 // level of STOP bit is ignored
468 1 // RX enabled
469 1 // ninth bits are zeros
470 1 // clear RI0 and TI0 bits
471 1 if (SYSCLK/BAUDRATE/2/256 < 1) {
472 2 TH1 = -(SYSCLK/BAUDRATE/2);
473 2 CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx
474 2 CKCON |= 0x08;
475 2 } else if (SYSCLK/BAUDRATE/2/256 < 4) {
476 2 TH1 = -(SYSCLK/BAUDRATE/2/4);
477 2 CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01
478 2 CKCON |= 0x09;
479 2 } else if (SYSCLK/BAUDRATE/2/256 < 12) {
480 2 TH1 = -(SYSCLK/BAUDRATE/2/12);
481 2 CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 00
482 2 } else {
483 2 TH1 = -(SYSCLK/BAUDRATE/2/48);
484 2 CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 10
485 2 CKCON |= 0x02;
486 2 }
487 1
488 1 TL1 = TH1; // init Timer1
489 1 TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 9
490 1 TMOD |= 0x20;
491 1 TR1 = 1; // START Timer1
492 1 TI0 = 1; // Indicate TX0 ready
493 1 }
494
495 //-----------------------------------------------------------------------------
496 // _getkey
497 //-----------------------------------------------------------------------------
498 //
499 // SFR Paged version of _getkey
500 //
501 char _getkey () {
502 1
503 1 char c;
504 1
505 1 while (!RI0);
506 1 c = SBUF0;
507 1
508 1 RI0 = 0;
509 1 return (c);
510 1 }
511
512 //-----------------------------------------------------------------------------
513 // putchar
514 //-----------------------------------------------------------------------------
515 //
516 // SFR Paged version of putchar
517 //
518 char putchar (char c) {
519 1
520 1 // output CR
521 1 if (c == '\n') {
522 2 while (!TI0);
523 2 TI0 = 0;
524 2 SBUF0 = 0x0d;
525 2 }
526 1
527 1 // output character
528 1 while (!TI0);
529 1 TI0 = 0;
530 1 SBUF0 = c;
531 1
532 1 return (c);
533 1 }
534
535 #endif // UART_ENABLED
536
537
538 //-----------------------------------------------------------------------------
539 // End Of File
540 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 574 ----
CONSTANT SIZE = 42 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 6 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILER V8.08 F34X_INIT 11/04/2008 18:45:33 PAGE 10
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -