Wond3rboy
Member
Hi i made this simple AD Converter program in C18, the problem is that this does not execute on the breadboard.It is for an LM35 Sensor.I did manage it in assembly but for some reason its not workingin C.When i import the hex file in the downloader, it says that some config words have not been set but these were the same config settings i used in assembly and also used in
3V0's tutorial.Here is the code:
3V0's tutorial.Here is the code:
Code:
#include<p18f1320.h>
#define LED LATAbits.LATA7
#include<adc.h>
#pragma config LVP=OFF,OSC=INTIO2,WDT=OFF,DEBUG=ON
#pragma code hi_prioriint=0x008
void ADCData(void);
void chk_isr(void);
void hi_prioriint(void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma interrupt chk_isr
void chk_isr(void)
{
if(PIR1bits.ADIF)
ADCData();
}
void main( void )
{
INTCONbits.GIEH=1;
TRISB=0;
TRISA=0b01111111;
OSCCON=0X60; //4MHz
OpenADC(ADC_FOSC_8 &
ADC_RIGHT_JUST &
ADC_6_TAD ,
ADC_CH0 &
ADC_INT_ON &
ADC_VREFPLUS_EXT
, 0x72
);
SetChanADC( ADC_CH0 );
while(1)
{
ConvertADC();
while(BusyADC());
}
}
void ADCData(void)
{ unsigned int adcdata;
adcdata=ReadADC();
LATB=(adcdata>>2);
LED=~LED;
PIR1bits.ADIF=0;
}
Last edited: