I2C without using XC32 library

Master Fast Read (no write of regsiter address first) #define MEMS_SENSOR_I2C_MASTER_IRQ_FLAG 0x0080 i2c_comms_failed = 0; //—– SEND THE START CONDITION —– I2C4CON |= 0x0001; //Set SEN while (I2C4CON & 0x0001) //Wait for SEN to clear ; //—– SEND THE I2C DEVICE ADDRESS WITH THE READ BIT SET —– IFS1 &= ~MEMS_SENSOR_I2C_MASTER_IRQ_FLAG; I2C4TRN = (MEMS_SENSOR_B_I2C_ADDRESS | […]

Read More

XC32 Timers

Using A Timer OpenTimer2((T2_ON | T2_IDLE_CON | T2_GATE_OFF | T2_PS_1_1 | T2_SOURCE_INT), 40); INTClearFlag(INT_T2); while (!INTGetFlag(INT_T2)) ;    

Read More

uS Delay

This works really well in XC8 //******************************* //******************************* //********** DELAY #uS ********** //******************************* //******************************* void ds18b20_delay_us(volatile unsigned char us_count) //input value will be in W. "Volatile" attribute prevents an "unused" warning. { #asm temp_ds18b20_dlyloop: addlw 0xFF ;1 clk 0xff=-1, 0xfe=-2, etc //<<<<<<<<<<<<<<<<<<<<SET AS NEEDED btfsc STATUS,0 ;1 clk will be clear if W was smaller […]

Read More

PIC18 AtoD

Not using AtoD //—– SETUP THE A TO D PINS —– ADCON0 = 0b00000000; //AtoD disabled //ADCON1 = 0b00000000; //ADCON2 = 0b10111110; //Right justified ANSELA = 0b00000000; //0 = digital ANSELB = 0b00000000; ANSELC = 0b00000000; Using AtoD Initialise //—– SETUP THE A TO D PINS —– VREFCON0 = 0b10110000; //FVR enabled, set to 4.096V […]

Read More

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

.New XC8 Project

New XC8 Projects Is your chosen PIC18 properly supported by XC8 V2 & MCC? You want it to be! The MCC release note lists the supported devices, under section “Supported devices”.The Release Note is available on the MCC page (microchip.com/mcc) >> Documentation >> For Current Release >> MCC Release Notes If its not then ideally […]

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: In a classic Microchip “lets make life difficuilt for programmers step” the 1 and 0 values the PIC device datasheets specify for these bits can’t actually […]

Read More

XC8 – peripheral library support is missing for the …

"Warning peripheral library support is missing for the 18F45K22" Right click project > properties > Conf: -> XC8 global options -> XC8 linker "Link in Peripheral Library" is causing it if set, but if you are using peripheral library functions you need this.  There seems to be some issue with XC8 no longer shipping with the peripheral […]

Read More