These example files can be used as the starting point for a new project in MPLAB. Use the project wizard, select the C18 compiler and add these files into the project. PIC18F2520 main.h – Generic project header file main.c – main C file main.h – header file for main.c
Category: ~C18 (old)
Memory(2)
Assembler
Using Assembler _asm goto _reset _endasm
Compiler Version
Viewing compiler version Project > Select Language Toolsuite
Configuration Bits
You can get the config field defines from the C:\Program Files (x86)\Microchip\mplabc18\v#.##\mpasm\ .inc file for your PIC18 device
Errors
New Project Error Could Not Find File 'c018i.o' Enter the proper directory path in Project>Build Options…>Project > Directories tab. Set the Library Path to “C:\mcc18\lib”. PRESS APPLY!! c018i.o is the start-up library for MPLAB There is no need to select the linker script to use or anything else Error – Coff file format for 'C:\mcc18\lib/c018i.o' […]
I2C
//—– SETUP SSP AS I2C —– //I2C requirements:- 100kHz clock high time 4.0uS, clock low time 4.7uS, 400kHz clock high time 0.6uS, clock low time 1.3uS //The PIC18 does not fully conform to the 400kHz I2C spec (which applies to all rates >100kHz) but may be used with care //where higher rates are required. //Lower […]
IO Pins
//INPUT if (PORTBbits.RB0) //OUTPUT LATBbits.LATB0 = 0;
Linker Files
C18 Linker Files For older versions of the compiler these were in: c:\mcc18\bin\LKR\ directory (c:\mcc\lkr folder is obsolete) For newer version ther are in: C:\Program Files (x86)\Microchip\mplabc18\v3.42\bin\LKR
Pointers
If you find program memory const pointers are not working check the compiler memory model is set to large > 64KB if you are using a PIC18 with >64KB of program memory. If not when accessing constants that are at addresses > 0xffff you’ll access the lower memory equivalent.
PWM
PWM Setup PWM Period = [(PR2) + 1] x 4 x TOSC x (TMR2 Prescale Value) PWM Duty Cycle = (CCPR4L:CCP4CON<5:4>) x TOSC x (TMR2 Prescale Value) So your PWM period is adjustable using an 8bit PR# value and a 2 bit timer prescaller value (x1, x4, x16) and is based on the instruction clock speed (4 […]