#pragma interruptlow LowISR
void LowISR(void)
{
if(PIR1bits.TMR1IF = 1)
{
ADCON0bits.GO = 1;
while(ADCON0bits.GO) // Conversión en progreso
{
if(i < 100)
{
valor[i] = ADRESL;
i = i + 1;
}
}
TMR1L = 0x4C;
TMR1H = 0xFF;
PIR1bits.TMR1IF = 0;
}
return;
}
#pragma code lowVector=0x18
void LowVector(void){_asm goto LowISR _endasm}
void adcinit(void);
void main(void)
{
adcinit();
while(1)
{
LowISR();
i = 0;
}
}
void adcinit(void)
{
ADCON0 = 0x01;
ADCON1 = 0x0E;
ADCON2 = 0x86; // Justificacion derecha, Fosc/64
//Timer 8 KHz
T1CONbits.RD16 = 1; // 8 bits
T1CONbits.T1RUN = 0;
T1CONbits.T1OSCEN = 0; // Oscilador Timer1 deshabilitado
T1CONbits.T1CKPS1 = 0; // Prescaler 1:1
T1CONbits.T1CKPS0 = 0;
T1CONbits.TMR1CS = 0; // Fosc/4
T1CONbits.TMR1ON = 1; // Enciende Timer1
//Interrupcion
PIE1bits.ADIE = 0;
PIE1bits.TMR1IE = 1; // Timer1
IPR1bits.TMR1IP = 0; // Interrupción baja prioridad
RCONbits.IPEN = 1; // Habilita prioridad de interrupcion
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
TMR1H = 0xFC; // Pre-carga Timer
TMR1L = 0x18;
}