0% found this document useful (0 votes)
26 views

Processor Architecture 2

The document provides an introduction to microcontrollers including: 1. The basic components of a microcontroller including a CPU, program memory, data memory, input/output ports, ADC/DAC, and clock generator. 2. A brief history of microcontrollers from the Intel 8048 in 1976 to modern microcontrollers with flash memory. 3. The key differences between microprocessors and microcontrollers are that microcontrollers have memory and I/O components internally on a single chip whereas microprocessors require external components, making microcontrollers more compact and efficient for embedded systems.

Uploaded by

patolesahil9371
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Processor Architecture 2

The document provides an introduction to microcontrollers including: 1. The basic components of a microcontroller including a CPU, program memory, data memory, input/output ports, ADC/DAC, and clock generator. 2. A brief history of microcontrollers from the Intel 8048 in 1976 to modern microcontrollers with flash memory. 3. The key differences between microprocessors and microcontrollers are that microcontrollers have memory and I/O components internally on a single chip whereas microprocessors require external components, making microcontrollers more compact and efficient for embedded systems.

Uploaded by

patolesahil9371
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 67

PROCESSOR ARCHITECTURE

UNIT I
PIC MICROCONTROLLER
ARCHITECTURE
PRESENT BY :-
Sr.no Student Name Roll.no

1 Omkar Vijay pehere 41

2 Tushar Dilip khairnar 28

3 Kiran Navnath Bodke 05

4 Priya Rajmangal Ray 44

5 Darshan Sunil Pawar 39

6 Harshal Sanjay pagar 36

7 Vinayak Aananda Gire 17

8 Sakshi Hemant Gangurde 13

9 Shraddha Santosh Gade 10

10 Prerna Vijay Bhalerao 02


SYLLABUS
 Introduction:
introduction to microcontroller, Brief history of microcontrollers, Difference between
microprocessor and microcontroller, Criteria for selection of microcontroller.

 PIC18FXXX:
Features and architecture, comparison of PIC 18 series microcontrollers; PIC18F458/452 Pin out
connection, Registers of PIC18F.

 Program and data memory organization:


The Program Counter and Programmable ROM space in the PIC, File register and Access bank,
Bank switching in PIC18.

 Addressing modes:
Addressing modes with instruction example, Oscillator configurations, Reset operations,
Brownout reset, Watchdog timer, Power down modes & Configuration registers
INTRODUCTION
 MICROPROCESSOR :

A microprocessor is a computer processor for which the data processing logic and control is included on a single
integrated circuit (IC), or a small number of ICs.

The microprocessor contains the arithmetic, logic, and control circuitry required to perform the functions of a
computer's central processing unit (CPU).
 COMPONENTS OF
MICROPROCESSOR:

Fig : Block Diagram Of Microprocessor


The microprocessors have these basic blocks as :
1. CPU
2. Bus
3. Memory

1). CPU : Central Processing Unit(CPU) has following important parts −


• Instruction register − It holds the instruction to be executed.
• Decoder − It decodes (converts to machine level language) the instruction.
• ALU − It has necessary circuits to perform arithmetic operations and logical operations.
• Register − It holds intermediate results obtained during program processing.

2). Bus: Connection lines used to connect the internal parts of the microprocessor chip is called bus.
There are three types of buses in a microprocessor −
• Data Bus − Data Bus carries data to and from memory are called data bus. It is a bidirectional bus.
• Address Bus − It is a unidirectional Bus. It carryies address of a memory location or I/O port.
• Control Bus − It is used to carry control signals. like clock signals, interrupt signal or ready signal are called control
bus.

3). Memory: Microprocessor has two types of memory


• RAM − Random Access Memory is volatile memory that gets erased when power is switched off.
• ROM − Read Only Memory is non-volatile memory whose data remains intact even after power is switched off.
Microprocessor can read from it any time it wants but cannot write to it. It is used to store operating system / boot
programs
 MICROCONTROLLER :

The microcontroller is essentially a simple mini-computer embedded on a single integrated chip, it requires many
of the same basic components as a larger and more complex computer.

A microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system.

A typical microcontroller includes a processor, memory and input/output (I/O) peripherals on a single chip.
 COMPONENTS OF
MICROCONTROLLER:

Fig : Block Diagram Of Microcontroller


The basic components of a Microcontroller are :
1. CPU (Central Processing Unit)
2. Program Memory and Data Memory
3. Input and Output Ports
4. ADC and DAC 5. Clock Generator (Oscillator)

• CPU (Central Processing Unit) :


