Micro Unit 3 Notes
Micro Unit 3 Notes
PIC microcontrollers are designed using the Harvard Architecture which includes:
Microprocessor unit (MPU)
Program memory for instructions
Data memory for data
I/O ports
Support devices such as timers, ADC etc.
Support for serial communication using Various Buses like SPI, I2C
MCU unit includes: Arithmetic Logic Unit (ALU), Registers, and Control Unit
Arithmetic Logic Unit (ALU)
• WREG (8)– working register (Accumulator)
• Status register that stores flags
• Instruction decoder – when the instruction is fetched it goes into the ID
The CPU fetches instructions from memory, decodes them, and passes them to the ALU for execution.
• The arithmetic logic unit (ALU) is responsible for adding, subtracting, shifting and performing logical
operations.
The ALU operates in conjunction with:
– A general purpose register called W register
– And f register that can be any location in data location
Control Unit:
– Provides timing and control signals to various Read and Write operations
Address bus:
I/O ports:
The series of PIC18 consists of five ports such as Port A, Port B, Port C, Port D & Port E. These ports
are used to connect digital Input output Devices
Timers
PIC microcontroller has four timer/counters wherein the one 8-bit timer and the remaining timers have
the choice to select 8 or 16-bit mode. Timers are used for generating accuracy actions, for example,
creating specific time delays between two operations.
ADC
The main intention of this analog to digital converter is to convert analog voltage values to digital
voltage values. The operation of the analog to digital converter is controlled by ADCON0 and ADCON1
special registers.
CCP module
The name CCP module stands for capture/compare/PWM where it works in three modes such as capture
mode, compare mode and PWM mode
Serial Communication
Serial communication is the method of transferring data one bit at a time sequentially over a
communication channel. PIC 18 has SPI, I2C and USART protocol for serial communication.
Each PIC18F member has a 21-bit program counter PC (21 bit). It is used by CPU to point to the
address of next instruction to be executed from ROM.
A 21-bit program counter is capable of addressing the 2Mbyte program memory space
1FFFFF=221=2M
User memory space on the PIC18 microcontroller is 00000H to 7FFFH. Accessing a nonexistent
memory location (8000H to 1FFFFFH) will cause a read of all 0s.
The reset vector where the program starts after a reset is at address 0000H. Addresses 0008H and
0018H are reserved for the vectors of high-priority and low-priority interrupts, respectively, and
interrupt service routines must be written to start at one of these locations.
The PIC18F microcontroller has a 31-entry stack that is used to hold the return addresses for
subroutine calls and interrupt processing. The stack is controlled by a 5-bit stack pointer, which is
initialized to 00000 after a reset.
PIC18F452 each have 32 Kbytes of FLASH memory. This means that it can store up to 16K of
single word instructions Total of word data size= 32K*16
There are two types of registers in the data memory, the General Purpose Register (GPRs) and the
Special function Registers (SFRs).
General purpose registers (GPRs) are used to hold dynamic data during program execution.
SFR has dedicated functions Such as ALU Status, Timers, Serial communication. ADC, I/O Ports etc.
PIC18 implements the access bank to reduce the problem caused by bank switching.
It is the default bank when we power up the PIC18
Access bank is formed using 128 bytes from GPR 00h to 7Fh and 128 bytes from SFR F80h to FFFh
• status register: It is an 8-bit register referred as flag registers and all are conditional
• C (Carry Flag)
– Set when an addition or subtraction generates a carry out of B7 Bits (unsigned Nos.)
• DC (Digit Carry Flag) (Half Carry)
– Set when carry generated from B3 to B4 in an BCD arithmetic operation ( Addition or
Subtraction)
• Z (Zero Flag)
– It reflects the result of arithmetic or logic operations. If result =0, Z=1 and if result ≠0, Z=0
• OV (Overflow Flag)
– Set when result of an operation of signed numbers goes beyond 7-bits- used to represent the
errors { carry from B6 to B7 but no carry out of B7[C=0];Carry out from B7[C=1]}
• N (Negative Flag)
– Binary representation of signed No. It is the reflection of the result of an arithmetic/logic
Operation if Result B7=0 , No. is Positive, if Result B7=1 , No. is negative
Q 7. What are various oscillator options? How they can be selected using config register
Essentially, there are three clock sources for The PIC microcontroller to operate in different modes of operation:
Primary oscillators: The primary oscillators include the External Crystal and Resonator modes
Secondary oscillators: The secondary oscillators are those external sources not connected to the OSC1 or
OSC2 pins.
Internal oscillator block: In addition to being a primary clock source, the internal oscillator block is available
as a power-managed mode clock source.
BOD/BOR
Mostly all microcontrollers have built in Brown-out detection (BOD) or Brown out reset(BOR) circuit,
which monitors supply voltage level during operation. BOD circuit is nothing more than comparator, which
compares supply voltage to a fixed trigger level.
Selecting a power-managed mode requires two decisions: if the CPU is to be clocked or not and the
Selection of a clock source
Switching from one power-managed mode to another begins by loading the OSCCON register.
The SCS1:SCS0 bits select the clock source and determine which Run or Idle mode is to be used
Following Table explains how particular power down mode will be selected
Watch dog timer is Hardware used in PIC microcontroller .This Timer force Microcontroller into reset state
when system is hang or out of control due to execution of incorrect code
CONFIG2H register is Used for Watch dog Timer
This timer is used to prevent a system from going into infinite loop due to software bug