Microchip 8-bit MCU Families
The PIC16F1xxx Enhanced Mid-Range 8-bit PIC®MCU Family spans a wide array of memory sizes and I/O pins.
This page presents the key architectural features of the PIC16F1xxx family of MCUs. Links are provided in this page to the technical details needed to implement applications on the enhanced mid-range PIC MCU family.
Enhanced mid-range PIC® MCUs use a dual-bus Harvard Architecture.
Program instructions are fed into the ALU from FLASH program memory via the 14-bit instruction bus. On every instruction clock cycle one 14-bit program word is read into the ALU
An 8-bit data bus connects the ALU to the Data Memory space. During each instruction the ALU can read data from data memory location, modify the data, then write the data back to memory.
The enhanced mid-range PIC's dual-bus architecture provides for a two stage instruction pipeline. One each clock cycle two instruction phases execute:
- The next instruction is "fetched" from Program Memory
- The current instruction is "executed" and reads/modifies/writes data memory (if needed)
Memory Mapped Peripherals
A closer look at the Data Memory section of the enhanced mid-range PIC®MCU shows the registers controlling the peripherals and I/O ports are accessed by reading or writing to specific data memory addresses. This mapping of peripherals to memory address greatly simplifies learning how to program the enhanced mid-range PIC.
The Data Memory Page of the enhanced mid-range tutorial offers a complete description along with program examples accessing the memory mapped peripherals
Orthogonal Instruction Set
Enhanced Mid-Range PIC® MCUs each have 49 instructions. Instructions directly accessing Data Memory addresses execute in one instruction cycle. Instructions which cause a change in the program counter BRA, GOTO, RETURN, CALL, ..etc) take two instruction cycles to execute.
By mapping the I/O and peripheral registers to memory addresses PIC MCUs do not need special instructions for I/O operations or to set peripheral registers. Writing to an I/O port or configuring a peripheral is a simple write to a memory location. Reading the value of an input pin, ADC result register, or timer is a simple read of a memory location. By using a small number of orthogonal instructions Enhanced Mid-Range PIC MCUs are easy to program, use less silicon to build, and consume less power.
Examples of Instruction Implementation
For a detailed list of the instruction set and a full discussion of instruction timing please consult the Instruction Set page of the Enhanced Mid-Range tutorial.
Flexible Clocking Options (Up to 32MHz)
Selected by the PIC® MCU's configuration bits the system clock has the following properties:
- Optional source (internal oscillator or external circuitry)
- Flexible speed options up to 32MHZ
- Two speed start-up - allows system to run initialization software while external oscillator is stabilizing
- Clock Switching - The system clock source can be switched between external and internal clock sources via software.
- Fail-Safe Clock Monitor - switches to internal oscillator in the event of an external clock failure
For a detailed description of the oscillator configuration options please refer to the 8-bit Oscillator page in the Enhanced Mid-Range Tutorial.
Almost every pin on the Enhance Mid-Range PIC MCU can be used as a digital input or output pin. Digital Pins share these attributes:
- Monitor Digital Inputs
- Control Digital Devices
- Internal Weak Pull-ups
- Multiplexed with Peripherals
- High Drive capability (up to 25 mA sink/source on many I/O pins)
- Direct single cycle bit manipulation
- 4kV ESD protection diodes
- Digital Pins revert to input (Hi-Z)
- Analog Capable pins revert to analog
Typical Digital Pin Structure
Five registers control the operation of the a digital pin. These 8-bit registers control 8 pins of a PORT. Using the registers TRISX, PORTx, LATx, WPUx, and ANSEL the program can:
- Configure the a pin as an input or output TRISx
- Read an input pin (or all 8 PORT pins) PORTx
- Output a 1 or 0 to a pin LATx
- Enable or disable the internal Pull Up Resistor WPUx
- Determine if analog capable pins operate in analog or digital Mode ANSEL
For a complete discussion of the enhanced mid-range PIC digital I/O including details on programming digital input and output operations refer to the Digital IO section of this enhanced mid-range tutorial
In addition to being configured as digital I/Os, pins on enhanced mid-range PIC MCUs can have several possible functions. The pin diagram on the datasheet shows the options for each pin. At start-up the program has the option of configuring the pins.
For comprehensive discussion of the enhanced mid-range PIC digital I/O including details on configuring the pins refer to the Peripheral Section of the enhanced mid-range tutorial
In addition to digital I/O enhanced mid-range PIC MCU family members have an assortment of advanced peripherals. These peripherals include peripherals for data conversion, communication, and signal conditioning.
For a complete list of peripherals available please reference the Peripheral Section of the tutorial
Enhanced mid-range PIC MCUs utilize a single vector pre-emptive interrupt structure.
Each peripheral on the PIC is capable of generating an interrupt request. When an interrupt request occurs AND interrupts for the requesting device are enabled an interrupt will occur.
The enhanced mid-rage PIC uses a 16 level hardware stack to store the current content of the PC when an interrupt occurs. The program context is saved in shadow registers and control is passed to program memory address 0x04.
Interrupt Service Routine (ISR)
The user is responsible for writing the code to service the interrupt and placing the code at address 0x04. This Interrupt Service Routine (ISR) determines the source of the interrupt, then performs the necessary task to service the interrupting peripheral. An ISR's final instruction is the Return From Interrupt (RETFIE) instruction.
Automatic Context Saving
The following registers are saved to a single-level shadow register set in the event of an interrupt
- W register
When the ISR executes the RETFIE instruction, these registers are restored to the pre-interrupt value
Single Level Interrupt Pre-emption
When an interrupt occurs the Global Interrupt Enable bit (GIE) in the status register is disabled. This will prevent the an interrupt from being pre-empted by another interrupt.
Upon executing a RETFIE the state of the GIE control bit is restored to its pre-interrupt value.
For a complete description of the interrupt process and programming examples please refer to the Interrupt Section of the Enhanced Mid-range tutorial.
What happens at System Start-up (RESET)
There are several sources of a RESET on the enhanced mid-range PIC MCU. The RESET sources common to almost all applications are the Power On Reset (POR) and Brown Out Reset (BOR) due to a sagging power supply voltage (i.e. brown-out). There are several other methods for resetting the MCU including Watchdog timeout and directly accessing the MCLR pin.
Program Counter is set to 0x00.
After a RESET the instruction located at address 0 is the first instruction executed. The application developer is responsible for placing code into this address to 'boot up' the PIC. Microchip's MPLAB® XC8 compiler will insert the appropriate instructions to start-up the PIC and transfer control to main. Assembly level programmers will have to write the code to initialize the PIC and jump past the Interrupt Vector located at address 0x04.
All Special Function Registers are set to a Default Value
The datasheet for each enhanced mid-range PIC MCU shows the values which the registers will contain at RESET.
The Programming Examples section of the enhanced mid-range tutorial provides programming examples of how to 'boot-up' the MCU.