a. It comprises of an Arithmetic Logic Unit (ALU) and a Control Unit (CU).
b. All the arithmetical and logical operations are performed by the Arithmetic Logic Unit (ALU).
c. The timing and operations are controlled by the Control Unit (CU).
• Program Memory: Program memory is a Read-Only Memory (ROM). The instructions are recorded and stored in
the Program Memory.
• Data Memory: Data Memory is Random Access Memory (RAM) and it is used for the storage of temporary data
and variables.
• Input and Output Ports: Input /Output Ports allows the physical connection of the microcontroller to the outside
world. Input data is received from the input ports and after processing the data is placed on the output port.
• Analog to Digital Converter :(ADC) and Digital to Analog Converter (DAC) The ADC and DAC are use to convert the
signal in the form required. For example if the input data is analog signal it is converted into digital form.
• Clock Generator (Oscillator): The clock generator is used to generate the clock using the external crystal
connected to microcontroller. The Clock is used for the synchronization of data and the flow of the commands.
 BRIEF HISTORY OF MICROCONTROLLERS :

• The first computer system on a chip optimized for control applications micro - controller was the Intel 8048 released
in 1976, with both RAM and ROM on the same chip.
• Most microcontrollers at this time had two variants. One had an erasable EEPROM program memory, which was
significantly more expensive than the PROM variantwhich was only programmable once.
• The Evolution of Microcontrollers has undergone a significant change.

 The development table of microcontrollers is as shown in Table.


YEAR MICROCONTROLLER FEATURES

1976 Intel 8048 64 bytes RAM, 1 kB ROM and I/O ports.

1980 8031 128 bytes RAM, Two 16-bit timers, One serial port and I/O
ports.
1980 Intel 8051 128 bytes RAM, 4 kB ROM, Two 16-bit timers, One serial port
and I/O ports.
1984 Atmel 89C51 128 bytes RAM, 4 kB ROM, Two 16-bit timers, One serial port
and I/O ports.
1985 Motorola 68HV11A8 256 bytes RAM, 8 kB ROM, 512 bytes EEPROM, 16-bit timer; 8
channel 8-bit A/D, SCI, SPI and I/O ports.
 HISTORY OF MICROCONTROLLERS :

1. Intel Corporation developed the first microcontroller, the 4-bit i4004, in 1971 for BUSICOM's calculators.

2. The i4004's success led Intel to develop subsequent microcontrollers, including the 16-bit 8086, paving the way for
CPUs in personal computers.

3. Toshiba introduced the 12-bit TLCS-12 microcontroller in 1973, initially used as Ford's in-vehicle engine controller.

4. Intel's 8048, a system-on-a-chip optimized for control applications, became highly successful and found its way into
over a billion PC keyboards.

5. Erasable microcontrollers with EPROM program memory were more expensive due to ceramic packages and quartz
windows.

6. In 1993, EEPROM memory was introduced, allowing for quick electrical erasure without expensive packaging,
facilitating rapid prototyping.

7. Atmel introduced the first microcontroller with Flash memory in 1993, leading to the adoption of this memory type
in the industry.
 DIFFERENCE BETWEEN MICROPROCESSOR AND MICROCONTROLLER :
Parameter Microprocessor Microcontroller
Microprocessors can be understood as the Microcontrollers can be understood as
Definition heart of a computer system. the heart of an embedded system.
A microprocessor is a processor where the A microcontroller is a controlling device
What is it? memory and I/O component are wherein the memory and I/O output
connected externally. component are present internally.
The circuit is complex due to external Microcontrollers are present on chip
Circuit complexity connection. memory. The circuit is less complex.
The memory and I/O components are to The memory and I/O components are
Memory and I/O components be connected externally. available.
Microprocessors can’t be used in compact Microcontrollers can be used with a
Compact system compatibility system. compact system.
Efficiency Microprocessors are not efficient. Microcontrollers are efficient.
Microprocessors have a zero status flag. Microcontroller doesn’t have a zero
Zero status flag status flag.
Microprocessors have less number of Microcontrollers have more number of
Number of registers registers. registers.
Microprocessors are generally used in Microcontrollers are generally used in
Applications personal computers. washing machines, and air conditioners.
 CRITERIA FOR SELECTION OF MICROCONTROLLER :
System Requirement:
• Begin with application needs.
• Decide on 4-bit, 8-bit, 16-bit, or 32-bit microcontroller based on processing power requirements.
• 8-bit microcontrollers are popular for embedded applications due to availability and long-standing technology.

Memory Architecture:
• CoOn-chip or off-chip memory and size impact system cost and operation speed.

Availability:
• Check device nsider program memory (Flash, OTP, ROM), data memory (on-chip SRAM or external SDRAM), and
nonvolatile memory (EEPROM or Flash).
• availability in needed quantities for current and future use.

Size:
• Select an IC with the appropriate number of I/O pins to minimize size and physical space.

Compatibility:
• Ensure pin and function compatibility for easy system upgrades.

Functionality Testing:
• Test MCU function within the designed circuit before system development.
Power Management:
• Consider power consumption for battery life and heat dissipation.
• Evaluate power-down, idle, and sleep modes in microcontrollers.

Manufacturer's Track Record:


• Choose stable manufacturers with a good track record, performance, and reliability.
• Consider factors like design challenges, on-time delivery, and financial stability.

Manufacturer's Support:
• Look for manufacturers with effective support through helplines, knowledgeable personnel, and after-sales
assistance.

