UART

PIC24 UART Full Duplex https://github.com/ibexuk/C_Communications_UART_PIC24_Full_Duplex  

Read More

SPI

SPI Master //—– SETUP SPI 1 —– //Used for: w_temp = SPI1BUF; SPI1STAT = 0; SPI1CON1 = 0b0000001100100001; //SPI in master mode (SPI1STATbits.SPIEN must be 0 to write to this register) //Data is valid on the rising edge of the clock (Transmit occurs on transition from active to idle clock state) //Clock low in idle […]

Read More

I2C

  //—– SETUP I2C 1 —– //Used for: EEprom w_temp = I2C1RCV; I2C1ADD = 0; I2C1BRG = 395; //157=100KHz@16MIPS, 395=100KHz@40MIPS (typically 100kHz, 400kHz or 1MHz) I2C1STAT = 0; I2C1CON = 0; I2C1CONbits.I2CEN = 1; //Enable I2C          

Read More

AtoD

PIC24FJ256GB106 Auto Sampling //—– SETUP THE A TO D PINS —– //AN0, AN1, AN11 analog //Auto scan of inputs AD1PCFGL = 0xF7FC; //Set the analog pins (0 = analog) AD1PCFGH = 0xFFFF; AD1CON2 = 0x0408; AD1CON3 = 0x1F05; AD1CHS = 0x0000; AD1CSSL = 0x0803; //Set the inputs to scan AD1CON1 = 0x80E4; //AD1CON2 SMPI (interrupts […]

Read More

PWM

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

Read More

.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

Read More

Reset Function

Soft Reset asm("reset"); Reset Function Generally the C30 will use the startup module to do some setup works. Refer to the device linker script file (p24HJ256GP206.gld), there are something like: OUTPUT_ARCH("24HJ256GP206") CRT0_STARTUP(crt0_standard.o) CRT1_STARTUP(crt1_standard.o) OPTIONAL(-lp24HJ256GP206) The CRTn_STARTUP commands specify two C run-time startup modules to be loaded from archives. The linker will select one of these […]

Read More

Peripheral Libraries

Peripheral Library Documentation You need to go to the library files themselves for the documentation – its not in MPLAB help: C:\Program Files (x86)\microchip\MPLAB C30\docs\periph_lib\

Read More

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

Read More