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; } } }
void IOShieldOledClass::displayOn() { OledDisplayOn(); }