Development Support:
• Consider development tools like assemblers, debuggers, C compilers, and emulators.
• Integrated Development Environments (IDEs) like Keil uVision or MPLAB are crucial.

Cost:
• Minimize costs by tactfully selecting components and optimizing features.
• ROM-based devices are preferred for high volume applications due to lower cost and code security.
PIC18FXXX
 PIC MICROCONTROLLER INTRODUCTION :

The term PIC stands for “Peripheral Interface Controller” .

It’s the popular line of microcontroller that is currently manufactured by Microchip Technology Inc.

The PIC microcontroller was introduced in 1993 by Microchip although the original chip design was created by General
Instruments in 1985. PIC microcontrollers are meant to enable simple programming and interfacing in embedded
system design.

Most of the PIC microcontrollers that hit the market are 8-bits microcontrollers, although Microchip did introduce some
16-bits and 32-bits PIC microcontrollers.

PIC 18 series microcontroller


 FEATURES OF PIC MICROCONTROLLER :
1. Harvard architecture : PIC uses Harvard architecture. Harvard architecture has the program memory and data
memory as separate memories and are accessed from separate buses. This improves bandwidth over traditional Ven
Neumann architecture in which program and data are fetched from the same memory using the same bus.

2. High performance RISC processors :


• C-Language friendly architecture
• PIC16 source code compatible
• Linear program memory addressing to 2 Mbyte
• Linear data memory addressing up to 4 Kbytes
• Up to 10 MIPs operation.
• 16-bit wide instructions, 8-bit wide data path2

3. Register file architecture: The register files/data memory can be directly or indirectly addressed. All special function
registers, including the program counter, are mapped in the data memory.
Instruction set simplicity

4. Reduced instruction set:


• Reduced instruction set: The instruction set of PIC consists of only 77 instructions.
• Orthogonal (symmetric) instructions: The instructions are orthogonal. It is possible to carry out any operation on
any register using any addressing mode when the instructions are orthogonal.
• Single word instructions.
5. FLASH program memory: In sizes from 8 to 128 Kbytes.

6. Data RAM: From 256 to 4 Kbytes.

7. Built-in power-on-reset: PIC has a built-in power-on-reset.

8. Brown-out reset: PIC has a brown-out-reset. A brown-out-reset feature causes a reset of the PIC when the power
supply voltage drops below 4 V or so.

9. Watchdog Timer (WDT) : Watchdog timer is a special timer with specific function. It is used to prevent software
crashes, i.e. endless loop.

10. Power saving SLEEP mode: The PIC can put itself to sleep to save power during intervals when it has nothing to do.
Thus, PIC supr saving SLEEP mode.

11. Flexible 8 and 16-bit timers.

12. Interrupt Control : The PIC can control up to 12 independent interrupt sources.

13. 10-bit ADC (Analog to digital converter)

14. Capture/Compare/PWM (CCP) modules : Up to five (CCP) modules.


 Peripheral Features :

1. High current sink/source 25mA/25mA.

2. Two 16-bit timer/counter (TMR1, TMR3).

3. One 8-bit/16-bit timer/counter with prescaler.

4. One 8-bit timer/counter with 8-bit period register.

5. Capture 16-bit, max. resolution 6.25ns (TCY/16).

6. Compare 16-bit, max. resolution 100ns.

7. 3-wire SPILwith Interrupt-on-Address Bit.

8. IPC Master and Slave mode.

9. Secondary Oscillator Clock Option Timer1/Timer3.

10. 1,2 or 4 PWM Outputs with Selectable Polarity.

11. Eight Channel 10-bit Analog-to-Digital Converter.


 ARCHITECTURE OF PIC MICROCONTROLLER :
Architecture of PIC Microcontroller
1.CPU (Central Processing Unit):

PIC microcontroller’s CPU consists of

•Arithmetic logic unit (ALU)


•Memory unit (MU)
•Control unit (CU)
•Accumulator

ALU is used for arithmetic operations and for logical decisions. Memory is used for storing the
instructions after processing. Control unit is used to control the internal and external peripherals which
are connected to the CPU and accumulator is used for storing the results.

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.

General Purpose Registers (GPR):

These registers don’t have any special function. These are used for general purpose for multiplying,
addition or subtraction and then storing the results in other registers. CPU can easily access the data in
these registers.

Special Function Registers (SFR):


These registers are used for special purposes and they cannot be used as normal registers. Their
function is set at the time of manufacturing. They perform the function assigned to them and user
cannot change the function of SFR. Three important SFRs for programming are:

STATUS register : It changes the bank


PORT registers : It assigns logic values 0 or 1 to the ports
TRIS registers : It is a data direction register for input and output
•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.

9.A/D CONVERTER:

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.
 comparison of PIC 18 series microcontrollers :
 PIC18F458/452 PINOUT CONNECTION :

PIC18F452 PIC
Microcontroller

PIC18F452
 PIC18F452 PIN CONFIGURATION :
