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 […]
Category: ~C18 (old)
Memory(2)
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
SPI – PIC18
//—– SETUP SSP1 —– //Used for: //CLK idle in low state //AT45DB081 clocks in data on the rising edge, outputs data on the falling edge SSPSTAT = 0b01000000; SSPCON1 = 0b00100000; //Fosc / 4 = 10MHz
Compiler Version
Viewing compiler version Project > Select Language Toolsuite
IO Pins
//INPUT if (PORTBbits.RB0) //OUTPUT LATBbits.LATB0 = 0;
Reset
Reset();
.Example Project Files
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
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.
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
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 […]