PIC24FJ256GB106 //—– SETUP TIMER 2 —– //Used for: PWM T2CON = 0x0000; //16 bit, 1:1 prescale TMR2 = 0; PR2 = 0x0fff; //<This sets the PWM resolution //—– OC1 —– //Used for: Intensity PWM OC1CON1 = 0x0000; //Turn off Output Compare 1 Module OC1R = 0x0000; //Initial PWM period OC1RS = 0x0000; //Set PWM period […]
All posts by
.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
.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 C30 compiler and add these files into the project. PIC24FJ256GB106 main.h – Generic project header file main.c – main C file main.h – header file for main.c
Defines
Microchip define examples #ifdef __DEBUG //Debug mode selected in MPLAB #if defined(__18CXX) #elif defined(__C30__) #elif defined (__PIC32MX__) #else #endif #ifndef __DEBUG #if (defined(__18CXX) & !defined(PIC18F87J50_PIM)) #endif #if defined(PIC18F87J50_PIM) || defined(PIC18F46J50_PIM) #if defined(__PIC24FJ256GB110__) #if defined(__18F46J50) Is This Microcontoller In Use #if defined( __PIC24FJ256GB106__ ) #if defined(__PIC24FJ256GB110__) || defined(__PIC24FJ256GB106__) || defined(__PIC24FJ256GA110__) || defined(__PIC24FJ256GB210__) Handy UART Setup Example #define […]
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.
Locating things in Pogram memory
//—– CONSTANTS LOCATED IN PROGRAM MEMORY —– #pragma romdata firm_upgrade_code_markers_romdata_section=0x0009fc const rom WORD firmware_upgrade_marker_1 = OUR_PRODUCT_ID; const rom WORD firmware_upgrade_marker_2 = OUR_FIRMWARE_REVISION; #pragma code normal_section=0x000a00 extern void _startup (void); // See c018i.c in your C18 compiler dir #pragma code _RESET_INTERRUPT_VECTOR = 0x000a00 void _reset (void) { _asm goto _startup _endasm } #pragma code Using […]
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 […]
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' […]
Assembler
Using Assembler _asm goto _reset _endasm