Short answer
Yes – on a PIC16‑F family device the hardware itself has no notion of “little‑endian” or “big‑endian” because every addressable object is a single 8‑bit byte.
When you need a value that occupies more than one byte (e.g., a uint16_t in C, an ADC result register, a 16‑bit timer, etc.) the compiler (or your own code) decides which byte lives at the lower address and which lives at the higher address.
In practice the Microchip XC8 compiler follows the little‑endian convention (low‑order byte at the lower address) for all multi‑byte objects, but you can override it or handle the ordering manually whenever you talk to external devices that expect a different order.
1. What “endianness” really means for a PIC16
| Feature | What the PIC16 hardware does |
|---|
| Data bus width | 8 bits (one byte per access) |
| Addressable unit | Byte‑addressable RAM, SFRs, and EEPROM |
| Instruction width | 14‑bit or 16‑bit (Harvard architecture) |
| Automatic byte‑reordering | None – the CPU never fetches a 16‑bit word in one go, so there is nothing to “swap”. |
| Registers | All SFRs (Special‑Function Registers) are 8 bits wide. Some peripherals expose a pair of registers that together form a 16‑bit value (e.g., ADRESH:ADRESL). The order of those two bytes is defined by the datasheet, not by a hidden endianness flag. |
Because the hardware only ever moves one byte at a time, the concept of “endianness” only appears when software needs to treat several consecutive bytes as a larger integer.
2. How the XC8 compiler treats multi‑byte objects
| C type | How XC8 stores it in RAM (address ↑ = higher) |
|---|
uint16_t x = 0x1234; | x occupies two consecutive bytes: addr → low byte 0x34 addr+1 → high byte 0x12 |
int32_t y = 0x11223344; | 4 bytes, low‑order first: addr → 0x44 addr+1 → 0x33 addr+2 → 0x22 addr+3 → 0x11 |
struct { uint8_t a; uint16_t b; } s; | a at addr b low byte at addr+1, high byte at addr+2 |
The compiler always emits code that reads/writes the low‑order byte first (little‑endian). This is hard‑coded in the code‑generator; there is no compiler switch to make the PIC16 “big‑endian”.
Why the compiler can pick a convention
- The PIC16 has no native 16‑bit load/store instructions, so the compiler must generate two separate 8‑bit accesses anyway.
- By fixing a convention (low‑byte first) the compiler can reuse the same code pattern for every
uint16_t operation, making the generated code predictable and small.
3. When you have to think about byte order yourself
| Situation | What you must do |
|---|
Reading a 16‑bit peripheral register (e.g., ADRESH:ADRESL) | The datasheet tells you which register is the high byte and which is the low byte. Typical code: ```c uint16_t adc = ((uint16_t)ADRESH << 8) |
Writing a 16‑bit value to a peripheral (e.g., TMR1H:TMR1L) | Split the value yourself: c TMR1H = value >> 8; <br> TMR1L = value & 0xFF; |
| Communicating over UART, SPI, I²C, CAN, etc. | The external protocol may define a specific byte order (often big‑endian for network protocols). You must reorder the bytes before sending or after receiving. |
| Storing data in EEPROM or external memory | Decide on a layout (e.g., little‑endian) and stick to it consistently. The compiler’s default layout is a good default for internal RAM, but external storage is up to you. |
| Using unions or bit‑field structs | Be aware that the order of fields inside a union is defined by the compiler’s layout rules (again, little‑endian). If you need a portable binary format, avoid relying on the raw memory representation of a union. |
Example: UART transmission of a 16‑bit value in big‑endian order
void uart_send_uint16_be(uint16_t v)
{
uint8_t hi = v >> 8; // high byte first
uint8_t lo = v & 0xFF; // low byte second
UART_Write(hi);
UART_Write(lo);
}
If you used the compiler’s natural order (low‑byte first) you would have to swap the two writes.
4. “All registers are 8‑bit – does that mean endianness never matters?”
For on‑chip operations, yes – the CPU never sees a multi‑byte register as a single entity, so the hardware does not care about byte order.
For software‑level handling of multi‑byte data (variables, peripheral pairs, communication buffers, EEPROM, etc.) you must be explicit about the order you place the bytes. The compiler’s default (little‑endian) is a convention, not a hardware rule.
5. Quick checklist for PIC16 projects
| ✅ | Check |
|---|
| Peripheral registers | Follow the order given in the datasheet (HIGH:LOW or LOW:HIGH). |
| C variables larger than 8 bits | Assume the compiler stores them little‑endian; verify with a debugger if you’re unsure. |
| External protocols | Look up the protocol’s byte order and manually swap if it differs from the compiler’s layout. |
| EEPROM / external flash | Define a file format (e.g., “store all 16‑bit values low‑byte first”) and use the same routine for both read and write. |
| Testing | Dump a few known values to a terminal or a logic analyser; confirm the byte sequence matches expectations. |
6. TL;DR (one‑sentence summary)
On a PIC16F883 every addressable object is a single byte, so the hardware has no built‑in endianness; the XC8 compiler (and any code you write) decides the order of bytes for multi‑byte variables, and by default it uses little‑endian (low byte at the lower address). You only need to worry about byte order when you combine several bytes yourself (peripheral registers, communication protocols, external storage).