void APP_Initialize ( void ) { //stopEverything(); /* Place the App state machine in its initial state. */ appData.state = APP_STATE_INIT; /* TODO: Initialize your application's state machine and other * parameters. */ //Create the queue appData.local_q = xQueueCreate(10, sizeof(unsigned int)); //Ensure queue was created. If not, do not continue and turn on LED if(appData.local_q == 0) { stopEverything(); } appData.sensor1_q = xQueueCreate(100, sizeof(unsigned char)); if(appData.sensor1_q == 0) { stopEverything(); } //stopEverything(); //Create the timer appData.local_timer = xTimerCreate( "50msTimer", 50 / portTICK_PERIOD_MS, pdTRUE, 0, vTimerCallback ); //Ensure timer was created. If not, do not continue and turn on LED if(appData.local_timer == 0) { stopEverything(); } BaseType_t started = xTimerStart(appData.local_timer, 0); //Ensure the timer started successfully. If not, do not continue and turn // on LED if(started == pdFAIL) { stopEverything(); } //Setup AD Driver SYS_INT_SourceEnable(INT_SOURCE_ADC_1); DRV_ADC_Initialize(); DRV_ADC_Open(); DRV_ADC_ChannelScanInputsAdd(ADC_INPUT_SCAN_AN0 | ADC_INPUT_SCAN_AN1|ADC_INPUT_SCAN_AN2); PLIB_ADC_MuxAInputScanEnable(ADC_ID_1); DRV_ADC_Start(); /* Initialization is done, allow the state machine to continue */ appData.state = APP_STATE_OUTPUT; }
void toggleLedForever() { volatile int num = 0; writeReg(IODIRA, 0x00); // writeReg(GPPUA, 0xff); writeReg(IODIRB, 0x00); //writeReg(GPPUB, 0xff); DRV_ADC_Open(); DRV_ADC_ChannelScanInputsAdd(DRV_ADC_INPUT_POSITIVE_AN11); DRV_ADC_Start(); /* Open the Device Layer */ LATF = 0; volatile int i = 0; while(1) { if(num%256 ==0) LATFINV = 0x00000002; for(i = 0; i < 0x3fff; i++); num++; static int adcVal = 0x1234; if((num%256 == 0)) { adcVal++; if(DRV_ADC_SamplesAvailable()) { adcVal = DRV_ADC_SamplesRead(0); DRV_ADC_Start(); } } writeReg(GPIOA, 0x0F); char adcHexDigit = (adcVal >> (4*(num%4))) & 0xf; int voltage = (adcVal*3300) / 1024; int temp = (voltage - 500) / 10; int digit = 16; int nDigit = (num%4); if (nDigit == 1) digit = abs(temp) / 10; else if(nDigit == 0) digit = abs(temp) % 10; else if(nDigit == 2 && temp < 0) digit = 18; writeReg(GPIOB, ~(numberPattern[digit])); writeReg(GPIOA, 0x0F & (~(1 << (num%4)))); } }