void _int_(27) isr_adc(void){ int *p = (int *)(&ADC1BUF0); int i, media = 0; for(i=0; i<SAMPLES; i++){ media += p[i*4]; } media /= SAMPLES; if(media > 0x299){ T1CONbits.TON = 1; OC1CONbits.ON = 0; }else{ T1CONbits.TON = 0; OC1CONbits.ON = 1; LATE = (LATE & 0xF0); } adc_percentage = (media*100)/1023; printInt10(adc_percentage); putChar('\n'); AD1CON1bits.ASAM = 1; IFS1bits.AD1IF = 0; }
void main(void) { spi2_init(); spi2_setClock(EEPROM_CLOCK); for(;;) { printInt10(eeprom_readStatus() & 0x0F); putChar('\n'); } }
int main(void){ while(1){ int temperature; if(getTemperature(&temperature) == 0){ printInt10(temperature); printStr("\e[G"); } delay(250); }
int main(void) { // Configure A/D module; int i = 0, V = 0; double average = 0; double sum = 0; TRISBbits.TRISB14 = 1; // RB4 digital output disconnected AD1PCFGbits.PCFG14 = 0; // RB4 configured as analog input (AN4) AD1CON1bits.SSRC = 7; // Conversion trigger selection bits: in this // modeaninternalcounterendssamplingand AD1CON1bits.CLRASAM = 1; // Stop conversions when the 1st A/D converter AD1CON1bits.ON = 1; AD1CON3bits.SAMC = 16; // Sample time is 16 TAD (TAD = 100 ns) AD1CHSbits.CH0SA = 14; AD1CON2bits.SMPI = 3; // uma conversao consecutiva while(1){ delay(10); // Wait 10 ms using the core timer if(i++ == 25) // 250 ms { AD1CON1bits.ASAM = 1; // Start conversion while(IFS1bits.AD1IF == 0 );// Wait while conversion not done (AD1IF == 0) int *p = (int *)(&ADC1BUF0); for( i = 0; i < 16; i++ ){ printInt10(p[i*4]); sum += p[i*4]; printStr("\n"); } average = sum/4; printf("%s %f","Média dos valores lidos: ", average ); V = (average*33+511)/1023; printStr("\n"); printf("%s %d","Tensão: ", V ); i = 0; sum = 0; average = 0; IFS1bits.AD1IF = 0; // Reset AD1IF V = toBCD(V); } send2displays(V); } return 0; // Consoante o número de conversões consecutivas, aparecerão os valores até 15 conversões consecutivas }
void send2displays(unsigned char value) { if (c < 3 || c > 8) displayFlag = 1; else displayFlag = 0; printInt10(value); putChar('\n'); if (!displayFlag) LATB = (LATB & 0xFC00) | snakeCodes[value] | 0x0200; else LATB = (LATB & 0xFC00) | snakeCodes[value] | 0x0100; }
int main(void) { int delay; int ack, temperature; i2c1_init(TC74_CLK_FREQ); while(1) { //start event i2c1_start(); //send write addr ack = i2c1_send(ADDR_WR); //command (read temp) i2c1_send(RTR); //start event i2c1_start(); //send read addr ack += i2c1_send(ADDR_RD); //printInt10(ack); if (ack != 0) { i2c1_stop(); printStr("An error has ocurred, exiting.\n"); } else { printStr("\nReading temperature: "); temperature = i2c1_receive(I2C_NACK); i2c1_stop(); printInt10(temperature); } //delay 250ms delay = readCoreTimer(); while (readCoreTimer() - delay < 5000000); } return 0; }