コード例 #1
0
ファイル: part2.c プロジェクト: DC11011100/C
int main(void)
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(SYS_FREQ);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4 the CPU frequency
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();

    // Set up the UART peripheral so we can send serial data.
    UARTConfigure(UART_USED, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_USED, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_USED, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_USED, F_PB, UART_BAUD_RATE);
    UARTEnable(UART_USED, UART_ENABLE | UART_TX);

    // And configure printf/scanf to use the correct UART.
    if (UART_USED == UART1) {
        __XC_UART = 1;
    }

/***************************************************************************************************
 * Your code goes in between this comment and the following one with asterisks.
 **************************************************************************************************/



/***************************************************************************************************
 * Your code goes in between this comment and the preceding one with asterisks.
 **************************************************************************************************/

    // Returning from main() is bad form in embedded environments. So we sit and spin.
    while (1);
}
コード例 #2
0
ファイル: main.c プロジェクト: jhallard/FallClasses14
int main(void)
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(SYS_FREQ);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4 the CPU frequency
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();


    // Set up the UART peripheral so we can send serial data.
    UARTConfigure(UART_USED, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_USED, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_USED, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_USED, F_PB, UART_BAUD_RATE);
    UARTEnable(UART_USED, UART_ENABLE | UART_TX);

    // And configure printf/scanf to use the correct UART.
    if (UART_USED == UART1) {
        __XC_UART = 1;
    }
    extern void T1Setup();
    extern void T1Stop();
    extern void T1Start();

    // Enable LED outputs 0-7 by setting TRISE register
    TRISECLR = 0x00FF;
    // Initialize the PORTE to 0
    PORTECLR = 0x00FF;
    // Set the lowest bit
    PORTESET = 1;

    OledInit();
    OledDisplayOn();
    printf("Starting Timer Set-up\n");
    T1Setup();

    int stopped = 0, reset = 0;

    extern volatile int milliseconds;
    int temp = 0;
    int count = 0;
    printTime(0, 0);
    while(1) {
        // Display the least significant part of the time for debugging
       int x = PORTD & 0xfff;
       if(x == 272) {
           if(stopped) {
               stopped = 0;
               T1Start();
           }
           if(reset)
               reset = 0;
        if(milliseconds - temp >= 1000) {
            count++;
            int minutes = count/60;
            int seconds = count % 60;
            printTime(minutes,seconds);
            temp = milliseconds;
        }
       }
       else if(x == 784 || x == 528) {
           if(reset != 1) {
             printTime(0, 0);
             T1Stop();
             stopped = 1;
             reset = 1;
             count = 0;
          }

       }
       else {
           stopped = 1;
           continue;
       }

    }

}
コード例 #3
0
ファイル: newfile.c プロジェクト: jhallard/FallClasses14
int main(void)
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(SYS_FREQ);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4 the CPU frequency
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();

    // Set up the UART peripheral so we can send serial data.
    UARTConfigure(UART_USED, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_USED, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_USED, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_USED, F_PB, UART_BAUD_RATE);
    UARTEnable(UART_USED, UART_ENABLE | UART_TX);

    // And configure printf/scanf to use the correct UART.
    if (UART_USED == UART1) {
        __XC_UART = 1;
    }

    // Enable LED outputs 0-7 by setting TRISE register
    TRISECLR = 0x00FF;
    // Initialize the PORTE to 0
    PORTECLR = 0x00FF;
    // Set the lowest bit
    int mask = 1;
    PORTESET = mask;
    int delay = 0xA0000;
    // Loop forever, it is bad to exit in an embedded processor.
    int count=0; // move this into the delay function
    while (1) {
        // Move this printf into your getDelay function!
        printf("Hello, world! %d\n",count++);
        // Replace this with the getDelay function call!

        //int delay = getDelay();

        // do nothing for a lot of cycles
        int i=0;
        for(i=0;i<delay;i++)
            ;
        // shift left by 1
        mask = mask << 1;
        // rotate around if more than 8 bits
        if (mask & 0x0100)
            mask = 1;
        // Set the output to the new mask
        PORTE=mask;

        delay = 0xA0000 + 0x40000*sin((double)count/10) + 0x20000*cos((double)count/5);

        if(delay < 0)
            delay *= -1;

    }
}
コード例 #4
0
ファイル: part1.c プロジェクト: DC11011100/C
int main(void)
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(SYS_FREQ);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4 the CPU frequency
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();

    // Set up the UART peripheral so we can send serial data.
    UARTConfigure(UART_USED, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_USED, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_USED, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_USED, F_PB, UART_BAUD_RATE);
    UARTEnable(UART_USED, UART_ENABLE | UART_TX);

    // And configure printf/scanf to use the correct UART.
    if (UART_USED == UART1) {
        __XC_UART = 1;
    }
    
    // Initialize the array
    char seed1[] = __TIME__;
    unsigned int seed2 = (((unsigned int)(seed1[7] ^ seed1[2])) << 8) | ((unsigned int)(seed1[4] ^ seed1[6]));
    srand(seed2);
    unsigned char vals[] = { rand(), rand(), rand(), rand(), rand() };
    int valsToBeSorted[] = {vals[0], vals[1], vals[2], vals[3], vals[4]};
    
    // Sort the array in place.
    int i, j;
    for (i = 0; i < 5; ++i)
    {
            int aTemp = valsToBeSorted[i];
            for (j = i - 1; j >= 0; j--) {
                    if (valsToBeSorted[j] <= aTemp)
                        break;
                    valsToBeSorted[j + 1] = valsToBeSorted[j];
            }
            valsToBeSorted  [j+1]   =   aTemp;
    }

    // Print out the array
    printf("[");
    for (i=0;i<4;++i) {
        printf("%d, ", valsToBeSorted[i]);
    }
    printf("%d]\n", valsToBeSorted[i]);

    /*
     * Returning from main() is bad form in embedded environments. So we
     * sit and spin.
     */
    while (1);
}
コード例 #5
0
ファイル: rpg.c プロジェクト: InvaderZim19/rpg-arduino-adv
int main()
{
    // Configure the device for maximum performance but do not change the PBDIV
    // Given the options, this function will change the flash wait states, RAM
    // wait state and enable prefetch cache but will not change the PBDIV.
    // The PBDIV value is already set via the pragma FPBDIV option above..
    SYSTEMConfig(F_SYS, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    // Auto-configure the PIC32 for optimum performance at the specified operating frequency.
    SYSTEMConfigPerformance(F_SYS);

    // osc source, PLL multipler value, PLL postscaler , RC divisor
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1);

    // Configure the PB bus to run at 1/4th the CPU frequency, so 20MHz.
    OSCSetPBDIV(OSC_PB_DIV_4);

    // Enable multi-vector interrupts
    INTEnableSystemMultiVectoredInt();
    INTEnableInterrupts();

    // Configure Timer 2 using PBCLK as input. We configure it using a 1:16 prescalar, so each timer
    // tick is actually at F_PB / 16 Hz, so setting PR2 to F_PB / 16 / 100 yields a .01s timer.
    OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_16, F_PB / 16 / 100);

    // Set up the timer interrupt with a medium priority of 4.
    INTClearFlag(INT_T2);
    INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_4);
    INTSetVectorSubPriority(INT_TIMER_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
    INTEnable(INT_T2, INT_ENABLED);

/******************************** Your custom code goes below here ********************************/
    int check;
    OledInit();
    AdcInit();
    LEDS_INIT();
    check = GameInit();

    if(check == STANDARD_ERROR) {
        FATAL_ERROR();
    }
    float currPage;
    float binSize;
    float titleSize;
    float descSize;
    float numPages;
    uint8_t roomExit;
    uint16_t adcValue = 0;

    while(1) {
        roomExit = GameGetCurrentRoomExits();
        LEDS_SET(roomExit);
        while(buttonEvents == 0) {
            descSize = GameGetCurrentRoomDescription(roomData.description);
            titleSize = GameGetCurrentRoomTitle(roomData.title);

            numPages = ((titleSize + descSize) / MAX_OLED_PIXELS);
            binSize = (ADC_MAX_VALUE / numPages);

            if(AdcChanged()) {
                adcValue = AdcRead();
            }

            currPage = (adcValue / binSize);
            if(currPage < 1) {
                char titleArray[TITLE_OLED_SPACE] = {0};
                char descriptionBuffer[FIRST_PG_DESCRIPTION_OLED_SPACE] = {0};

                strncpy(descriptionBuffer, roomData.description, DESCRIPTION_COPY);
                sprintf(titleArray, "%s\n%s", roomData.title, descriptionBuffer);

                OledClear(OLED_COLOR_BLACK);
                OledDrawString(titleArray);
            } else {
                char buffer[MAX_OLED_PIXELS] = {0};
                int buffIndex;
                buffIndex = (int)currPage * MAX_OLED_PIXELS;
                strncpy(buffer, (roomData.description + buffIndex - OFFSET), MAX_OLED_PIXELS);

                OledClear(OLED_COLOR_BLACK);
                OledDrawString(buffer);
            }
            OledUpdate();
        }

        if((buttonEvents & BUTTON_EVENT_4UP) && (roomExit & GAME_ROOM_EXIT_NORTH_EXISTS)) {
            GameGoNorth();
        } else if((buttonEvents & BUTTON_EVENT_3UP) && (roomExit & GAME_ROOM_EXIT_EAST_EXISTS)) {
            GameGoEast();
        } else if((buttonEvents & BUTTON_EVENT_2UP) && (roomExit & GAME_ROOM_EXIT_SOUTH_EXISTS)) {
            GameGoSouth();
        } else if((buttonEvents & BUTTON_EVENT_1UP) && (roomExit & GAME_ROOM_EXIT_WEST_EXISTS)) {
            GameGoWest();
        }
        buttonEvents = BUTTON_EVENT_NONE;
    }



/**************************************************************************************************/
    while (1);
}