MC 6
MC 6
PIC
• PIC microcontroller is the smallest microcontroller in the world and are programmed to execute
large number of operations.
• PIC microcontrollers hold the ability of faster execution of programs than microcontrollers.
• It was invented in 1989 by microchip technology corporation and was an 8-bit microcontroller.
• Microchip Inc. has developed the PIC18 series of microcontrollers for use in high-pin count, high-
density, and complex applications.
• The PIC18F microcontrollers offer costefficient solutions for general purpose applications written in
C that use a real-time
• operating system (RTOS) and require a complex communication protocol stack such as TCP/IP,
CAN, USB, or ZigBee
• 77 instructions
• DC to 40MHz operation
• 8 x 8 hardware multiplier
D. Accumulator
• Control unit is used to control the internal and external peripherals which are connected to the
CPU
• The ALU gets one of the input operand from W register (WREG) or the IR (in case of immediate
addressing mode).
• The other operand may be given either from a register or a memory location, and hence the other
input side of ALU is connected to the internal data bus.
• For transfer of data, ALU is not required.
• The task of data transfer is carried out by the control unit by issuing various control signals
• Status Register
• The WREG (Working Register) Register is one of the most widely used registers of the PIC.
• 8-bit register any data larger than 8 bits must be broken into 8-bits chunks before it is processed.
• If values 0 to F are moved into an 8-bit register such as WREG, the rest of the bits are assumed to
be all zeros.
• Moving a value larger than 255 (FF in hex) into the WREG register will truncate the upper byte and
cause a warning in the .err file.
Ex.
B. Status Register
• It is a 8-bit register
D5, D6 & D7 are not implemented & reserved for future used
C. Stack
• PIC18CXX8 has a 21-bit stack with 31 levels, or in other words, a group of 31 memory locations, 21
bits wide, with special purpose.
• Its basic role is to keep the value of program counter after a jump from the main program to an
address of a subprogram.
• In order for a program to know how to go back to the point where it started from, it has to return
the value of a program counter from a stack.
• When moving from a program to a subprogram, program counter is being pushed onto a stack
• When executing instructions such as RETURN, RETLW or RETFIE which were executed at the end of
a subprogram, program counter will be taken from a stack so that program will continue where was
stopped before it was interrupted.
• These operations of placing on and taking off from a program counter stack are called PUSH and
POP, and are named according to similar instructions on some bigger microcontrollers.
3. Data Memory
• The data memory address bus is 12 bits with the capability to address up to 4Mbytes.
• The memory in general consists of sixteen banks, each of 256 bytes, where only 6 banks are used.
• The PIC18F452 has 1536 bytes of data memory (6 banks 256 bytes each) occupying the lower end
of the data memory.
• Bank switching happens automatically when a high-level language compiler is used, and thus the
user need not worry about selecting memory banks during programming.
4. Program Memory
• Program memory addresses consist of 21 bits, capable of accessing 2Mbytes of program memory
locations.
• The PIC18F452 has only 32Kbytes of program memory, which requires only 15 bits.
• A table pointer provides access to tables and to the data stored in program memory.
• The program memory contains a 31-level stack which is normally used to store the interrupt and
subroutine return addresses.
5. PWM Mode
• The pulse width modulation (PWM) mode produces a PWM output at 10-bit resolution.
• A PWM output is basically a square waveform with a specified period and duty cycle.
Where
• The PWM duty cycle is selected by writing the eight most significant bits into the CCPR1L register
and the two least
• Set PWM duty cycle by writing to the CCPR1L register and CCP1CON <5:4> bits
• Set the TMR2 prescale value and enable Timer 2 by writing to T2CON
• This is accomplished by forcing current through a coil and producing a magnetic field that spins the
motor.
• Hence by varying the voltage to DC motor we can control the speed of DC motor.
• In PWM, a variation in the duty cycle generates variation in the average DC voltage.
• Pulse Width Modulation (PWM) is one of the methods to provide Digital to Analog Conversion, by
controlling the duty cycle of the square wave provided at the output the average voltage varies and
hence a DC voltage at the output of the filter available is dependent on the pulse width (counter
digital value).
• A RC circuit provides filtering and gives the average DC voltage proportional to the count as shown
fig (a)
• The Fig (b) shows how it can be used to turn on a LED and then to control its intensity by varying
the voltage (inversely proportional) across it.
• The Fig (c) shows how it can be used to turn on a DC motor and then to control its speed by varying
the voltage across it.
• 1Kbytes EEPROM
4. Peripheral features
• One 16-bit Timer/Counter with separate prescaler, compare mode, and capture mode
6. Operating voltage:
7. Temperature range:
8. Speed grade:
• 0 to 8MHz at 2.7 to 5.5V (automotive temperature range: -40°C to +125°C)
• In order to maximize performance and parallelism, the AVR uses a Harvard architecture with
separate memories and buses for program and data.
• While one instruction is being executed, the next instruction is pre-fetched from the program
memory.
• The ALU supports arithmetic and logic operations between registers or between a constant and a
register.
• In a typical ALU operation, two operands are output from the Register file, the operation is
executed and the result is stored back in the Register file in one clock cycle.
• After an arithmetic operation, the Status register is updated to reflect information about the result
of the operation.
• Program flow is provided by conditional and unconditional jump and call instructions, able to
directly address the whole address space.
• Most of the instructions operating on the register file have direct access to all registers and most of
them are single cycle instructions.
• Each register is also assigned a data memory address, mapping them directly into the first 32
locations of the user data space
• Registers R26 through R31 have some added functions to their general purpose usage.
• These registers are 16-bit address pointers for indirect addressing of the data space.
• The three indirect address registers (X, Y, and Z) are defined as described in the figure.
• The status register is an 8-bit register in the microcontroller's I/O memory space.
• It contains 8 flags that are updated based on the results of the previous instruction.
• N : Negative Flag: The Negative Flag, N, indicates a negative result in an arithmetic or logic
operation.
• V : Two's Compliment Overflow Flag: The Two’s Complement Overflow Flag, V, supports two’s
complement arithmetic.
• S : Sign Flag : The S-bit is always an exclusive or between the Negative Flag and the Two’s
Complement Overflow Flag.
• H : Half Carry Flag: It indicates a half carry in some arithmetic operations. It is useful in Binary Code
Decimal (BCD) arithmetic.
• T : Copy Storage: The Bit Copy instructions Bit Load (BLD) and Bit Store (BST) use the T-bit as a
source or destination for the operated bit
• I : Global Interrupt Enable: This bit must be set for the interrupts to be enabled. The individual
interrupt enable control is then performed in separate control registers.
• The stack is mainly used for storing temporary data, local variables, and return addresses after
interrupts and subroutine calls.
• The Stack Pointer register always points to the top of the stack;
• It points to the data SRAM stack area where the subroutine and interrupt stacks are located.
• The AVR Stack Pointer is implemented as two 8-bit registers in the I/O space. The number of bits
actually used depends on the implementation.
• The stack in the data SRAM must be defined by the program before any subroutine calls are
executed or interrupts are enabled.
• The initial Stack Pointer value equals the last address of the internal SRAM and the Stack Pointer
must be set to point above the start of the SRAM.
• The AVR Central Processing Unit (CPU) is driven by the CPU clock clkCPU, directly generated from
the selected clock source for the chip.
• Parallel instruction fetches and instruction executions are enabled by the Harvard architecture and
the fast-access register file concept.
• This is the basic pipelining concept to obtain up to 1 MIPS per MHz with the corresponding unique
results for functions per cost, functions per clocks, and functions per power-unit.
program storage.
• Since all AVR instructions are 16 or 32 bits wide, the Flash is organized as 16K x 16.
• For software security, the Flash Program memory space is divided into two sections, Boot Loader
Section and Application Program section.
• The ATmega328P Program Counter (PC) is 14 bitswide and addresses the 16K program memory
locations.
• The Range of memory address for ATmega328P Flash Memory is 0x0000 – 0x3FFF.
• Data can be accessed through the standard data bus (Load/Store Instructions).
• There is a secondary In/Out Bus for rapid direct access to select locations.
• The ATmega328P is a complex microcontroller with more peripheral units than can be supported
within the 64 locations reserved in the Opcode for the IN and OUT instructions.
• For the Extended I/O space from 0x60 – 0xFF in SRAM, only the ST/STS/STD (Store) and
LD/LDS/LDD (Load) instructions can be used.
• The IN/OUT data bus has direct access to the 64- byte I/O Memory section (not Extended) using a
• This memory can also be accessed by the standard data bus using a 0x20 address offset in the
acces command.
• There are five different data bus addressing modes for the data memory:
2. Indirect – In the Register File, registers R26 to R31 feature the indirect addressing pointer
registers.
3. Indirect with Displacement – The Indirect with Displacement mode reaches 63 address locations
from the base address given by the Y or Z register.
• It is organized as a separate data space, in which single bytes can be read and written.
• The access between the EEPROM and the CPU is performed using the EEPROM Address Registers,
the EEPROM Data Register, and the EEPROM Control Register.
• LCDs (Liquid Crystal Displays) are used for displaying status or parameters in embedded systems.
• LCD 16x2 is a 16-pin device that has 8 data pins (D0-D7) and 3 control pins (RS, RW, EN).
• The remaining 5 pins are for the supply and backlight for the LCD.
• The control pins help us configure the LCD in command mode or data mode.
• They also help configure read mode or write mode & also when to read or write.
• LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on the requirement of the
application.
• In order to use it we need to send certain commands to the LCD in command mode and once the
LCD is configured according to our need, we can send the required data in data mode.
• For every +1 centigrade raise in temperature there will be +10mV higher output.
• So if the temperature is 0◦centigrade the output of sensor will be 0V, if the temperature is 10◦
centigrade the output of sensor will be +100mV, if the temperature is 25◦ centigrade the output of
sensor will be +250mV.
• So for now with LM35 we get temperature in the form of variable voltage.
Converter) of ATMEGA32A.
• I2C : Inner Integrated Circuit RTC : Real Time Clock Features of I2C RTC DS12887