PIC24HJXXXGPX06/X08/X10 //10MHz Osc //= 80MHz with /2, x32, /2 PLL //= 40MIPS //= 25nS per instruction //How it works: //Input OSC = 10MHz (1.6 MHz to 16MHz required) //10MHz / 2 = 5MHz (0.8 MHz to 8 MHz required) //PLLFBD = 30 = x32 = 160MHz (100 MHz to 200 MHz required) //CLKDIV 7:6 = […]
All posts by
Locating things in Program memory
Locating things in Pogram memory //—– CONSTANTS LOCATED IN PROGRAM MEMORY —– #ifdef FLASH_FIRMWARE_VALUES_LOCATION #ifndef __DEBUG //Don't do in devel mode to reduce the programming time if these are being located at the end of the memory space const unsigned int __attribute__ ((space(psv), address (FLASH_FIRMWARE_VALUES_LOCATION))) firmware_upload_markers [2] = {OUR_PRODUCT_ID, OUR_FIRMWARE_REVISION}; #endif #endif //A function int […]
I2C
//—– SETUP I2C 1 —– //Used for: temperature sensor I2C1CONbits.I2CEN = 0; I2C1BRG = 93; //400kHz @ 40MHz Fcy I2C1CONbits.I2CEN = 1;
Converting old DSPIC firmware
EEprom definitions section(“.eedata,r”) changes to space(eedata) See ww1.microchip.com/downloads/cn/DeviceDoc/cn023342.pdf
Constant Pointers In Program Memory
Constants In Program Memory Issues Although PIC24 has 3 bytes per instruction, you can only store data in 2 of them. Therefore program memory usage is 3x actaul data size. C30 uses 16 bits for pointers. By default it expects all constants to be in 32K of program memory address space. This is a limitation […]
Assembler
Notes Bit Numbers Use # in front of the number, so bit 0 is "#0" Special Function Registers You can use SFR's in the assembler directly instead of including via an input or output. Doing this is faster as the compiler won't move the SFR via W0 and instead will access it directly. Multiple Assembler Statements Use "/n" to […]
IO
IO Defines //Output define examples #define MY_OUTPUT _LATD0 #define MY_OUTPUT(state) _LATF0 = state //<<<This method better for compatibility with with other compilers #define MY_OUTPUT(state) LATCbits.LATC1 = state //Input define examples #define MY_INPUT _RF2 //Port define examples #define DATA_BUS_IP PORTD #define DATA_BUS_OP(data) LATD = data #define DATA_BUS_TRIS(state) TRISD = state Peripheral Pin Select //—– INPUTS —– […]
High Low
Getting High and Low Byte Of A 16 Bit Value movlw high 8332 movwf spbrgh movlw low 8332 movwf spbrg
Debounce Switches
Simple Debounce Only ;debounce the switches movf sw_inputs_0,w andwf sw_inputs_0_last,w movwf switches_debounced_0 movf sw_inputs_0,w movwf sw_inputs_0_last Detect New Keypresses Too ;—– DEBOUNCED SWITCHES —– #define SW_LCD_BRIGHTNESS_UP_PRESSED b0_switches_debounced_0,0 #define SW_LCD_BRIGHTNESS_DOWN_PRESSED b0_switches_debounced_0,1 ;—– NEW KEYPRESSES —– #define SW_LCD_BRIGHTNESS_UP_NEW b0_switches_new_0,0 #define SW_LCD_BRIGHTNESS_DOWN_NEW b0_switches_new_0,1 ;*********************************** ;*********************************** ;********** READ SWITCHES ********** ;*********************************** ;*********************************** read_switches clrf b0_switches_new_0 btfss b0_do_sw_read ;Set by […]