Unit1 Notes
Unit1 Notes
A microcontroller is a compact integrated circuit that contains a processor core, memory, and
programmable input/output peripherals. It is designed to execute a specific set of tasks and is
commonly used in embedded systems. Microcontrollers are widely employed in various
applications, ranging from simple household appliances to complex industrial systems. Here's an
introduction to the key components and concepts associated with microcontrollers:
1. Core Components:
● Processor (CPU): The central processing unit performs the actual computation and
controls the execution of instructions.
● Memory:
● RAM (Random Access Memory): Provides temporary data storage for the
microcontroller during program execution.
● Flash/ROM (Read-Only Memory): Stores the firmware or program that is
permanently embedded in the microcontroller.
● Peripherals:
● Input/Output (I/O) ports: Connect the microcontroller to external devices.
● Timers/Counters: Assist in measuring time intervals or counting events.
● Serial Communication Interfaces (UART, SPI, I2C): Facilitate communication
with other devices.
● Analog-to-Digital Converters (ADC): Convert analog signals (e.g., sensor
readings) into digital values.
2. Program Development:
● Microcontrollers are programmed using low-level languages like Assembly or
higher-level languages like C. Integrated Development Environments (IDEs) and
compilers are often used for coding and program compilation.
3. Embedded Systems:
● Microcontrollers are the heart of embedded systems, which are dedicated computing
devices designed for specific tasks. Examples include microwave ovens, washing
machines, automotive control systems, and more.
4. Real-time Operation:
● Many microcontrollers are designed for real-time operation, meaning they can respond to
external events within specific time constraints. This makes them suitable for applications
requiring precise timing, such as controlling motors or reading sensors.
5. Power Efficiency:
● Microcontrollers are optimized for low power consumption, making them suitable for
battery-powered devices and other energy-efficient applications.
6. Variety of Architectures:
● Microcontrollers come in various architectures, including 8-bit, 16-bit, and 32-bit. The
choice depends on the complexity of the application and performance requirements.
7. Development Boards:
● To facilitate experimentation and prototyping, development boards with built-in
microcontrollers are available. Popular examples include Arduino and Raspberry Pi.
8. Programming and Debugging:
● Microcontrollers can be programmed and debugged using various methods, including
in-circuit programming (ICP), JTAG (Joint Test Action Group), or through a bootloader.
The history of microcontrollers dates back several decades and is closely tied to the development
of integrated circuits and the evolution of computing technology. Here is a brief overview of the
key milestones in the history of microcontrollers:
Microprocessors and microcontrollers are both integral components of digital systems, but they
serve different purposes and have distinct characteristics. Here are the key differences between
microprocessors and microcontrollers:
1. Function:
● Microprocessor: A microprocessor is primarily designed for general-purpose computing.
It is the central processing unit (CPU) of a computer system and executes instructions
fetched from memory. Microprocessors are commonly used in personal computers and
servers.
● Microcontroller: A microcontroller is designed for specific embedded applications. It
integrates a processor core, memory, and input/output peripherals on a single chip,
making it suitable for dedicated control tasks in embedded systems.
2. Integration:
● Microprocessor: Typically, a microprocessor requires external components, such as
memory (RAM and ROM/Flash), input/output interfaces, and other peripherals, to form a
complete computer system.
● Microcontroller: It is a highly integrated device, containing not only the processor core
but also on-chip memory, I/O ports, timers, and other peripherals. Microcontrollers are
designed to be self-contained, simplifying their use in embedded applications.
3. Applications:
● Microprocessor: Found in general-purpose computing devices like personal computers,
laptops, servers, and workstations where versatility and computational power are crucial.
● Microcontroller: Used in embedded systems, such as automotive control units, home
appliances, industrial automation, medical devices, and other applications that require
real-time control and specific functionality.
4. Usage in Systems:
● Microprocessor: Requires external support for memory, peripherals, and other
components. It is part of a larger system that includes separate components for different
functions.
● Microcontroller: A standalone device designed to perform a specific task. It is often the
sole processing unit in an embedded system.
5. Complexity and Cost:
● Microprocessor: Generally more powerful and complex, leading to higher costs. Suited
for applications that demand high processing capabilities.
● Microcontroller: More cost-effective due to integration and is tailored for applications
with specific functionality, often with lower processing requirements.
6. Power Consumption:
● Microprocessor: Tends to consume more power, as it is optimized for high performance
and versatility.
● Microcontroller: Typically designed for lower power consumption, making it suitable
for battery-powered or energy-efficient applications.
7. Development:
● Microprocessor: Development involves connecting external components and
peripherals, requiring a more extensive setup.
● Microcontroller: Development is often more straightforward, as most components are
integrated on-chip. Development boards are widely available for experimentation and
prototyping.
In summary, while both microprocessors and microcontrollers are crucial components in the
digital world, they are designed for different purposes. Microprocessors are versatile and
powerful, serving general-purpose computing needs, while microcontrollers are specialized for
embedded applications, providing a compact and integrated solution for control tasks.
Selecting the right microcontroller for a project is crucial, as it significantly influences the
performance, power consumption, and overall success of the system. Here are some key criteria
to consider when choosing a microcontroller:
1. Application Requirements:
● Functionality: Clearly define the tasks and functions the microcontroller needs to
perform in the target application.
● Processing Power: Assess the computational requirements to choose a microcontroller
with an appropriate processing speed and capabilities.
2. Memory Requirements:
● Program Memory (Flash/ROM): Consider the size of the program code and choose a
microcontroller with sufficient program memory.
● Data Memory (RAM): Evaluate the data storage needs and select a microcontroller with
an adequate amount of RAM.
3. Peripheral Integration:
● I/O Ports: Determine the number and types of input/output pins required for interfacing
with sensors, actuators, and other devices.
● Communication Interfaces: Consider the need for serial communication (UART, SPI,
I2C), USB, Ethernet, or other interfaces.
● Analog-to-Digital Converters (ADC): If the application involves analog signals, choose
a microcontroller with the required number and resolution of ADC channels.
4. Power Consumption:
● Operating Voltage Range: Ensure that the microcontroller operates within the power
supply constraints of the application.
● Power Modes: Evaluate the availability of low-power modes to optimize energy
consumption, especially for battery-powered devices.
5. Cost:
● Component Cost: Consider the overall cost of the microcontroller, including any
additional components required for operation.
● Development Tools: Assess the availability and cost of development tools, compilers,
and debugging equipment.
6. Availability and Longevity:
● Vendor Support: Choose a microcontroller from a reputable manufacturer with good
technical support and documentation.
● Longevity: Ensure that the chosen microcontroller will be available for the duration of
the product life cycle.
7. Development Environment:
● Development Tools: Evaluate the availability and user-friendliness of development tools,
such as Integrated Development Environments (IDEs), compilers, and debuggers.
● Community Support: A strong community and available online resources can be
beneficial for troubleshooting and sharing knowledge.
8. Size and Package:
● Physical Size: Consider the size constraints of the application, especially in compact or
space-sensitive designs.
● Package Type: Choose a package type (e.g., DIP, QFP, BGA) that suits the
manufacturing and assembly requirements.
9. Temperature and Environmental Considerations:
● Operating Temperature Range: Ensure that the microcontroller can operate within the
specified temperature range for the intended environment.
● Environmental Conditions: Consider factors such as humidity, vibration, and other
environmental conditions.
10. Security Features:
● Assess the security features of the microcontroller, especially if the application involves
sensitive data or communication.
11. Scalability and Future Expansion:
● Consider the scalability of the microcontroller family to accommodate future
enhancements or changes in the project requirements.
By carefully evaluating these criteria, you can choose a microcontroller that aligns with the
specific needs and constraints of your project, leading to a successful and reliable embedded
system.
PIC18FXXX:
1. Processor Core:
● 8-bit Harvard architecture.
2. Clock Speed:
● Available with various clock speeds, supporting internal and external clock sources.
3. Program Memory (Flash):
● On-chip Flash memory for storing program code. Different models have varying amounts
of program memory.
4. Data Memory (RAM):
● On-chip RAM for data storage and manipulation.
5. EEPROM:
● Some models include Electrically Erasable Programmable Read-Only Memory
(EEPROM) for non-volatile data storage.
6. I/O Ports:
● Multiple General-Purpose I/O (GPIO) pins for interfacing with external devices and
sensors.
7. Timers:
● Integrated timers with Capture/Compare/PWM (CCP) modules for various timing and
control applications.
8. Communication Interfaces:
● USART (Universal Synchronous/Asynchronous Receiver/Transmitter) modules for serial
communication.
● SPI (Serial Peripheral Interface) and I2C (Inter-Integrated Circuit) modules for
synchronous and asynchronous serial communication.
9. Analog Features:
● Analog-to-Digital Converters (ADC) for converting analog signals into digital values.
● Comparator modules for analog signal comparison.
10. Interrupts:
● Multiple interrupt sources and an interrupt controller for efficient handling of events.
11. Watchdog Timer:
● Watchdog timer for system reliability by resetting the microcontroller in case of a system
lockup.
12. Operating Voltage:
● Supports a range of operating voltages, allowing for flexibility in power supply
requirements.
13. Low Power Modes:
● Various low-power modes to conserve energy, suitable for battery-powered applications.
14. Security Features:
● Some models may include code protection and other security features.
15. Development Tools:
● Support from Microchip's MPLAB development environment, providing tools for code
development, debugging, and simulation.
16. Package Options:
● Available in various package types, such as DIP (Dual In-line Package), QFP (Quad Flat
Package), and others.
17. Temperature Range:
● Designed to operate within specified temperature ranges.
It's crucial to refer to the datasheet and reference manual of the specific PIC18F model you are
working with to get detailed information about its features, pinout, electrical characteristics, and
programming considerations. The exact features and specifications can vary between different
models within the PIC18F series.
PIC18FXXX Features:
1. Architecture:
● The PIC18F series uses an 8-bit Harvard architecture.
2. Clock Speed:
● Typically available with various clock speeds, with options for internal and external clock
sources.
3. Flash Memory:
● Program memory (Flash) for storing user code. The size of the Flash memory varies
among different models within the series.
4. RAM:
● On-chip RAM for data storage and manipulation.
5. EEPROM:
● Some models have integrated Electrically Erasable Programmable Read-Only Memory
(EEPROM) for non-volatile data storage.
6. I/O Ports:
● Multiple General-Purpose I/O (GPIO) pins for interfacing with external devices and
sensors.
7. Timers:
● Built-in timers, including timers with Capture/Compare/PWM (CCP) modules for various
timing and control applications.
8. Communication Interfaces:
● USART (Universal Synchronous/Asynchronous Receiver/Transmitter) modules for serial
communication.
● SPI (Serial Peripheral Interface) and I2C (Inter-Integrated Circuit) modules for
synchronous and asynchronous serial communication.
9. Analog Features:
● Analog-to-Digital Converters (ADC) for converting analog signals into digital values.
● Comparator modules for analog signal comparison.
10. Interrupts:
● Multiple interrupt sources and an interrupt controller for efficient handling of events.
11. Watchdog Timer:
● Watchdog timer for system reliability by resetting the microcontroller in case of a system
lockup.
12. Operating Voltage:
● Supports a range of operating voltages, often allowing for low-power operation.
13. Low Power Modes:
● Various low-power modes to conserve energy in battery-powered applications.
14. Security Features:
● Some models may include security features for code protection and prevention of
unauthorized access.
15. Development Tools:
● Support from Microchip's MPLAB development environment, providing tools for code
development, debugging, and simulation.
16. Package Options:
● Available in various package types, such as DIP (Dual In-line Package), QFP (Quad Flat
Package), and others.
17. Temperature Range:
● Designed to operate within specified temperature ranges, making them suitable for a
variety of environments.
It's important to note that specific models within the PIC18F series may have additional features
or variations. Therefore, when selecting a PIC18F microcontroller for a particular application, it's
recommended to refer to the datasheet of the specific model to ensure accurate information about
its features and capabilities.
PIC18FXXX architecture:
PIC stands for Peripheral Interface Controller. PIC microcontroller was developed by microchip
technology in 1993. It was developed for supporting PDP computers to control its peripheral
devices and that’s why it was named Peripheral Interface Controller. PIC microcontrollers are of
low cost, very fast and easy for the programming and execution of program. Their interfacing
with other peripherals is also very easy. PIC Microcontrollers from Microchip Company are
divided into 4 large families. In this PIC MICROCONTROLLER ARCHITECTURE article, I
will explain step by step about PIC MICROCONTROLLER ARCHITECTURE and components
used in pic microocntrollers. I recommend you to check a list of Pic microcontroller
project here.
● First family: PIC10 (10FXXX) called Low End
● Second family: PIC12 (PIC12FXXX) called Mid-Range
● Third family: PIC16 (16FXXX)
● Fourth family: PIC 17/18 (18FXXX)
Each family has a variety of components along with built in special features. It offers a lot of
memory sizes and pin packages and different clock ratings.
ARCHITECTURE:
2. MEMORY ORGANIZATION:
PIC microcontroller memory module consists of mainly 3 types of memories:
● PROGRAM MEMORY:
It contains the written program after we burned it in microcontroller. Program Counter executes
commands stored in the program memory, one after the other. Pic microcontroller can have 8K
words x 14 bits of Flash program memory that can be electrically erased and
reprogrammed. Whenever we burn program into the micro, we erase an old program and write a
new one.
● DATA MEMORY:
It is a RAM type which is used to store the data temporarily in its registers. The RAM memory is
classified into banks. Each bank extends up to 7Fh (128 bytes). Number of banks may vary
depending on the microcontroller. PIC16F84 has only two banks. Banks contain Special
Function Registers (SFR) and General Purpose Registers (GPR). The lower locations of each
bank are reserved for the Special Function Registers and upper locations are for General Purpose
Registers.
● DATA EEPROM:
This memory allows storing the variables as a result of burning the written program. It is
readable and writable during normal operation (over the full VDD range). This memory is not
directly mapped in the register file. It is indirectly addressed through the SFRs. There are six
SFRs which are used to read and write to this memory (EECON1, EECON2, EEDATA,
EEDATH, EEADR, EEADRH).
3. SERIAL COMMUNICATION:
The transfer of one bit of data at time consecutively over a communication channel is called
Serial Communication. There are three protocols of serial communication:
● USART: It stands for Universal synchronous and Asynchronous Receiver and
Transmitter which provides a serial communication in two devices. In this protocol data
is transmitted and received bit by bit through a single wire according to the clock pulses.
To send and receive data serially the PIC microcontroller has two pins TXD and RXD.
● SPI Protocol: SPI stands for Serial Peripheral Interface. It is used to send data between
PIC microcontrollers and other peripherals like sensors, shift registers and SD cards.
Three wire SPI communications is supported in PIC microcontroller between two devices
on a common clock source. SPI protocol has greater data handling capability than that of
the USART.I2C Protocol: I2C stands for Inter Integrated Circuit, and this protocol is
used to connect low speed devices like microcontrollers, EEPROMS and A/D converters.
PIC microcontroller support two wire Interface or I2C communication between two
devices which can work as both Master and Slave device.
Serial Communication
4. INTERRUPTS:
There are 20 internal interrupts and three external interrupt sources in PIC microcontrollers
which are related with different peripherals like ADC, USART, Timers, and CCP etc.
5. I/O PORTS:
Let us take PIC16 series, it consists of five ports, such as Port A, Port B, Port C, Port D and Port
E.
● Port A:This port is 7-bit wide and can be used for both input and output. The status of
TRISA register decided whether it is used as input or output port.
● Port B:It is an 8-bit port. This port also can be used as input and output. Moreover in
input mode four of its bits are variable according to the interrupt signals.
● Port C:It is also an 8-bit port and can be used as both input and output port which is
determined by the status of the TRISC register.
● Port D:This 8-bit port, unlike Port A, B and C is not an input/output port, but is used as
acts as a slave port for the connection to the microprocessor When in I/O mode Port D
all pins should have Schmitt Trigger buffers.
● Port E:It is a 3-bit port which is used as the additional feature of the control signals to
the A/D converter.
6. CCP MODULE:
A CCP module works in the following three modes:
● Capture Mode: In this mode time is captured when a signal is arrived, or we can say
that, when the CCP pin goes high it captures the value of the Timer1.
● Compare Mode: It works same as an analog comparator, which means that when timer
1’s value reaches some reference value it will give an output signal.
● PWM Mode: This mode provides a 10 bit resolution pulse and duty cycle that is
programmable.
7. Timers:
Timers and counters are important as timers can tell the time and count. PIC microcontroller can
have up to four timers (depending upon the family) Timer0, Timer1, Timer2 and Timer3. Timer0
and Timer2 are of 8-bits while the Timer1 and Timer3 are of 16-bits, which can also be used as
a counter. These timers work according to the selected modes.
8. D/A CONVERTER:
There are no analog outputs in PIC Microcontroller. To get analog output we have to use
external Digital-to-Analog Converter (DAC). It can convert 8 bits of digital number from the
eight digital outputs of PIC microcontroller.
A/DCONVERTER:
It converts the analog voltage levels to digital voltage values. In PIC Microcontroller, ADC has
8-channels and has resolution of 10-bit, which means that if we have to convert an analog
voltage between 0V to 5V the converter will divide it to 2^10 levels (1024 levels). The special
function registers ADCON0 and ADCON1 control the operation of ADC. The converter stores
the lower 8 bits in ADRESL register and the upper bits in the ADRESH register. Reference
voltage of 5V is required for the operation of the converter.
The PIC18F series microcontrollers are based on an 8-bit Harvard architecture, and they are part
of Microchip's PIC (Peripheral Interface Controller) family. Here are key aspects of the
architecture commonly found in PIC18F microcontrollers:
1. CPU Core:
● The CPU core is an 8-bit processor.
● It executes a set of RISC (Reduced Instruction Set Computing) instructions, providing a
streamlined and efficient instruction set.
2. Registers:
● The PIC18F architecture includes a set of general-purpose registers (GPRs) used for
arithmetic and logical operations.
● Special Function Registers (SFRs) control various peripheral functions and system
configurations.
3. Program Memory (Flash):
● The program memory (Flash memory) is used to store the user's program code.
● It is non-volatile, allowing the code to be retained even when power is turned off.
● Program memory is organized into program memory pages, and instructions are fetched
from these pages during program execution.
4. Data Memory (RAM):
● The data memory (RAM) is used for temporary data storage during program execution.
● It is volatile and loses its content when power is turned off.
5. Stack:
● The architecture includes a hardware stack used for storing return addresses and other
temporary data during subroutine calls.
6. I/O Ports:
● General-Purpose I/O (GPIO) pins allow interaction with external devices and sensors.
● Ports are often configurable and can be used for digital input/output or other specific
functions.
7. Timers and Counters:
● Integrated timers and counters, including Capture/Compare/PWM (CCP) modules, for
various timing and control applications.
● Timers are crucial for generating accurate time delays and controlling the timing of
events.
8. Communication Peripherals:
● USART (Universal Synchronous/Asynchronous Receiver/Transmitter) modules for serial
communication.
● SPI (Serial Peripheral Interface) and I2C (Inter-Integrated Circuit) modules for
synchronous and asynchronous serial communication.
9. Analog Features:
● Analog-to-Digital Converters (ADC) for converting analog signals into digital values.
● Comparator modules for comparing analog signals.
10. Interrupt System:
● The architecture supports multiple interrupt sources, and an interrupt controller manages
interrupt prioritization.
11. Watchdog Timer:
● A watchdog timer helps ensure system reliability by resetting the microcontroller if the
program execution gets stuck or encounters an error.
12. Clock Management:
● The microcontroller typically supports various clock sources, allowing flexibility in
choosing the system clock.
● Clock dividers and prescalers help manage the clock frequency.
13. Power Management:
● Low-power modes are available to conserve energy, suitable for battery-powered
applications.
14. Security Features:
● Some models in the PIC18F series include features for code protection and securing the
microcontroller against unauthorized access.
It's important to note that while the overall architecture is common among PIC18F
microcontrollers, specific features and peripherals can vary between different models within the
series. Therefore, it's recommended to refer to the datasheet and reference manual of the specific
PIC18F model you are working with for detailed information on its architecture and features.
1. Performance:
● PIC18 microcontrollers vary in terms of clock speed, processing power, and overall
performance. Higher-end models may offer faster clock speeds and more advanced
processing capabilities.
2. Memory:
● Different PIC18 models come with varying amounts of Flash program memory, RAM,
and EEPROM. Choose a model based on the memory requirements of your application.
3. Peripheral Integration:
● PIC18 microcontrollers offer a range of peripherals such as timers, UART, SPI, I2C,
ADC, and PWM modules. Higher-end models may have additional or enhanced
peripherals.
4. Communication Interfaces:
● Consider the communication interfaces required for your application, such as UART, SPI,
and I2C. Ensure that the chosen PIC18 model provides the necessary interfaces.
5. Analog Features:
● Check the availability and specifications of analog features, including the number of
ADC channels, resolution, and other analog peripherals.
6. I/O Ports:
● Evaluate the number of GPIO pins and the flexibility of configuring I/O ports based on
your application's requirements.
7. Clocking Options:
● PIC18 microcontrollers support various clocking options. Consider the available clock
sources, frequency ranges, and clock management features.
8. Power Consumption:
● Assess the power consumption characteristics, especially if the application requires
low-power operation. Some models may have specific low-power modes.
9. Package Options:
● Different PIC18 models come in various package types, such as DIP, QFP, and others.
Choose a package that suits your application's size and assembly requirements.
10. Temperature Range:
● Ensure that the selected PIC18 model operates within the required temperature range for
your application.
11. Security Features:
● Some PIC18 microcontrollers offer security features such as code protection, preventing
unauthorized access to the program memory.
12. Development Tools and Support:
● Consider the availability and quality of development tools, IDEs, compilers, and
community support for the PIC18 model you are evaluating.
13. Cost:
● Factor in the cost of the microcontroller and any additional components required for your
application. Consider the overall system cost.
14. Longevity and Availability:
● Check the long-term availability of the chosen PIC18 model, especially if your product
has a long life cycle.
When comparing PIC18 microcontrollers, it's crucial to identify the specific requirements of
your application and select a model that best meets those requirements. Refer to the datasheets
and reference manuals of individual PIC18 models for detailed and accurate information.
Please note that the pinouts are presented for the 40-pin DIP (Dual In-line Package) versions of
these microcontrollers. If you are using a different package, the pinouts may vary. Always refer
to the specific datasheet of the microcontroller model you are using for the most accurate and
detailed information.
luaCopy code
PIC18F458/452 +-----------------+ VSS | 1 40 | VDD RD0 | 2 39 | RA5 RD1 | 3 38 | RA4 RD2 | 4
37 | RA3 RD3 | 5 36 | RA2 RD4 | 6 35 | RA1 RD5 | 7 34 | RA0 RD6 | 8 33 | OSC1 RD7 | 9 32 |
OSC2 VPP | 10 31 | RC7/T1OSI/CCP10 RD8 | 11 30 | RC6/T1OSO/CCP9 RD9 | 12 29 |
RC5/T1CKI/CCP8 RD10 | 13 28 | RC4/T1G/CCP7 RD11 | 14 27 | RC3/CCP6 RD12 | 15 26 |
RC2/CCP5 RD13 | 16 25 | RC1/CCP4 RD14 | 17 24 | RC0/CCP3 RD15 | 18 23 | RB7 | | VSS | 19
22 | RB6 RB0 | 20 21 | RB5 +-----------------+
In this pinout:
● VSS and VDD are ground and power supply, respectively.
● RBx and RCx refer to port pins on Port B and Port C, respectively.
● RDx refers to port pins on Port D.
● OSC1 and OSC2 are the crystal oscillator connections.
● VPP is the programming voltage for In-Circuit Serial Programming (ICSP).
● T1OSI, T1OSO, T1CKI are Timer1-related pins.
● CCPx refers to Capture/Compare/PWM pins, which are associated with the
Capture/Compare/PWM modules.
Please refer to the specific datasheet for your microcontroller model to ensure accuracy and
completeness.
Registers of PIC18F:
The PIC18F microcontrollers have a variety of special function registers (SFRs) that control and
configure the device's peripherals, features, and overall behavior. These registers are
memory-mapped locations that can be read from or written to in order to interact with the
hardware. Below are some commonly used special function registers found in PIC18F
microcontrollers. Keep in mind that this is not an exhaustive list, and the availability of specific
registers can vary between different models within the PIC18F series.
These are just a few examples, and the specific set of registers may vary between PIC18F
models. Always refer to the datasheet and reference manual for the specific PIC18F device you
are using to get accurate information about the available special function registers and their
functionalities.
1. Memory Architecture:
● The program memory in PIC18 devices is organized into multiple program memory
blocks. Each block typically contains a certain number of words (16-bit instructions).
2. Instruction Set:
● PIC18 microcontrollers use a 16-bit instruction set. Instructions are fetched from program
memory and executed by the CPU.
3. Word Addressability:
● Program memory is word-addressable, meaning each address points to a 16-bit
instruction word. Instructions are fetched in a single operation.
4. Address Range:
● The address range for program memory depends on the specific PIC18 device but is often
16 bits, allowing for a maximum of 64 KB of program memory.
5. Bootloader Area (Optional):
● Some PIC18 devices may have a dedicated bootloader area in program memory, allowing
for firmware updates through In-Circuit Serial Programming (ICSP).
Data Memory (RAM):
1. Memory Organization:
● Data memory (RAM) in PIC18 devices is organized into multiple banks. Each bank has
its set of registers and SFRs (Special Function Registers).
2. Bank Selection:
● The Bank Select Register (BSR) is used to select the active bank. The CPU can access
registers and data in the selected bank.
3. Register Files:
● Each bank contains a set of general-purpose registers (GPRs) and SFRs. The number of
registers and SFRs may vary between banks and PIC18 devices.
4. Address Range:
● The address range for data memory is often 12 bits, allowing for a maximum of 4 KB of
RAM. The actual size of RAM may vary between PIC18 models.
5. Accessing SFRs:
● Special Function Registers (SFRs), controlling various peripherals and features, are
located in specific addresses within data memory. Accessing these registers usually
requires selecting the appropriate bank.
6. Indirect Addressing:
● The PIC18 architecture supports indirect addressing using the FSR (File Select Register),
allowing the CPU to access data indirectly through an address in another register.
Configuration Bits:
It's essential to refer to the specific datasheet and reference manual for the PIC18 device you are
working with, as the memory organization details can vary between different models within the
PIC18 family. The information provided here is a general overview.
1. Definition:
● The Program Counter (PC) is a register within the CPU that keeps track of the memory
address of the next instruction to be fetched and executed.
2. Word Addressing:
● In the PIC18 architecture, the PC is word-addressable. This means that each address
points to a 16-bit instruction word (a single machine instruction).
3. Incrementing:
● The PC is automatically incremented after each instruction fetch. It points to the next
sequential memory location in program memory.
4. Control Flow:
● During program execution, the PC determines the control flow by pointing to the next
instruction to be executed. Conditional branches or jumps modify the PC to alter the
program flow.
5. Reset Condition:
● After a power-up or a reset condition, the PC is typically initialized to the reset vector
address, which is the starting address of the program.
1. Definition:
● The Programmable ROM space, often referred to as program memory or Flash memory,
is where the machine code or program instructions are stored.
2. Type of Memory:
● In PIC18 microcontrollers, Flash memory is used for program storage. It is non-volatile
memory, meaning that the stored program remains even when the power is turned off.
3. Word Size:
● The Flash memory is word-addressable, where each address points to a 16-bit instruction
word.
4. Writing to Flash:
● During the programming phase, the microcontroller allows writing or programming the
Flash memory with the user's program. After programming, the memory becomes
read-only during normal execution.
5. Block Organization:
● The Flash memory is typically organized into multiple blocks. Each block may have a
specific purpose, such as storing program code, data, or bootloader information.
6. Erasing:
● Flash memory can be erased before reprogramming. This is often done at the block level,
and the erasure is a necessary step before writing new data.
7. Program Memory Limitations:
● There might be limitations on the number of write/erase cycles in Flash memory.
Excessive writes can lead to wear, so care should be taken during development and
testing.
8. Configuration Bits:
● Some portions of the Flash memory may be reserved for configuration bits, which control
various aspects of the microcontroller's behavior.
Initialization:
1. Reset Vector:
● The reset vector is the initial address to which the PC is set during a reset condition. It
points to the starting address of the program in Flash memory.
2. Interrupt Vector Table:
● For devices supporting interrupts, there is often an Interrupt Vector Table in program
memory. Each vector contains the starting address of the interrupt service routine for a
specific interrupt source.
In summary, the Program Counter (PC) is responsible for keeping track of the next instruction to
be executed, and the Programmable ROM space (Flash memory) stores the program instructions.
Together, they ensure the sequential execution of machine code instructions in a PIC18
microcontroller. Always refer to the specific datasheet and reference manual for the PIC18
device you are working with for detailed information on the memory organization and
programming considerations.
1. Bank Selection:
● PIC18 microcontrollers feature multiple banks of data memory (RAM), typically referred
to as Bank 0, Bank 1, etc.
● The Bank Select Register (BSR) is used to select the active bank. The BSR holds the
upper bits of the file register address.
2. Access Bank:
● The Access Bank, also known as Bank 0, is a special bank where the lower 128 bytes of
RAM are directly accessible without using the BSR. This is often the default bank after a
reset or during certain instructions.
3. General-Purpose Registers (GPRs):
● General-purpose registers, often referred to as file registers, are used for temporary
storage and manipulation of data during program execution.
● GPRs are organized into banks, and the specific register accessed depends on both the
bank selected by the BSR and the lower bits of the file register address.
It's important to consult the specific datasheet and reference manual for the PIC18 device you are
working with, as details can vary between different models within the PIC18 family. The
organization of file registers and data memory is a crucial aspect of PIC18 programming, and
understanding it is essential for effective code development.
Banks in PIC18:
1. Bank Organization:
● PIC18 devices typically have multiple banks of data memory, commonly referred to as
Bank 0, Bank 1, etc.
● Each bank has its set of GPRs and SFRs.
2. Access Bank (Bank 0):
● The Access Bank (Bank 0) is a special bank that is directly accessible without explicitly
changing the bank. It is often the default bank after a reset or during certain instructions.
3. BSR (Bank Select Register):
● The BSR is a register dedicated to selecting the active bank.
● It is often an 8-bit register, and its value determines the upper bits of the file register
address.
1. Read/Modify/Write Operations:
● When working with file registers in a specific bank, it's common to follow a
read/modify/write procedure:
● Read: Read the current value of the file register.
● Modify: Perform the necessary operations on the data.
● Write: Write the modified value back to the file register.
2. Selecting the Active Bank:
● Before accessing registers in a specific bank, set the BSR register to the desired bank.
● Use the MOVLW and MOVWF instructions to load the bank number into the WREG
and then write it to the BSR, respectively.
MOVLW 0x01 ; Load bank number 1 into WREG
MOVWF BSR ; Set the active bank to Bank 1
MOVLW 0x01 ; Load bank number 1 into WREG MOVWF BSR ; Set the active bank to Bank 1
3. Default Bank (Access Bank):
● Certain instructions implicitly use the Access Bank (Bank 0) if the BSR is not explicitly
set. This simplifies certain operations.
Understanding and managing bank switching is crucial for effective programming in PIC18
microcontrollers, especially when dealing with a large number of registers and variables. Always
refer to the specific datasheet and reference manual for the PIC18 device you are working with
for detailed information on bank switching and register organization.
Example Code:
Here is a simple example code snippet that demonstrates bank switching:
MOVWF 0x30 ; Store the value in the file register at address 0x30 in Bank 2
MOVLW 0x01
MOVWF BSR
Addressing modes:
The PIC18 microcontroller architecture supports various addressing modes, which define how
the processor determines the location of operands for instructions. These addressing modes
provide flexibility in accessing data in program memory (Flash), data memory (RAM), and
special function registers (SFRs). Here are some common addressing modes used in PIC18
assembly language:
These examples show how configuration bits are typically set in assembly language to select the
desired oscillator configuration. The specific names of configuration bits may vary slightly
depending on the exact PIC18 device model.
Always refer to the datasheet and reference manual for the specific PIC18 microcontroller you
are using to obtain accurate information on oscillator configurations and the corresponding
configuration bit settings.
Reset operations of PIC18
Reset operations in PIC18 microcontrollers involve actions taken when the microcontroller is
powered on or undergoes a reset condition. Resetting the microcontroller initializes its various
components, clears registers, and prepares it for a fresh start. There are different types of reset
operations in PIC18 microcontrollers:
Example configuration bits setting for enabling Brown-Out Reset (BOR) and Master Clear
(MCLR)
CONFIG BOR = ON
CONFIG MCLRE = ON
It's essential to configure the appropriate bits in the configuration word to control the behavior of
the microcontroller during reset conditions. The configuration bits vary between different PIC18
devices, so consult the datasheet and reference manual for your specific microcontroller model
for accurate and detailed information on configuring reset-related settings.