Introduction To Programming The PIC32
Introduction To Programming The PIC32
Introduction To Programming The PIC32
Ex. TRISX = 0x0000 More understanding of underlying code More difficult to program Microchip Reference Manual Jasio book Programming 32-bit Microcontrollers in C
Ex. ReadADC10(bufIndex) SFR (*(&ADC1BUF0+((bufIndex) * 4))) Special Function Registers are used underneath the function (can be seen in the header and source files) PIC32 Peripheral Libraries for MPLAB C32 Compiler
TRISx initializes pins as input or output PORTx digital input LATx digital output ODCx open drain (similar to transistor) CNCON, CNEN, CNPUE change notification
Port bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 A X X X X B X X C D X X X X X E X X Out Out Input Input Input Input F X X X G X X X X X X X X PIC32 PIC32 but not available for programming Not on PIC32
TRISx,
PORTx, and LATx operate on a 16 bit number for port x Each bit corresponds to a given pin Note: not always 16 pins available for each port Note: port B defaults to analog input
TRISx bit = 0 sets up digital output TRISx bit = 1 sets up digital input TRISx &= 0xFFF0
TRISx &= 1111 1111 1111 0000 Makes bits 0, 1, 2, 3 digital outputs
TRISx |= 0x00F0
TRISx |= 0000 0000 1111 0000 Makes bits 4, 5, 6, 7 digital inputs
TRISEbits.TRISE0 = 0
Makes E0 digital output
Functions
PORTSetPinsDigitalOut(IOPORT_C, IOPORT_PIN_6 | IOPORT_PIN_7);
Read High or Low for pin / port (READ) #define PIN_A9 PORTAbits.RA9
value = PIN_A9
Functions:
unsigned int mPORTxRead(void) unsigned int mPORTxReadBit(unsigned int _bits)
Functions:
void mPORTxWrite(unsigned int _value)
AD1CON1 = 1010 0000 1110 0100 OpenADC10(config1, config2, config3, configport, configscan)
(mPORTBSetPinsAnalogIn(configport), AD1CSSL = ~(configscan), AD1CON3 = (config3), AD1CON2 = (config2), AD1CON1 = (config1) )
C:\Program Files \Microchip\MPLAB C32 \ pic32mx\include\proc\pic32mx460f512l.h _AD1CON1_ADON_POSITION = 15 _AD1CON1_ADSIDL_POSITION = 13 _AD1CON1_FORM_POSITION = 8 _AD1CON1_SSRC_POSITION = 5 _AD1CON1_ASAM_POSITION = 2
1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1110 0000 0000 0000 0000 0100 -------------------------1000 0000 1110 0100
PCB Digital Input / Output Analog Input LCD Display Computer Communication RS232