# 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
#pragma config LVP=OFF,OSC=INTIO2,WDT=OFF,DEBUG=ON
#pragma code hi_prioriint=0x008
void chk_isr(void);
void hi_prioriint(void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma interrupt chk_isr
void chk_isr(void)
{
}

void main( void )
{
INTCONbits.GIEH=1;

TRISB=0;
TRISA=0b01111111;
OSCCON=0X60;    //4MHz
,			0x72
);
while(1)
{
}
}

LED=~LED;
}

Last edited:

#### Wond3rboy

##### Member
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!

#### Pommie

##### Well-Known Member
In MPLAB, check the status of Configure->Configuration bits->Configuration bits set in code.

Mike.

#### Wond3rboy

##### Member
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)

#### AtomSoft

##### Well-Known Member
C:\MCC18\h\eep.h

Its there with my c18 install so it should be there with yours.

#### be80be

##### Well-Known Member
Its there with my c18 install so it should be there with yours.
I have it in mine too maybe just not setting it right.

Last edited:

#### AtomSoft

##### Well-Known Member
file:///C:/MCC18/doc/periph-lib/EEPROM.htm

is the info for the eep.h

#### Wond3rboy

##### Member
C:\MCC18\h\eep.h

Its there with my c18 install so it should be there with yours.
I have it too lolz!

file:///C:/MCC18/doc/periph-lib/EEPROM.htm

is the info for the eep.h

#### AtomSoft

##### Well-Known Member
heh no problem. got a bit confused. Glad i could help.

#### Hakachukai

##### New Member
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.

#### AtomSoft

##### Well-Known Member
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.
Inline Assembly
MPLAB C18 provides an internal assembler using a syntax similar to the MPASM assembler. The block of assembly code must begin with _asm and end with _endasm. The syntax within the block is:

[label:] [<instruction> [arg1[, arg2[, arg3]]]]
The internal assembler differs from the MPASM assembler as follows:

No directive support
Comments must be C or C++ notation
Full text mnemonics must be used for table reads/writes. i.e.,
TBLRD
TBLRDPOSTDEC
TBLRDPOSTINC
TBLRDPREINC
TBLWT
TBLWTPOSTDEC
TBLWTPOSTINC
TBLWTPREINC
No defaults for instruction operands - all operands must be fully specified
Literals are specified using C radix notation, not MPASM assembler notation. For example, a hex number should be specified as 0x1234, not H'1234'.
Label must include colon
Indexed addressing syntax (i.e., []) is not supported - must specify literal and access bit (e.g., specify as CLRF 2,0, not CLRF [2])
For example:

_asm
/* User assembly code */
MOVLW 10 // Move decimal 10 to count
MOVWF count, 0
/* Loop until count is 0 */
start:
DECFSZ count, 1, 0
GOTO done
BRA start
done:
_endasm
It is generally recommended to limit the use of inline assembly to a minimum. Any functions containing inline assembly will not be optimized by the compiler. To write large fragments of assembly code, use the MPASM assembler and link the modules to the C modules using the MPLINK linker.

--------------------------------------------------------------------------------
Microchip Technology Inc.
Microchip Web Site
Voice: (480) 792-7200
Fax: (480) 792-7277
Microchip Technical Support

Help Updated: 07/09/09
14:13:39

Popup

Last edited:
Status
Not open for further replies.