Questions tagged [mplab-c18]

For questions specifically about the MPLAB C Compiler for PIC18 MCUs (also known as MPLAB C18). This is a C89-compatible compiler for Microchip's PIC18 series of microcontroller units. DO NOT USE this tag for questions about the C standard ISO 9899:2018—use the [c17] tag for that.

C18 is Microchip's C compiler for PIC18 MCUs. Some of its main features are compatibility with Microchip's MPLAB and MPLAB X IDEs, Microchip's hardware and software debuggers, support for code size optimizations, support for PIC18F extended mode instructions and library support for SPI, I2C, PWM, UART, string manipulation and math.

It is available in free LITE version which doesn't support size optimizations and PIC18F extended mode instructions.

Official website of the compiler is here.

Microchip is currently phasing out the C18 compiler in favour of new XC8 compiler.

46 questions
10
votes
2 answers

Use external header files in MPLAB X IDE

I have a folder with some .h and .c files and I want to use header files in my projects. I have included them in "Header Files" folder of my project using "Add Existing Item" but when i try to "#include" them compiler(mplabc18\v3.41) say "unable to…
blow
  • 12,811
  • 24
  • 75
  • 112
4
votes
1 answer

Char array comparison in C

I have following function to compare two char arrays in C: short test(char buffer[], char word[], int length) { int i; for(i = 0; i < length; i++) { if(buffer[i] != word[i]) { return 0; } } return…
CAPS LOCK
  • 1,960
  • 3
  • 26
  • 41
3
votes
2 answers

C18: Do unused library functions consume space in EPROM?

Library.h void Foo1(void); // Unused int Foo2(int, int); // Used char Foo3(char); // Unused main.c // ... #include "Library.h" // ... void main(void) { int ret; // ... ret = Foo2(3, 7); // ... } I have a library…
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
3
votes
1 answer

C18 pseudo variables

I'm looking for a way to make Jalv2-like pseudo variables in C using the C18 compiler. A pseudo variable is something that acts like a variable but actually is a function. In Jalv2, it's possible to make a pseudo variable like this: function…
user1544337
3
votes
1 answer

Pointer for ROM variable in a RAM variable?

I'm doing a project using the Microchip C18 compiler. I have a struct called a block that points to other blocks (north east south west). These blocks will make me a map. I then have a pointer that I use to evaluate everything. Just using RAM it…
Cal Pratt
  • 33
  • 1
  • 4
2
votes
4 answers

parsing ip adress string in 4 single bytes

I'm programming on a MCU with C and I need to parse a null-terminated string which contains an IP address into 4 single bytes. I made an example with C++: #include int main() { char *str = "192.168.0.1\0"; while (*str != '\0') …
BETSCH
  • 104
  • 2
  • 3
  • 8
2
votes
2 answers

PIC C18: Reading bits from a byte

I have a very elementary question. However, what ever I tried, I couldn't successfully implement this. I have a shift register (74LS164) connected to PIC18F2550 with the following hardware configuration: // Data pin #define SCLCD_DATA …
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
2
votes
1 answer

MPLAB gives Low power and device failed to connect error when programming pic18f25q10

I am trying to add a simple led application to a PIC18F25Q10 in another circuit using the Curiosity HPC development board. I am using the MCLR, PGD, PGC and GND pins. Although I set the LVP mode to enable in the CONFIG settings and the program speed…
fthelb
  • 23
  • 5
2
votes
2 answers

Concatenate 5 or more bytes and convert to decimal and then to ASCII

I've this array below: dataIn[5] = 0x88; dataIn[6] = 0x2A; dataIn[7] = 0xC7; dataIn[8] = 0x2B; dataIn[9] = 0x00; dataIn[10] = 0x28; I need to convert those values to decimal because after that I need to convert the decimal values into ASCII and…
2
votes
2 answers

const function parameters in prototypes but not declarations (in C)

When writing code in C, I often include const in function parameter declarations in the function's definition, but not its declaration: int func(int arg); ... int func(int const arg) { return arg + 1; } This has always compiled for me without…
thetic
  • 174
  • 1
  • 11
2
votes
2 answers

Using enums and switch in functions (C18 Compiler)

I recently started rewriting a program to make it more easy to understand and I started using enums for describing the different states my program can be in. byte VoltageLimit(byte progState, word voltage) { switch(progState){ case…
Grossu Iulian
  • 275
  • 1
  • 2
  • 10
2
votes
2 answers

What is the difference between the Microchip XC8 and C18 compilers?

I want further understand the difference between XC8 & C18 compiler. I know that XC8 is the latest compiler for all 8-bit microchip controllers. e.g. PIC16F, PIC18F. And C18 is the compiler for their PIC18 products. For C18, PIC18 series include…
TJCLARK
  • 489
  • 1
  • 5
  • 19
2
votes
2 answers

reading pic18 rom constants with C18

I am struggling to understand why I get random data while trying to read from multidimensional table that is stored in rom. I have a table of bitmap character which I want to display on OLED screen. Table of characters is too big to fit into ram…
user2771538
  • 103
  • 1
  • 10
2
votes
1 answer

Suspcicious pointer conversion warning

I'm compiling my C code using Microchip's C18 compiler. I'm getting a warning [2054] suspicious pointer conversion in this code: unsigned char ENC_MAADR1 = 0x65; unsigned char ENC_ReadRegister(unsigned char address); //…
user1544337
2
votes
2 answers

How does C handle non-booleans in an if statement?

I sometimes see this in a C program (I'm using the C18 compiler): unsigned char someValue = getSomeDataFromSomewhere(); if (someValue) { doStuff(); } else { doOtherStuff(); } I know what happens when you give an if loop a boolean (unsigned…
user1544337
1
2 3 4