Pin Number Pin Name Description

1 MCLR/VPP Master Clear (input) or High voltage ICSP programming enable pin mainly used for
programming purposes.

2 RA0/AN0 Bidirectional I/O pin of Port A bit 0 or Analog input 0

3 RA1/AN1 Bidirectional I/O pin of Port A bit 1 or Analog input 1

4 RA2/AN2/VREF- Bidirectional I/O pin of Port A bit 2 or Analog input 2 or A/D Reference (Low)
Voltage.

5 RA3/AN3/VREF+ Bidirectional I/O pin of Port A bit 3 or Analog input 3 or A/D Reference (High)
Voltage.

6 RA4/T0CKI Bidirectional I/O pin of Port A bit 4 or Timer 0 external clock input.

7 RA5/AN4/SS/LVDIN Bidirectional I/O pin of Port A bit 5 or Analog input 4 or SPI Slave Select input or
Low voltage Detect input.

8 RE0/RD/AN5 Bidirectional I/O pin of Port E bit 0 or Read control for parallel slave port or Analog
input 5
9 RE1/WR/AN6 Bidirectional I/O pin of Port E bit 1 or Write control for parallel slave port
or Analog input 6

10 RE2/CS/AN7 Bidirectional I/O pin of Port E bit 2 or Chip select control for parallel slave
port or Analog input 7.

11 VSS Positive supply pin.

12 VDD Ground supply pin.

13 OSC1/CLKI Oscillator Crystal or External clock input.

14 OSC2/CLKO/RA6 Bidirectional I/O pin of Port A bit 6 or Oscillator crystal or clock output.

15 RC0/T1OSO/T1CKI Bidirectional I/O pin of Port C bit 0 or Timer 1 Oscillator output or Timer
1/Timer 3 external clock input.

16 RC1/T1OSI/CCP2 Bidirectional I/O pin of Port C bit 1 or Timer 1 Oscillator input or Capture 2
input, Capture 2 output, PWM 2 output.

17 RC2/CCP1 Bidirectional I/O pin of Port C bit 2 or Capture 1 input, Capture1 output,
PWM1 output
18 RC3/SCK/SCL Bidirectional I/O pin of Port C bit 3 or Synchronous serial clock input/output
for SPI mode or Synchronous serial clock input/output for 12C mode.

19 RD0/PSP0 Bidirectional I/O pin of Port D bit 0 or Parallel slave Port Data

20 RD1/PSP1 Bidirectional I/O pin of Port D bit 1 or Parallel slave Port Data.

21 RD2/PSP2 Bidirectional I/O pin of Port D bit 2 or Parallel slave Port Data

22 RD3/PSP3 Bidirectional I/O pin of Port D bit 3 or Parallel slave Port Data

23 RC4/SDI/SDA Bidirectional I/O pin of Port C bit 4 or SPI Data In or 12C data I/O.

24 RC5/SDO Bidirectional I/O pin of Port C bit 5 or SPI Data Out.

25 RC6/TX/CK Bidirectional I/O pin of Port C bit 6 or USART Asynchronous Transmit or


USART Synchronous Clock

26 RC7/RX/DT Bidirectional I/O pin of Port C bit 7 or USART Asynchronous Receive or


USART Synchronous Data
27 RD4/PSP4 Bidirectional I/O pin of Port D bit 4 or Parallel slave Port Data

28 RD5/PSP5 Bidirectional I/O pin of Port D bit 5 or Parallel slave Port Data

29 RD6/PSP6 Bidirectional I/O pin of Port D bit 6 or Parallel slave Port Data

30 RD7/PSP7 Bidirectional I/O pin of Port D bit 7 or Parallel slave Port Data

31 VSS Ground Supply pin

32 VDD Positive supply pin

33 RB0/INT0 Bidirectional I/O pin of Port B bit 0 or External Interrupt 0.

34 RB1/INT1 Bidirectional I/O pin of Port B bit 1 or External Interrupt 1.

35 RB2/INT2 Bidirectional I/O pin of Port B bit 2 or External Interrupt 2.

36 RB3/CCP2 Bidirectional I/O pin of Port B bit 3 or Capture 2 input, Compare 2 output,
PWM 2 output.
37 RB4 Bidirectional I/O pin of Port B bit 4 with IOC (Interrupt-on-change)

38 RB5/PGN Bidirectional I/O pin of Port B bit 5 with IOC (Interrupt-on-change) or Low
Voltage ICSP programming enable pin

39 RB6/PG Bidirectional I/O pin of Port B bit 6 with IOC (Interrupt-on-change) or In-
Circuit Debugger and ICSP programming clock pin.

40 RB7/PGD Bidirectional I/O pin of Port B bit 7 with IOC (Interrupt-on-change) or In-
Circuit Debugger and ICSP programming data pin
 REGISTERS OF PIC18F :
The PIC18F microcontroller family has several types of registers that are used to control the operation of the device.
Here are some of the main registers:

General Purpose Registers (GPRS):


