2.2.1.2 Components of a Microcontroller

The microcontroller (MCU) has on-chip program memory (Figure 2-2 or Figure 2-3) for the firmware, or coded instructions, to run a program (Figure 2-4 or Figure 2-5). A Program Counter (PC) is used to address program memory, including Reset and interrupt addresses. A hardware stack is used with call and return instructions in code, so it works with, but is not part of, program memory. Device data sheets describe the details of program memory operation, vectors and the stack.

Figure 2-2. PIC® MCU Data Sheet - Program Memory and Stack
Figure 2-3. AVR® MCU Data Sheet - Program Memory
Figure 2-4. PIC® MCU Data Sheet – Instruction Set (Excerpt)
Figure 2-5. AVR® MCU Instruction Set (Excerpt)

The microcontroller also has data, or File Register, memory. This memory consists of Special Function Registers (SFRs) and General Purpose Registers (GPRs). SFRs are registers used by the CPU and peripheral functions for controlling the desired operation of the device. GPRs are for storage of variables that the program will need for computation or temporary storage. Some microcontrollers have additional data EEPROM memory. As with program memory, device data sheets describe the details of data memory use and operation.

Table 2-2. PIC® MCU Data Sheet – File Registers Example
Bank 0File AddressBank 1File AddressBank 2File AddressBank 3File Address
Indirect addr. (1)00hIndirect addr. (1)80hIndirect addr. (1)100hIndirect addr. (1)180h
TMR001hOPTION_REG81hTMR0101hOPTION_REG181h
PCL02hPCL82hPCL102hPCL182h
STATUS03hSTATUS83hSTATUS103hSTATUS183h
FSR04hFSR84hFSR104hFSR184h
PORTA05hTRISA85hPORTA105hTRISA185h
PORTB06hTRISB86hPORTB106hTRISB186h
PORTC07hTRISC87hPORTC107hTRISC187h
08h88h108h188h
09h89h109h189h
PCLATH0AhPCLATH8AhPCLATH10AhPCLATH18Ah
INTCON0BhINTCON8BhINTCON10BhINTCON18Bh
PIR10ChPIE18ChEEDAT10ChEECON118Ch
PIR20DhPIE28DhEEADR10DhEECON2(1)18Dh
TMR1L0EhPCON8EhEEDATH10Eh18Eh
TMR1H0FhOSCCON8FhEEADRH10Fh18Fh
T1CON10hOSCTUNE90h110h190h
TMR211h91h111h191h
T2CON12hPR292h112h192h
SSPBUF13hSSPADD(2)93h113h193h
SSPCON14hSSPSTAT94h114h194h
CCPR1L15hWPUA95hWPUB115h195h
CCPR1H16hIOCA96hIOCB116h196h
CCP1CON17hWDTCON97h117h197h
RCSTA18hTXSTA98hVRCON118h198h
TXREG19hSPBRG99hCM1CON0119h199h
RCREG1AhSPBRGH9AhCM2CON011Ah19Ah
1BhBAUDCTL9BhCM2CON111Bh19Bh
PWM1CON1Ch9Ch11Ch19Ch
ECCPAS1Dh9Dh11DhPSTRCON19Dh
ADRESH1EhADRESL9EhANSEL11EhSRCON19Eh
ADCON01FhADCON19FhANSELH11Fh19Fh
General 
Purpose 
Register

96 Bytes

20hGeneral 
Purpose 
Register

80 Bytes

A0hGeneral 
Purpose 
Register

80 Bytes

120h1A0h
EFh16Fh
accesses

70h-7Fh

F0haccesses

70h-7Fh

170haccesses

70h-7Fh

1F0h
7FhFFh17Fh1FFh

Empty table cells: Unimplemented data memory locations, read as ‘0’.
Note 1: Not a physical register.
Note 2: Address 93h also accesses the SSP Mask (SSPMSK) register under certain conditions.

Figure 2-6. AVR® MCU Data Sheet – SRAM Data Memory and Stack

In addition to memory, the microcontroller has a number of peripheral device circuits on the same chip. Some peripheral devices are called input/output (I/O) ports. I/O ports are pins on the microcontroller that can be used as outputs and driven high or low to send signals, blink lights, drive speakers – just about anything that can be sent through a wire. Often these pins are bidirectional and can also be configured as inputs, allowing the program to respond to an external switch, a sensor, or to communicate with some external device.

Figure 2-7. PIC® MCU Data Sheet – Block Diagram (Excerpt)
Figure 2-8. AVR® MCU Data Sheet – Block Diagram (Excerpt)

To design such a system, choose which peripherals are necessary for the application.

The following is a list of common peripherals:

  • Analog-to-Digital Converters (ADCs) allow microcontrollers to connect to sensors and receive changing voltage levels.
  • Serial communication peripherals that allow streaming communications over a few wires to another microcontroller, to a local network, or to the Internet.
  • Peripherals on the PIC MCU called “timers” accurately measure signal events and generate and capture communications signals, produce precise waveforms, even automatically reset the microcontroller if it gets “hung” or lost due to a power glitch or hardware malfunction.
  • Other peripherals detect when the external power is dipping to dangerous levels, so that the microcontroller can store critical information and safely shut down before power is completely lost.

The peripherals, and the amount of memory an application needs to run a program, largely determine which PIC MCU to use. Other factors could include the power consumed by the microcontroller and its “form factor,” i.e., the size and characteristics of the physical package that must reside on the target design.

Figure 2-9. PIC® MCU Device Package Example
Figure 2-10. Example AVR® MCU Device Package

A microcontroller becomes active when power is applied and an oscillator begins generating a clocking signal. Depending on the microcontroller, there may be several internal and external oscillator operational modes.

Figure 2-11. PIC® MCU Data Sheet – Timing Diagram (Excerpt)
Figure 2-12. AVR® MCU Data Sheet – Timing (Excerpt)