Asked: sourcecode for internal ADC interrupted driven

Thread Starter

mcu_pic32

Joined Mar 19, 2009
1
Dear All

Can someone post an example where an internal ADC of an MCU 16F877A is used, but interrupt driven.
I ask this because the in -build function ADC read ()doesn't work with interrupts and I need this.
Can you control my code in asm and C where I use the internal ADC with interrupts.

Its for my only interesting the internal ADC (buildin on the MCU) interrupt driven written in assembly or c code

I'm using the MCU 16F877A and my EasyPIC4
For compiler MicroC


Best regards,

I coded the next examples:

Code:

; =============================================
; Normally ISR routine with interrupts
; =============================================
GET_ADC: MOVLW 0x07 ; load pointer
MOVWF COUNT ; and delay 20µs
down DECFSZ COUNT ; repeat until counter <> 0
GOTO down ;
BSF ADCON0,GO ; start ADC conversion
wait BTFSC ADCON0,G0 ; if GO <> 0 repeat
GOTO wait
RETURN



Code:


float GetVoltage(void);
void main(void);

float GetVoltage()
{
ADCON0.GO = 1;
while(ADCON0.GO == 1);
return(ADRESL | (ADRESH << 8));
}

void main()
{
ADCON0 = 0x01;
ADCON1 = 0x0E;
ADCON2 = 0x84;
TRISA = 1;
PORTA = 0;

while(1)
{
// other code that used the ADC internal
}
}
 
Top