These are the 8-bit registers used to store data and program variables during the execution of the program. The PIC18F
has 96 GPRS, numbered from 0x00 to 0x5F.
Special Function Registers (SFRs): These are the registers that control the operation of the microcontroller. They are
used to configure and control the operation of the various peripherals on the device, such as timers, UARTs, and SPI
modules. The PIC18F has many SFRs, and they are mapped to specific memory addresses in the device's memory
space. These registers are used to control various on-chip peripherals, such as the analog-to-digital converter (ADC), the
serial communication modules, and the PWM modules. Some examples of SFRs include the STATUS register, the PORTB
register, and the TMRO register.

Control Registers:
These registers control the operation of the microcontroller itself. For example, the Program Counter (PC) register
contains the address of the next instruction to be executed, while the Status register contains flags that indicate the
outcome of the most recent operation.

Stack Pointer (SP):


This register points to the top of the stack, which is used to store data during subroutine calls and interrupts. This
register keeps track of the current location of the top of the stack, which is used for storing return addresses and other
data during subroutine calls.
Program Counter (PC):
This register contains the address of the next instruction to be executed.

Special Event Trigger (SRE) Register:


This register is used to configure the SRE module, which allows the device to trigger an interrupt when a specific event
occurs.

File Registers:
These are the most used registers in the PIC18F microcontroller. They are used to store data values, control flags, and other
information that is needed during program execution.

Status Register (STATUS):


This register contains several status flags that indicate the current state of the microcontroller. These flags include the carry
flag, the zero flag, and the interrupt enable flag, among others.

1. W register: This register is a temporary storage location used for arithmetic and logic operations.
2. BSR register: This register is used to select the bank of GPRs that will be accessed.
3. FSR register: This register is used to select the memory bank that will be accessed when reading or writing to memory.

Timer Registers:
The PIC18F has several timer registers, such as TMRO, TMR1, TMR2, and TMR3. These registers can be used for measuring
time intervals or generating timing signals.
Interrupt Registers:
These registers are used to enable and disable interrupts and to indicate the source of an interrupt.

Configuration Registers:
These registers are used to configure various settings of the microcontroller, such as clock frequency, oscillator type, and
other hardware parameters.

ADC registers:
The PIC18F has an Analog-to-Digital Converter (ADC) module, which has several registers for configuring and controlling the
ADC.
 PROGRAM AND DATA MEMORY ORGANIZATION:
PIC microcontrollers have a Harvard architecture, which means they have separate memory spaces for program
memory and data memory.

Program memory: also known as Flash memory, is used to store the code that the microcontroller executes. It is non-
volatile, which means that the code remains in memory even when power is removed. The size of the program memory
varies depending on the specific PIC microcontroller, but it typically ranges from a few kilobytes to a few megabytes.

Data memory: on the other hand, is used to store data that the program manipulates during execution. There are
several types of data memory in a PIC microcontroller, including:

• RAM (Random Access Memory): This is volatile memory that is used to store data that is frequently accessed or
modified during program execution. The size of RAM also varies depending on the specific PIC microcontroller, but it
typically ranges from a few hundred bytes to a few kilobytes.

• EEPROM (Electrically Erasable Programmable Read-Only Memory): This is non- volatile memory that is used to
store data that needs to be retained even when power is removed, EEPROM memory is typically smaller than
program memory and RAM.

• Special Function Registers (SFRs): These are memory locations that are used to control the behaviour of the
microcontroller's peripherals, such as timers, interrupts, and input/output ports.
 THE PROGRAM COUNTER IN THE PIC :
• A program counter is a register in a CPU that contains the address (location) of the instruction being executed at
the current time. After each instruction is fetched, the program counter is incremented to point to the next
instruction in the sequence.
• The PC can be accessed/modified by jump and branch instructions. Therefore, the destination address can be
loaded to the program counter via branch instructions.
• The width of the program counter decides how many memory locations CPU canaccess. More the width, more the
memory locations CPU can access.
• the width of program counter in various PIC families and code memory access by them.

PIC family PC width Memory address range Code memory


PIC12F 12 bit 000 - FFFH 4 KBytes
PIC16F 14 bit 0000 – 3FFFH 16 KBytes
PIC18F 21 bit 000000 – 1FFFFFH 2 MBytes
• the 21 bit program counter in PIC18 Family. The first location of program memory in PIC has the address of 00000H;
however the last location can be different depending on the size of the ROM on the chip.

Bit program counter of PIC18 family

• Program Counter (PC) - 21-bit register that holds the program memory address while executing programs. This
means that the PIC18 family can access program addresses 000000 to 1FFFFFH, a total of 2M bytes of code.
 THE PROGRAMMABLE ROM SPACE IN THE PIC :

PIC Family Code (ROM) Memory Address Range


PIC18F2220 4 KBytes 00000 - 00FFFH
PIC18F2410 16 KBytes 00000 - 03FFFH
PIC18F458 32 KBytes 00000 - 07FFFH
PIC18F6680 64 KBytes 00000 - 0FFFFH
PIC18F8722 128 KBytes 00000 - 1FFFFH

