- //-----------------------------------------------------------------------------
- // GlobalVariabel.c
- //-----------------------------------------------------------------------------
- // Copyright 2007 Vson Technology, Inc.
- // http://www.usbmcu.com
- //
- // Program Description:
- //
- //
- //
- //
- //
- // MCU: C8051F347
- // Tool chain: Keil C51 7.50 / Keil EVAL C51
- // Silicon Laboratories IDE version 2.6
- // Command Line:
- // Project Name: TR1000
- //
- //
- // Release 1.0
- // -All changes by Brin
- // -24 JUL 2007
- //
- //
- //-----------------------------------------------------------------------------
- // Includes
- //-----------------------------------------------------------------------------
- #include "Include_H.h"
- //-----------------------------------------------------------------------------
- // Initialization Subroutines
- //-----------------------------------------------------------------------------
- void Initial(void)
- {
- data BYTE i;
- PORT_Init (); // Initialize Crossbar and GPIO
- Timer_Init();
- SYSCLK_Init (); // Initialize oscillator
- USB0_Init (); // Initialize USB0
- VDD_MON_Init(); // Turn on VDD Monitor
- for (i = 0; i < 64; i++)
- {
- gaucTxData2HostBuffer[i]=0;
- }
- }
- //-----------------------------------------------------------------------------
- // SYSCLK_Init
- //-----------------------------------------------------------------------------
- //
- // Return Value : None
- // Parameters : None
- //
- // This function initializes the system clock and USB clock.
- //
- //-----------------------------------------------------------------------------
- void SYSCLK_Init (void)
- {
- unsigned char delay = 100;
- OSCICN |= 0x03; // Configure internal oscillator for
- // its maximum frequency
- CLKMUL = 0x00; // Select internal oscillator as
- // input to clock multiplier
- CLKMUL |= 0x80; // Enable clock multiplier
- while (delay--); // Delay for >5us
- CLKMUL |= 0xC0; // Initialize the clock multiplier
- while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
- CLKSEL |= USB_4X_CLOCK; // Select USB clock
- CLKSEL |= SYS_4X_DIV_2; // Select SYSCLK as Clock Multiplier/2
- }
- /*
- void SYSCLK_Init (void) //void Oscillator_Init()
- {
- int i = 0;
- OSCICN = 0x83;
- CLKMUL = 0x80;
- for (i = 0; i < 20; i++); // Wait 5us for initialization
- CLKMUL |= 0xC0;
- while ((CLKMUL & 0x20) == 0);
- CLKSEL = 0x10;
- }
- */
- //-----------------------------------------------------------------------------
- // VDD_MON_Init
- //-----------------------------------------------------------------------------
- //
- // Return Value : None
- // Parameters : None
- //
- // This function initializes the VDD monitor
- //
- //-----------------------------------------------------------------------------
- void VDD_MON_Init(void)
- {
- RSTSRC |= 0x02;
- }
- //-----------------------------------------------------------------------------
- // USB0_Init
- //-----------------------------------------------------------------------------
- //
- // Return Value : None
- // Parameters : None
- //
- // - Initialize USB0
- // - Enable USB0 interrupts
- // - Enable USB0 transceiver
- // - USB0 left disabled
- //
- //-----------------------------------------------------------------------------
- void USB0_Init (void)
- {
- UWRITE_BYTE(POWER, 0x08); // Asynch. reset
- UWRITE_BYTE(IN1IE, 0x0F); // Enable Endpoint0 Interrupt
- UWRITE_BYTE(OUT1IE, 0x0F);
- UWRITE_BYTE(CMIE, 0x04); // Enable Reset interrupt
- USB0XCN = 0xC0; // Enable transceiver
- USB0XCN |= FULL_SPEED; // Select device speed
- UWRITE_BYTE(CLKREC, 0x80); // Enable clock recovery,
- // single-step mode disabled
- EIE1 |= 0x02; // Enable USB0 Interrupts
- }
- //-----------------------------------------------------------------------------
- // PORT_Init
- //-----------------------------------------------------------------------------
- //
- // Return Value : None
- // Parameters : None
- //
- // This function configures the crossbar and GPIO ports.
- //
- // P2.2 digital push-pull LED
- // P2.3 digital push-pull LED
- //
- //-----------------------------------------------------------------------------
- void PORT_Init(void)
- {
- P2MDOUT |= 0x0C; // Port 2 pins 0,1 set high impedence
- Led1 = 0; // Start with both Leds off
- Led2 = 0;
- XBR0 = 0x00;
- XBR1 = 0x40; // Enable Crossbar
- }
- void Timer_Init(void)
- {
- TMOD = 0x21;
- CKCON = 0X08; //0x01;
- TH1 = 0X30; //0x63;
- // TL0 = 0xa0;
- TH0 = 0x15;
- TCON = 0x50;
- TMR2CN = 0x04;
- TMR2RLL = 0xDF;
- TMR2RLH = 0xB1;
- TMR2L = 0xDF;
- TMR2H = 0xB1;
- }