SPI

Master SPI Port Initialise #define INTERBOARD_COMMS_SS_PIN LATDbits.LATD3 #define INTERBOARD_COMMS_PACKET_LENGTH 10 //—– SETUP SSP2 AS SPI BUS —– //Used for: //CLK idle in low state //Devices clock in data on the rising edge, output data on the falling edge SSP2STAT = 0b11000000; SSP2CON1 = 0b00100010; //16MHz Fosc / 64 = 250000kHz //—– INIT SPI —– //Send […]

Read More

Assembler

ISSUE – Destination and RAM access bit specified This used to be requried for asm code when you wanted to tell it the ,d and ,a bits of the instruction: near static unsigned char uc_asm_irq_temp; // near qualifier specifies access RAM near static unsigned char uc_asm_irq_temp1; movlw 0xcb addwf _uc_asm_irq_temp,f,c //(1 = file register, 0 = […]

Read More

I2C

  //———————————————– //—– SETUP SYNCHRONOUS SERIAL PORT (SSP) —– //———————————————– //—– SETUP SSP AS I2C —– //Used for: LED Driver //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 […]

Read More

.XC8 BASIC SETTINGS FOR NEW PROJECTS

Right click project > Properties > XC8 global options > XC8 Compiler Select 'Optimizations' Speed & Debug checkboxes Set as needed (off and on is good for debugging) Address qualifiers – VERY IMPORTANT!!!! If you are using anything that requires locating in specific memory locations set this to 'Require', e.g. variables used in assembler, etc. […]

Read More

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 […]

Read More