shows program ROM space for PIC18F458 and PIC18F8722. As shown in the Reset vector address is at 0000h and the
interrupt vector addresses are at 0008h and 0018h
• The PIC18F458 has 32 kbytes of flash program memory. This translates into 32768 single-word instructions, which can
be stored in the program memory.

• On the other hand, the PIC18F8722 has 128 kbytes of Flash program memory. Thistranslates into 131072 single-word
instructions, which can be stored in the program memory.
 FILE REGISTER AND ACCESS BANK, BANK SWITCHING IN PIC18 :
• In PIC18 microcontrollers, the data (Read/Write) memory is implemented as staticRAM. It is also known as File
Register.

• Like WREG we can perform arithmetic and logic operations on many locations of the file register data RAM.

• PIC microcontroller's file register size ranges from 32 bytes to several thousands ofbytes depending on the chip.

• shows the file register organization for the PIC18FXXS devices. It is 4096 bytes of data memory with 12-bit address
for each register.

• The data memory map is divided into as many as 16 banks that contain 256 bytes. each. The lower 4 bits of the
Bank Select Register (BSR) select which bank will be accessed.

• When using direct addressing, the Bank Select Register (BSR) is used to select the desired bank.

• BSR<3:0> holds the upper 4 bits of the 12-bit RAM address. These 4 bits are used to select the desired bank. The
BSR<74> bits will always read U's and writes will have no effect.

• The file register data memory of PIC is divided into two sections:
 Special Function Registers (SFRS): Used for control and status of the controller and peripheral functions.
 General Purpose Registers (GPRs): Used for data storage and scratchpad operations in the user's application.
Data memory map
• The SFRs start at the last location of Bank 15 (FFFh) and grow downwards. GPRS start at the first location of Bank 0
and grow upwards.

• The entire data memory may be accessed directly or indirectly. Direct addressing may require the use of the BSR
register. Indirect addressing requires the use of the File Select Register (FSR). Each FSR holds a 12-bit address value
that can be used to access any location in the data memory map without banking.

• File Select Registers: FSRO, FSRI and FSR2. These registers are composed of two 8-bit registers: PSRH and FSRL.

• The Access Bank is comprised of the upper 160 bytes in Bank 15 (SFRs) and thelower 96 bytes in Bank 0. These two
sections will be referred to as Access Bank High and Access Bank Low, respectively.

• All the instructions without 'A' letter in instructions assume the access bank as adefault bank. Here, A 0. When 'A'
letter is included in the instruction, A is 1,the instruction use bank select register to select the bank.

• Upon reset BSR 0000H and by default Bank) is selected. We can load 0001H in. BSR to select Bank1, 0002H in BSR to
select Bank2 and so on.
 ADDRESSING MODES:

Addressing Modes :
The term addressing modes refers to the way in which the operand of an instruction is specified. The addressing
mode specifies a rule for interpreting or modifying the address field of the instruction before the operand is actually
executed

In computer programming, addressing modes are primarily of interest to those who write in assembly languages and
to compiler writers. For a related concept see orthogonal instruction set which deals with the ability of any instruction
to use any addressing mode. The PIC18F Microcontroller has 4 addressing modes.

1. Immediate Addressing Mode.

2. Direct Addressing Mode.

3. Register Indirect Addressing Mode.

4. Register Indirect/Indexed ROM Addressing Mode.


 IMMEDIATE ADDRESSING MODE :

• In immediate addressing mode, the immediate data is specified in the instruction.Immediate data is also called literal
in PIC18.

• The immediate addressing mode is used to load the data into PIC registers and WREG register. However, we cannot
use immediate addressing mode to load data. into any of the file register.Examples:
1. MOVLW 0x50 :Load 50 H into WREG
2. ANDLW D ‘18’ :Logically AND WREG with 18 decimal
3. ADDLW B' 01100000 : Add 60 H in WREG.

• The letter 'L' in the instruction means literal (immediate).

• To load immediate data in file register data RAM, we have to load immediate data in WREG register and then it can
be copied to file register data RAM location.

• We can use the EQU directive to access immediate data as shown below.
• NUM EQU 0x50

MOVLW NUM Load 50H in WREG.


Immediate Addressing Mode
 DIRECT ADDRESSING MODE :

In direct addressing mode, the operand data is in the file register (RAM) data memory. The address of this memory
location is specified in the instruction.

Examples:

1. MOVWF 0X10 Copy contents of WREG into File Register RAM location 10 H
2. MOVFF OX10, 0X20 Copy contents of location 10 H to 20 H
3. MOVFF OX30, PORTC Copy contents of location 30 H to PORTC.

• The letter 'F in the instruction means the address of the file register location.

• The letter FF in the instruction means the both source and destination addresses. are file register locations.
Direct Addressing Mode
 REGISTER INDIRECT ADDRESSING MODE :

