Trying to C but can not see

Status
Not open for further replies.

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:


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:
I think its the problem of the software but i have reinstalled all MPLAB,C18 and the downloader.Amazingly the program works if i export the hex file.


Man.. i always have weird porblems!
 
In MPLAB, check the status of Configure->Configuration bits->Configuration bits set in code.

Mike.
 
It was unchecked

Also i have a few questions about C18,

First about atomsofts cheat sheet, i dont find the usage of eep.h listed any where in the C18 libraries document.Is it documented anywhere?I was getting errors when i called it multiple times(made it in to a function) and then called it a number of times(used variables as address and data).Had to write it manually.

Secondly about the limitations of the _asm..._endasm directive.I noticed that we could not write in to registers(SFR's) except W.If i am wrong then correct me.I was thinking if we could just move values to SFR's directly using asm, we could save code lines.Examples of such commands are:

MOVWF LATB (The error says incorrect arguments for MOVWF)

BCF EECON1,EEPGD(Same error)
 
MOVWF LATB (The error says incorrect arguments for MOVWF)
BCF EECON1,EEPGD(Same error)

I haven't done any PIC C, but I've used Gcc a lot on X86 platforms. So, I have 2 ideas:

#1. Check to see if LATB, EECON1 and EEPGD are defined. If they are not, you'll have to define them yourself as the numerical values that they represent.

#2. Some C compilers require regs in inline assembly statements to be preceeded by special charactors. So it might need to be something like:
Code:
movwf %%LATB
bcf %%EECON1,EEPGD

These are just suggestions. I know that i've run into issues like that before with other C compilers.
 
If its inline asm you have to specify something else...

BCF EECON1,EEPGD

try

BCF EECON1,EEPGD,0

This is becuase:

No defaults for instruction operands - all operands must be fully specified
The blow can be found in hlpC18ug aka C18 User Guide. search inline assembly and you will get this. You have to specify all the info nothing has default values.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…