You are on page 1of 1

#include "p30f4013.

h"
#include "libpic30.h"
#include "dspic.h"

int a=0;
int value1=0x0000,value2=0x0000,value3=0;
int main(){
TRISB=0X7800;
TRISD=0X0000;
ADCON1bits.FORM=0B11;
ADCON1bits.SSRC=0B111;
ADCON1bits.ASAM=0B1;
ADCON2bits.VCFG=0;
ADCON2bits.ALTS=0;
ADCON3bits.SAMC=0B0001;
ADCON3bits.ADRC=1;
ADCON3bits.ADCS=0B000001;
ADCHSbits.CH0NA=0;
ADPCFGbits.PCFG12=0;//analog mode 12
ADPCFGbits.PCFG11=0;//analog mode 11
//enabling the interrupts
IPC2bits.ADIP=1;//interrupt highes priority
IFS0bits.ADIF=0;//clears interrupt flag
IEC0bits.ADIE=1;//INTERRUPT REQUEST ENABLE
CORCON = 0x0000;
ADCHSbits.CH0SA=0B1100;//select the 3 channel
ADCON1bits.ADON=1;//enable adc module
while(1){
__asm__("MOV _value1,W4");//high frequency
__asm__("MOV _value2,W5");//low frequency
__asm__("MPY W4*W5,A");
__asm__("SAC A,w6");
//__asm__("MOV W6,W5");//result of multiplication to w5
//__asm__("MPY W4*W5,A");//result of multiplication(w5)xhigh
frequency(w4)
//__asm__("SAC A,w6");
__asm__("_value3=w6");
value3^=(1<<15);
PORTB=((value3>>3)&0x07ff);
PORTDbits.RD0=(value3>>14);
}
return 0;
}

void _ISR _ADCInterrupt(void){


IFS0bits.ADIF=0;
if(a==0){
value1=ADCBUF0;//bitshift for the correction of value
ADCHSbits.CH0SA=0B1011;//select the 11 channel
a=1;
}
else if(a==1){
value2=ADCBUF0;//bitshift for the correction of value
ADCHSbits.CH0SA=0B1100;//select the 12 channel
a=0;
}
}

You might also like