Register indirect addressing mode is used for accessing data stored in the fileregister (RAM) data memory.
In this addressing mode, three file select registers FSRO, FSR1, and FSR2 are usedas pointers to the memory locations
of the file register (RAM) data memory.

Each of the FSRO, FSRI, and FSR2 registers has an INDF register associated withit, and these are called INDFI, INDFI, and
INDF2 When we move data into INDFx we are moving data into a RAM location pointed to by the FSRx.

Examples:

1. LFSR 1, 0x55 :Load FSR1 with 55H


MOVWF INDF1 :copy contents of WREG into RAM location.
:whose address is held by PSR1 register, Le. 55H.

2. LFSR 0, 0x40 :Load FSRO with 40H


MOVF INDFO,W :Copy the contents of RAM location pointed by FSRO to WREG.
Register Indirect Addressing Mode
 REGISTER INDIRECT/INDEXED ROM ADDRESSING MODE

• We use code space to store fixed data along with the code. This addressing mode is used for accessing the fixed
data from look up tables that reside in the PIC18 program ROM. This process is often called table processing.

• Directive DB is used to define an 8-bit fixed data in data ROM. Here, we have to use special function register to
point the data to be fetched from the code space.

• Two registers are used in the table processing TBLPTR (TaBLe PoinTR) and TABLAT (TABle LATch).

• The 21 bit register TBLPTR is used to access byte from PIC18 program ROM. With 21 bit register TBLPTR we can
cover the entire 2M program (code) space for PIC18.

• TBLPTR register in divided into three parts: TBLPTRL (Low), TBLPTRH (High),and TBLPTRU (Upper). These parts are
of the SFRS.

• TABLAT register is used for keeping the byte read from code space pointed byTBLPTR.

• Example:
MOVLW 0x0 : WREG 0 Look-up Table low-byte address
MOVWF TBLPTRL :Load Look-up Table low-byte address in TBLPTRL register
MOVLW 0x10 :WREG 10 Look-up Table high-byte address
MOVWF TBLPTRH :Load Look-up Table high-byte address in TBLPTRH register
MOVLW 0x0 :WREG 0 Look-up Table upper-byte address
Index Addressing Mode
 OSCILLATOR CONFIGURATIONS :
Mid-Range devices can have up to eight different oscillator modes. The user can program up to three device
configuration bits (FOSC2, FOSC1 and FOSC0) to select one of these eight modes:
• LP Low Frequency (Power) Crystal
• XT Crystal/Resonator
• HS High Speed Crystal/Resonator
• RC External Resistor/Capacitor (same as EXTRC with CLKOUT)
• EXTRC External Resistor/Capacitor
• EXTRC External Resistor/Capacitor with CLKOUT
• INTRC Internal 4 MHz Resistor/Capacitor
• INTRC Internal 4 MHz Resistor/Capacitor with CLKOUT

 The LP, XT, and HS modes differ in the gain of the internal inverter of the oscillator circuit, allowing for different
frequency ranges.

 It is advisable to select the oscillator mode with the lowest gain that still meets specifications to minimize
dynamic currents (IDD).

 The frequency range of each oscillator mode represents the recommended (tested) frequency cutoffs, but
choosing a different gain mode is acceptable with thorough validation, considering voltage, temperature, and
component variations.
• The PIC18FXX8 can be operated in one of eight oscillator modes, programmable by three configuration bits
(FOSC2, FOSC1 and FOSCO).
 RESET OPERATIONS :
The reset logic is used to place the device into a known state. The source of the reset can be determined by using
the device status bits. The reset logic is designed with features that reduce system cost and increase system
reliability.

 Reset Function :

Reset function is one of the most advanced features that is available on all modern microcontrollers. The PIC18
series have various kinds of resets. The various kinds of reset options that are available on PIC 18 series are given
below.

• Power-on Reset (POR).


• MCLR Reset during normal operation.
• MCLR Reset during Sleep.
• WDT Reset (during normal operation).
• WDT Wake-up (during Sleep).
• Brown-out Reset (BOR).
MCLR:
MCLR is an advanced reset path that helps to filter the unwanted noise. This filter helps to detect unwanted clock
pulses and other noise signals and filter such pulses. It should be noted that a WDT Reset does not drive MCLR pin
low. The behaviour of the ESD protection on the MCLR pin differs from previous devices of this family. Voltages
applied to the pin that exceed its specification can result in both Resets and current consumption outside of device
specification during the Reset event. For this reason, Microchip recommends that the MCLR pin no longer be tied
directly to VDD.

Power-on Reset (POR):


The power –on-reset signals are generated by on-chip when VDD rise is detected. In the normal conditions, the VDD
rise is in the range of 1.2v to1.7v. To take the advantage of POR, connect the MCLR pin to VDD by the resistor
capacitor (RC) network. Before the device is set to start for its normal operation, the different operating parameters
such as frequency, voltage, temperature, and so on must be checked to see if they are normal or proper. If not, the
chip/circuit must be held in reset until the operating conditions are proper or normal. Brown-out-reset function
provides support for these operations.

