Old C18 Code //********************************************** //********** HIGH PRIORITY INTERRUPTS ********** //********************************************** #pragma code highVector=0x08 void athighvector (void) { _asm GOTO interruptisrh _endasm } #pragma code //********************************************* //********** LOW PRIORITY INTERRUPTS ********** //********************************************* #pragma code lowVector=0x18 void atlowvector (void) { _asm goto interruptisrl _endasm } #pragma code // give back code control New XC8 Code Dont' bother […]
All posts by
Assembler variables to be located in access ram
Old C18 code //Inline assembler access bank variables #pragma udata access acssect // "acssect" is the section label near unsigned char uc_asm_irq_temp; // near qualifier specifies access RAM near unsigned char uc_asm_irq_temp1; #pragma udata New XC8 Code //Inline assembler access bank variables near static unsigned char uc_asm_irq_temp; // near qualifier specifies access RAM near static […]
Location Of Linker Scripts
Default Location C:\Program Files (x86)\Microchip\xc16\v1.10\support\PIC24F\gld\
Large Data Arrays
XC16 can accept up to 8k of data in near memory. Above that you can use compiler options to allow for larger memory access of specify individual arrays for far memory using the far attribute. far Attribute to locate large arrays in far memory BYTE edid_emulation_buffer[16384] __attribute__ ((far)); extern BYTE edid_emulation_buffer[16384] __attribute__ ((far)); eds Attribute […]
Configuration of projects
Places where your project may be configured in MPLAB X Files or directories included in compiler preprocessing Right click project > Properties > Select the configuration you are using for your project > XC16 (Global Options) > xc16-gcc > Option categories: Preprocessing and message > C include dirs This is where the basic device config […]
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 […]
Quadrature Encoder Inputs
Setup Quadrature Encoder Inputs dsPIC33EP256MU806 example: //——————————————- //—– SETUP QUADRATURE ENCODER INPUTS —– //——————————————- //—– SETUP QEI 1 —– QEI1CONbits.QEIEN = 0; //Module counters are disabled QEI1CONbits.CCM = 0; //Quadrature Encoder mode QEI1CONbits.PIMOD = 0; //Index input event does not affect position counter QEI1CONbits.IMV = 0; //Index input event does not affect position counter […]
I2C
//—– SETUP I2C 2 —– //Used for: I2C2CONbits.I2CEN = 0; I2C2BRG = 93; //400kHz @ 40MHz Fcy I2C2CONbits.I2CEN = 1;
Timers
Setup Timers #include <timer.h> //—– SETUP TIMER 4/5 —– //Used for: Heartbeat OpenTimer45(T4_ON & T4_GATE_OFF & T4_PS_1_1 & T4_SOURCE_INT, (INSTRUCTION_CLOCK_FREQUENCY / 1000)); //1mS irq, 1:1 prescaller WriteTimer45(0); ConfigIntTimer45(T4_INT_PRIOR_1 & T4_INT_ON); //Interrupt priority level 1 //—– SETUP TIMER 6 —– //Used for: Buzzer PWM //4000Hz = 250uS per complete PWM cycle T6CON = 0x8000; //Timer on, […]
Interrupts
Example Interrupt Functions //Timer 45 Interrupt void __attribute__((interrupt, auto_psv)) _T5Interrupt(void) { _T5IF = 0; //Clear interrupt flag //Timer 6 interrupt void __attribute__((interrupt, auto_psv)) _T6Interrupt(void) { _T6IF = 0; //Clear interrupt flag //Timer 7 interrupt void __attribute__((interrupt, auto_psv)) _T7Interrupt(void) { _T7IF = 0; //Clear interrupt flag