C32 Notes

Important Reminder when debugging EEPROM write / reads endianess:

http://www.d.umn.edu/~cprince/courses/cs2521fall09/lectures2/Alignment.pdf:

 

Our)PIC32)is)li?le@endian)
– For)mulBple)byte)values)(e.g.,)words),)the)smallest)RAM)address)
contains)the)lower)byte)order)logical)value

Our PIC32 / PIC32MX is little endian:

– For multple byte values e.g. words, the smallest RAM address contains the lower byte order logical value

We ask: Is it consistent across all data types.. ie DWORD vs WORD? Or is it only QWord thats not working as expected?

 


I/O Registers
Input and output on the PIC18XXXX pins is accomplished by reading and writing the registers associated with the port pins on the device. Check the data sheet for available ports on the device. There are three special function registers associated with each port, one called a TRIS register defines the direction of the port pin: input or output. A second register called the PORT register is used to read and write values to the port pin, and a third, named LAT, is a latch, which allows reading and writing the values on the port without actually reading the current state of the pins on the port. This is important in the PIC18XXXX architecture because of read/modify/write considerations. The contents of I/O port registers should not be treated like variable storage --they operate quite differently. See the data sheets for more information.
Some pins are multiplexed and may need to be configured by other special function registers before they can be used as digital I/O. Specifically, PORTA on many PIC18XXXX devices also can be used as analog inputs to the A/D converter.
To configure and use PORTB as 4 input pins and 4 output pins, the following code could be written in MPLAB C compiler:

 

TRISB = 0xF0
PORTB = 0x0C /* set pins 0 and 1 low, pins 2 and 3 high */

 


 

TRISDbits.TRISD6 = 0;
PORTDbits.RD6 = 0;

_RD6 = 1;

 

or

 

input_bit = _RD6

 

 

 

A sequence of binary digits preceded by 0b or 0B (the numeral ‘0’ followed by the letter
‘b’ or ‘B’) is taken to be a binary integer. The binary digits consist of the numerals ‘0’
and ‘1’. For example, the (decimal) number 255 can be written as 0b11111111. Like
other integer constants, a binary constant may be suffixed by the letter ‘u’ or ‘U’, to
specify that it is unsigned. A binary constant may also be suffixed by the letter ‘l’ or ‘L’,
to specify that it is long. Similarly, the suffix ‘ll’ or ‘LL’ denotes a long long binary
constant.