Power-up Timer (PWRT):


The Power-up Timer provides a fixed 72 ms nominal time-out on power-up only from the POR. The Power-up Timer
operates on an internal RC oscillator. The chip is kept in Reset as long as the PWRT is active. The PWRT’s time delay
allows VDD to rise to an acceptable level. A configuration bit is provided to enable or disable the PWRT. The power-
up time delay will vary from chip to chip due to VDD, temperature and process variation
Oscillator Start-up Timer (OST):
The Oscillator Start-up Timer (OST) provides a delay of 1024 oscillator cycles (from OSC1 input) after the PWRT
delay is over (if PWRT is enabled). This helps to ensure that the crystal oscillator or resonator has started and
stabilized. The OST time-out is invoked only for XT, LP and HS modes and only on Power-on Reset or wake-up from
Sleep.

Brown-out Reset (BOR):


Brown-out-reset is a special resetting function in modern controllers. Once the brown-out occurs, the device will
remain in Brown-out Reset until VDD rises above VBOR. The Power-up Timer then keeps the device in Reset for
TPWRT. If VDD should fall below VBOR during TPWRT, the Brown-out Reset process will restart when VDD rises
above VBOR with the Power-up Timer Reset. The Power-up Timer is always enabled when the Brown-out Reset
circuit is enabled, regardless of the state of the PWRT configuration bit.

Time-out Sequence:
On power-up, the time-out sequence is as follows: the PWRT delay starts (if enabled) when a POR Reset occurs.
Then, OST starts counting 1024 oscillator cycles when PWRT ends (LP, XT, and HS). When the OST ends, the device
comes out of Reset. If MCLR is kept low long enough, the time-outs will expire. Bringing MCLR high will begin
execution immediately. This is useful for testing purposes or to synchronize more than one PIC16F87XA device
operating in parallel. Table shows the Reset conditions for the Status, PCON and PC registers, while Table shows the
Reset conditions for all the registers.
 BROWNOUT RESET :
• A Brown-out Reset (BOR) is a circuit that monitors the Vpp level during operation by comparing it to a fixed
threshold level. When Vpo drops below the threshold level, the Brown-out Reset is activated.

• When Vpp rises again, the controller is restarted after a specified delay. This ensures that the device does not
continue program execution outside of its valid operation range, which can lead to improper code execution.

• Not all devices have BOR, but most do, and some have multiple voltage thresholds to select from.

• Many PIC microcontrollers have a BOR with configurable voltage levels. Devicefamilies, such as the PIC18F,
PIC24F and dsPIC30F series, support the BOR threshold levels. Table shows voltage thresholds for PIC18FXX8.
CONFIG2L: Configuration Register 2 Low (Byte Address 300002h)

• We can configure BOR threshold levels using BORV1 : BORVO bits in the CONFIG2L register.

• CONFIG2L. register also allows us to enable/disable Power-up Timer Enable bit.


 Watchdog timer :
• There are countless applications where the system cannot afford to get stuck at a point (not even for a small
duration of time). For example, in a radar system, if the system hangs for 5 minutes, it can result in serious
repercussions (an enemy plane or missile may go undetected resulting in huge losses).

• The watchdog timer is loaded with a timeout period which is dependent on the application. Whenever software
failed to clear the watchdog timer before its timeout period, the watchdog timer resets the system.

• In PIC18FXX8, the Watchdog Timer is a free running, on-chip RC oscillator which does not require any external
components. This RC oscillator is separate from the RC oscillator of the OSC1/CLKI pin.

• During normal operation, a WDT time-out generates a device Reset (Watchdog Timer Reset). If the device is in
Sleep mode, a WDT time-out causes the device to wake-up and continue with normal operation (Watchdog Timer
wake-up).

the Watchdog Timer is enabled/disabled by a device configuration bit. If the WDT is enabled, software execution
may not disable this function. When the WDTEN (Watchdog Timer Enable) configuration bit is cleared, the SWDTEN
(Software Controlled Watchdog Timer Enable) bit in the watchdog timer control register.(WDTCON) enables/disables
the operation of the WDT.
• The WDT has a postscaler that can extend the WDT Reset period. The postscaler is selected at the time of
device programming by the value written into WDTPS2:WDTPSO bits of the CONFIG2H Configuration register.
 Power down modes & Configuration registers :
• By setting the PD bit of the PCON register from within the program, the microcontroller is set to Power down
mode.

• thus turning off its internal oscillator and reduces power consumption enormously.

• The microcontroller can operate using only 2V power supply in power- down mode, while a total power
consumption is less than 40uA.

• The only way to get the micro controller back to normal mode is by reset.

• While the microcontroller is in Power Down mode, the state of all SFR registers and I/O ports remains
unchanged.

• By setting it back into the normal mode, the contents of the SFR register is lost, but the content of internal
RAM is saved.

• Reset signal must be long enough, approximately 10mS, to enable stable operation of the quartz oscillator.

You might also like