uint32_t SRAND_GetSeed(void) { #define WIFIRE_POT_ADC_CH_INDEX (8) unsigned int result = 0; #ifdef __32MZ2048ECG100__ AD1CON3bits.RQCONVRT = 1; while (AD1DSTAT1bits.ARDY8 == 0); result = AD1DATA8; #else DRV_ADC_Start(); while (!DRV_ADC_SamplesAvailable(WIFIRE_POT_ADC_CH_INDEX)) ; result = DRV_ADC_SamplesRead(WIFIRE_POT_ADC_CH_INDEX); DRV_ADC_Stop(); #endif return result; }
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)))); } }