示例#1
0
文件: system.c 项目: timwuu/PK3SP24
/*********************************************************************
* Function: void SYSTEM_Initialize( SYSTEM_STATE state )
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  SYSTEM_STATE - the state to initialize the system into
*
* Output: None
*
********************************************************************/
void SYSTEM_Initialize( SYSTEM_STATE state )
{
    //On the PIC24FJ64GB004 Family of USB microcontrollers, the PLL will not power up and be enabled
    //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL).
    //This allows the device to power up at a lower initial operating frequency, which can be
    //advantageous when powered from a source which is not gauranteed to be adequate for 32MHz
    //operation.  On these devices, user firmware needs to manually set the CLKDIV<PLLEN> bit to
    //power up the PLL.
    {
        unsigned int pll_startup_counter = 600;
        CLKDIVbits.PLLEN = 1;
        while(pll_startup_counter--);
    }

    switch(state)
    {
        case SYSTEM_STATE_USB_HOST:
            PRINT_SetConfiguration(PRINT_CONFIGURATION_UART);

            break;
            
        case SYSTEM_STATE_USB_HOST_HID_KEYBOARD:
            LED_Enable(LED_USB_HOST_HID_KEYBOARD_DEVICE_READY);

            //also setup UART here
            PRINT_SetConfiguration(PRINT_CONFIGURATION_UART);
            //timwuu 2015.04.11 LCD_CursorEnable(true);

            TIMER_SetConfiguration(TIMER_CONFIGURATION_1MS);

            break;
    }
}
示例#2
0
/*********************************************************************
* Function: void SYS_Initialize(void)
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  None
*
* Output: None
*
********************************************************************/
void SYS_Initialize()
{
    TIMER_SetConfiguration(TIMER_CONFIGURATION_1MS);
    ADC_SetConfiguration(ADC_CONFIGURATION_DEFAULT);
    LED_Enable(LED_USB_HOST_MSD_DATA_LOGGER);
    LED_Off(LED_USB_HOST_MSD_DATA_LOGGER);
    BUTTON_Enable(BUTTON_USB_HOST_MSD_DATA_LOGGER);
}
示例#3
0
/*********************************************************************
* Function: void SYSTEM_Initialize( SYSTEM_STATE state )
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  SYSTEM_STATE - the state to initialize the system into
*
* Output: None
*
********************************************************************/
void SYSTEM_Initialize( SYSTEM_STATE state )
{
    switch(state)
    {
    case SYSTEM_STATE_USB_HOST:
        ANSELA = 0x0000;
        ANSELB = 0x0000;
        ANSELC = 0x0000;
        ANSELD = 0x0000;
        ANSELE = 0x0000;
        ANSELG = 0x0000;

        // Configure the device PLL to obtain 60 MIPS operation. The crystal
        // frequency is 8MHz. Divide 8MHz by 2, multiply by 60 and divide by
        // 2. This results in Fosc of 120MHz. The CPU clock frequency is
        // Fcy = Fosc/2 = 60MHz. Wait for the Primary PLL to lock and then
        // configure the auxilliary PLL to provide 48MHz needed for USB
        // Operation.

        PLLFBD = 58;                        /* M  = 60  */
        CLKDIVbits.PLLPOST = 0;             /* N1 = 2   */
        CLKDIVbits.PLLPRE = 0;              /* N2 = 2   */
        OSCTUN = 0;

        /*	Initiate Clock Switch to Primary
         *	Oscillator with PLL (NOSC= 0x3)*/
        __builtin_write_OSCCONH(0x03);
        __builtin_write_OSCCONL(0x01);

        while (OSCCONbits.COSC != 0x3);

        // Configuring the auxiliary PLL, since the primary
        // oscillator provides the source clock to the auxiliary
        // PLL, the auxiliary oscillator is disabled. Note that
        // the AUX PLL is enabled. The input 8MHz clock is divided
        // by 2, multiplied by 24 and then divided by 2. Wait till
        // the AUX PLL locks.

        ACLKCON3 = 0x24C1;
        ACLKDIV3 = 0x7;

        ACLKCON3bits.ENAPLL = 1;
        while(ACLKCON3bits.APLLCK != 1);

        PRINT_SetConfiguration(PRINT_CONFIGURATION_LCD);
        LED_Enable(LED_USB_HOST_HID_MOUSE_DEVICE_READY);
        break;

    case SYSTEM_STATE_USB_HOST_HID_MOUSE:
        PRINT_SetConfiguration(PRINT_CONFIGURATION_LCD);
        LCD_CursorEnable(true);

        TIMER_SetConfiguration(TIMER_CONFIGURATION_1MS);

        break;
    }
}
示例#4
0
/*********************************************************************
* Function: void SYSTEM_Initialize( SYSTEM_STATE state )
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  SYSTEM_STATE - the state to initialize the system into
*
* Output: None
*
********************************************************************/
void SYSTEM_Initialize( SYSTEM_STATE state )
{
    switch(state)
    {
        case SYSTEM_STATE_USB_HOST:
            PRINT_SetConfiguration(PRINT_CONFIGURATION_OLED);
            LED_Enable(LED_USB_HOST_HID_MOUSE_DEVICE_READY);
            break;
            
        case SYSTEM_STATE_USB_HOST_HID_MOUSE:
            PRINT_SetConfiguration(PRINT_CONFIGURATION_LCD);
            TIMER_SetConfiguration(TIMER_CONFIGURATION_1MS);
            break;
    }
}
示例#5
0
/*********************************************************************
* Function: void SYS_Initialize( none )
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  None
*
* Output: None
*
********************************************************************/
void SYS_Initialize( )
{
    ANSELA = 0x0000;
    ANSELB = 0x0000;
    ANSELC = 0x0000;
    ANSELE = 0x0000;
    ANSELG = 0x0000;

            // Configure the device PLL to obtain 60 MIPS operation. The crystal
            // frequency is 8MHz. Divide 8MHz by 2, multiply by 60 and divide by
            // 2. This results in Fosc of 120MHz. The CPU clock frequency is
            // Fcy = Fosc/2 = 60MHz. Wait for the Primary PLL to lock and then
            // configure the auxilliary PLL to provide 48MHz needed for USB
            // Operation.

            PLLFBD = 58;                        /* M  = 60  */
            CLKDIVbits.PLLPOST = 0;             /* N1 = 2   */
            CLKDIVbits.PLLPRE = 0;              /* N2 = 2   */
            OSCTUN = 0;

            /*	Initiate Clock Switch to Primary
             *	Oscillator with PLL (NOSC= 0x3)*/
            __builtin_write_OSCCONH(0x03);
            __builtin_write_OSCCONL(0x01);

            while (OSCCONbits.COSC != 0x3);

            // Configuring the auxiliary PLL, since the primary
            // oscillator provides the source clock to the auxiliary
            // PLL, the auxiliary oscillator is disabled. Note that
            // the AUX PLL is enabled. The input 8MHz clock is divided
            // by 2, multiplied by 24 and then divided by 2. Wait till
            // the AUX PLL locks.

            ACLKCON3 = 0x24C1;
            ACLKDIV3 = 0x7;

            ACLKCON3bits.ENAPLL = 1;
            while(ACLKCON3bits.APLLCK != 1);

    TIMER_SetConfiguration(TIMER_CONFIGURATION_1MS);
    ADC_SetConfiguration(ADC_CONFIGURATION_DEFAULT);
    LED_Enable(LED_USB_HOST_MSD_DATA_LOGGER);
    LED_Off(LED_USB_HOST_MSD_DATA_LOGGER);
    BUTTON_Enable(BUTTON_USB_HOST_MSD_DATA_LOGGER);
}
示例#6
0
文件: main.c 项目: clark173/477Team2
// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
int main ( void )
{
    /* Call the System Intialize routine*/
    SYS_Initialize ( ) ;

    /*Initialize Timer*/
    TIMER_SetConfiguration ( TIMER_CONFIGURATION_RTCC ) ;

    TRISGbits.TRISG7 = 1; //in breakout pin RF2 (row 1)
    TRISGbits.TRISG2  = 1; //in breakout pin RA2 (row 2)
    TRISCbits.TRISC0 = 1; //in breakout pin RB8 (row 3)
    TRISCbits.TRISC1 = 1;//in breakout pin RB9 (row 4)                 
    TRISEbits.TRISE12 = 0; //in breakout pin RB12 (col 1)
    TRISCbits.TRISC2 = 0; //in breakout pin RB10 (col 2)
    TRISEbits.TRISE14 = 0; //in breakout pin RB14 (col 3)
    
    
    ANSELGbits.ANSG7 = 0; //Row 1-4        //configuring all pins as digital
    ANSELGbits.ANSG2 = 0;
    ANSELCbits.ANSC0 = 0;
    ANSELCbits.ANSC1 = 0;
    ANSELEbits.ANSE12 = 0; //Col 1-3
    ANSELCbits.ANSC2 = 0;
    ANSELEbits.ANSE14 = 0;
    
    char return_key;
    
    /* Infinite Loop */
    while ( 1 )
    {  
        return_key = 'X'; //initialize return key to default return variable from readKeyboard()
        
        while(return_key == 'X'){ //while nothing is pressed, keep on making calls
            return_key = readKeyboard();
        }
        
        if(return_key != 'X'){ //if return_key is not default key, print to LCD 
            //should transmit to UART at this point  
            LCD_PutChar(return_key);
        }
        
        while(readKeyboard() != 'X'){
            //no operation till next key is pressed.
        }
    }    
}
示例#7
0
文件: system.c 项目: timwuu/PK3SP24
/*********************************************************************
* Function: void SYSTEM_Initialize( SYSTEM_STATE state )
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  SYSTEM_STATE - the state to initialize the system into
*
* Output: None
*
********************************************************************/
void SYSTEM_Initialize( SYSTEM_STATE state )
{
    switch(state)
    {
        case SYSTEM_STATE_USB_HOST:
            PRINT_SetConfiguration(PRINT_CONFIGURATION_RAM_BUFFER);
            break;
            
        case SYSTEM_STATE_USB_HOST_HID_KEYBOARD:
            LED_Enable(LED_USB_HOST_HID_KEYBOARD_DEVICE_READY);

            PRINT_SetConfiguration(PRINT_CONFIGURATION_RAM_BUFFER);

            TIMER_SetConfiguration(TIMER_CONFIGURATION_1MS);

            break;
    }
}
示例#8
0
文件: system.c 项目: timwuu/PK2BL32
/*********************************************************************
* Function: void SYSTEM_Initialize( SYSTEM_STATE state )
*
* Overview: Initializes the system.
*
* PreCondition: None
*
* Input:  SYSTEM_STATE - the state to initialize the system into
*
* Output: None
*
********************************************************************/
void SYSTEM_Initialize( SYSTEM_STATE state )
{
    switch(state)
    {
        case SYSTEM_STATE_USB_HOST:
            //PRINT_SetConfiguration(PRINT_CONFIGURATION_UART);
            //UART2Init();  //?timijk for DEBUGGING
            
            break;
            
        case SYSTEM_STATE_USB_HOST_HID_PICKIT:
            LED_Enable(LED_USB_HOST_HID_PICKIT_DEVICE_READY);

            //also setup UART here
            //PRINT_SetConfiguration(PRINT_CONFIGURATION_UART);
            //timijk 2015.04.11 LCD_CursorEnable(true);
            UART2Init();
            IEC1bits.U2RXIE= 1;  //enable RXIE
            
            TIMER_SetConfiguration(TIMER_CONFIGURATION_1MS);

            break;
    }
}