0% found this document useful (0 votes)
28 views37 pages

Unit 2 - Es

Unit II of the EE1672 Embedded Systems course introduces embedded processors, focusing on the PIC 16F877A microcontroller and ARM Cortex processor architecture. It covers the microcontroller's features, pin configuration, memory organization, and serial communication protocols. Additionally, it highlights the programming tools available, such as Micro-C and Keil compilers for embedded C coding.

Uploaded by

Free Fire tamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views37 pages

Unit 2 - Es

Unit II of the EE1672 Embedded Systems course introduces embedded processors, focusing on the PIC 16F877A microcontroller and ARM Cortex processor architecture. It covers the microcontroller's features, pin configuration, memory organization, and serial communication protocols. Additionally, it highlights the programming tools available, such as Micro-C and Keil compilers for embedded C coding.

Uploaded by

Free Fire tamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

UNIT - II INTRODUCTION TO EMBEDDED PROCESSORS


Introduction to PIC 16F877A microcontroller: architecture and pin diagram, Overview of
instruction sets and addressing modes. Introduction to ARM processor: Architecture and pin
diagram of CORTEX processor. Micro-c and Keil compilers for programming using
embedded C coding.

Introduction to PIC16F877
PIC16F877 is one of the advanced and commonly used Peripheral Interface
Microcontroller from Microchip. Simplicity, quality, ease of availability and low price makes
them ideal for different applications. Also, this PIC features all components that modern
microcontrollers have.
Some of the remarkable features of this PIC microcontroller are listed below.

General Features
• 35 instructions are only there.
• Single-cycle instructions are used here. While, two-cycle instructions are used for
program branches.
• 20 MHz clock input – 200 ns instruction cycle is the operating speed.
• 8K x 14 words of Flash Program Memory, Data Memory RAM of 368 x 8 bytes,
EEPROM Data Memory of 256 x 8 bytes.
• Pin out compatible to other 28-pin or 40/44-pin.
• Voltage range of 2 to 5.5 V.
• Low-power, high-speed Flash/EEPROM technology.
• Low-power consumption.
• Static design.
Peripheral Features
• 3 timers are present: Timer0, Timer1, and Timer2.
• Two Compare and Capture PWM modules.
• Synchronous Serial Port (SSP).
• Universal Synchronous Asynchronous Receiver Transmitter with the capability of 9-
bit address detection.
• Parallel Slave Port.
• Brown-out detection circuitry.
Analog Features
• Analog Comparator module present.
• 10-bit, upto 8-channel Analog-to-Digital Converter (A/D).
Other Features
• Selectable oscillator options.
• Data EEPROM Retention > 40 years.
• In-Circuit Debug (ICD) via two pins.
• 100,000 erase/write cycle Enhanced Flash program memory.
• 1,000,000 erase/write cycle Data EEPROM memory.
• Self-reprogrammable.
• In-Circuit Serial Programming via two pins.
• Programmable code protection.
• Power saving Sleep mode.
• Watchdog Timer with RC oscillator.

St. Joseph’s College of Engineering 1 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Peripheral Interface Controller PIC 16F877A


Peripheral Interface Controller (PIC) is a microcontroller from Microchip Technology.
It is a Reduced Instruction Set Computer (RISC) that has been developed to achieve good
performance from the use of a small optimized set of instructions. It comes in many different
packagings that suit several simple and complex applications. It has a total number of 40 pins
and there are 33 pins for input and output.
It consists of two 8 bit and one 16 bit timer. Capture and compare modules, serial ports,
parallel ports and five input/output ports are also present in it.
PIC16F877A is used in many pic microcontroller projects. PIC16F877A also have much
application in digital electronics circuits.

This picture shows the pinout diagram of PIC16F877A.

PIC16F877A Pin Diagram

PIC16F877A Microcontroller Pinout Configuration


Pin Pin Name Description
No.

1 MCLR/Vpp MCLR is used during programming, mostly connected to


programmer like PicKit

2 RA0/AN0 Analog pin 0 or 0th pin of PORT A

3 RA1/AN1 Analog pin 1 or 1st pin of PORT A

4 RA2/AN2/Vref- Analog pin 2 or 2nd pin of PORT A


St. Joseph’s College of Engineering 2 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

5 RA3/AN3/Vref+ Analog pin 3 or 3rd pin of PORT A

6 RA4/T0CKI/C1out 4th pin of PORT A

7 RA5/AN4/SS/C2out Analog pin 4 or 5th pin of PORT A

8 RE0/RD/AN5 Analog pin 5 or 0th pin of PORT E

9 RE1/WR/AN6 Analog pin 6 or 1st pin of PORT E

10 RE2/CS/AN7 7th pin of PORT E

11 Vdd Positive pin of MCU (+5V)

12 Vss Ground pin of MCU

13 OSC1/CLKI External Oscillator/clock input pin

14 OSC2/CLKO External Oscillator/clock output pin

15 RC0/T1OSO/T1CKI 0th pin of PORT C

16 RC1/T1OSI/CCP2 1st pin of PORT C or Timer/PWM pin

17 RC2/CCP1 2nd pin of PORT C or Timer/PWM pin

18 RC3/SCK/SCL 3rd pin of PORT C

19 RD0/PSP0 0th pin of PORT D

20 RD1/PSPI 1st pin of PORT D

21 RD2/PSP2 2nd pin of PORT D

22 RD3/PSP3 3rd pin of PORT D

23 RC4/SDI/SDA 4th pin of PORT C or Serial Data in pin

24 RC5/SDO 5th pin of PORT C or Serial Data Out pin

25 RC6/Tx/CK 6th pin of PORT C or Transmitter pin of Microcontroller

26 RC7/Rx/DT 7th pin of PORT C or Receiver pin of Microcontroller

27 RD4/PSP4 4th pin of PORT D

28 RD5/PSP5 5th pin of PORT D

29 RD6/PSP6 6th pin of PORT D

30 RD7/PSP7 7th pin of PORT D

31 Vss Ground pin of MCU

St. Joseph’s College of Engineering 3 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

32 Vdd Positive pin of MCU (+5V)

33 RB0/INT 0th pin of PORT B or External Interrupt pin

34 RB1 1st pin of PORT B

35 RB2 2nd pin of PORT B

36 RB3/PGM 3rd pin of PORT B or connected to programmer

37 RB4 4th pin of PORT B

38 RB5 5th pin of PORT B

39 RB6/PGC 6th pin of PORT B or connected to programmer

40 RB7/PGD 7th pin of PORT B or connected to programmer

• PIN 1: MCLR: The first pin is the master clear pin of this IC. It resets the microcontroller
and is active low, meaning that it should constantly be given a voltage of 5V and if 0 V are
given then the controller is reset. Resetting the controller will bring it back to the first line of
the program that has been burned into the IC.

A push button and a resistor is connected to the pin. The pin is already being supplied
by constant 5V. When we want to reset the IC we just have to push the button which will bring
the MCLR pin to 0 potential thereby resetting the controller.
• PIN 2: RA0/AN0: PORT A consists of 6 pins, from pin 2 to pin 7, all of these are bidirectional
input/output pins. Pin 2 is the first pin of this port. This pin can also be used as an analog pin
AN0. It is built in analog to digital converter.
• PIN 3: RA1/AN1: This can be the analog input 1.
• PIN 4: RA2/AN2/Vref- : It can also act as the analog input2. Or negative analog reference
voltage can be given to it.
• PIN 5: RA3/AN3/Vref+: It can act as the analog input 3. Or can act as the analog positive
reference voltage.1
• PIN 6: RA4/T0CKI: To timer0 this pin can act as the clock input pin, the type of output is
open drain.
• PIN 7: RA5/SS/AN4: This can be the analog input 4. There is synchronous serial port in the
controller also and this pin can be used as the slave select for that port.
• PIN 8: RE0/RD/AN5: PORT E starts from pin 8 to pin 10 and this is also a bidirectional input
output port. It can be the analog input 5 or for parallel slave port it can act as a ‘read control’
pin which will be active low.
St. Joseph’s College of Engineering 4 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

• PIN 9: RE1/WR/AN6: It can be the analog input 6. And for the parallel slave port it can act
as the ‘write control’ which will be active low.
• PIN 10: RE2/CS/AN7: It can be the analog input 7, or for the parallel slave port it can act as
the ‘control select’ which will also be active low just like read and write control pins.
• PIN 11 and 32: VDD: These two pins are the positive supply for the input/output and logic
pins. Both of them should be connected to 5V.
• PIN 12 and 31: VSS: These pins are the ground reference for input/output and logic pins.
They should be connected to 0 potential.
• PIN 13: OSC1/CLKIN: This is the oscillator input or the external clock input pin.
• PIN 14: OSC2/CLKOUT: This is the oscillator output pin. A crystal resonator is connected
between pin 13 and 14 to provide external clock to the microcontroller. ¼ of the frequency of
OSC1 is outputted by OSC2 in case of RC mode. This indicates the instruction cycle rate.

• PIN 15: RC0/T1OCO/T1CKI: PORT C consists of 8 pins. It is also a bidirectional input


output port. Of them, pin 15 is the first. It can be the clock input of timer 1 or the oscillator
output of timer 2.
• PIN 16: RC1/T1OSI/CCP2: It can be the oscillator input of timer 1 or the capture 2
input/compare 2 output/ PWM 2 output.
• PIN 17: RC2/CCP1: It can be the capture 1 input/ compare 1 output/ PWM 1 output.
• PIN 18: RC3/SCK/SCL: It can be the output for SPI or I2C modes and can be the input/output
for synchronous serial clock.
• PIN 23: RC4/SDI/SDA: It can be the SPI data in pin. Or in I2C mode it can be data
input/output pin.
• PIN 24: RC5/SDO: It can be the data out of SPI in the SPI mode.
• PIN 25: RC6/TX/CK: It can be the synchronous clock or USART Asynchronous transmit
pin.
• PIN 26: RC7/RX/DT: It can be the synchronous data pin or the USART receive pin.
• PIN 19, 20, 21, 22, 27, 28, 29, 30: PORT D/PSP: All of these pins belong to PORT D which
is again a bidirectional input and output port. When the microprocessor bus is to be interfaced,
it can act as the parallel slave port.
• PIN 33-40: PORT B: All these pins belong to PORT B. Out of which RB0 can be used as the
external interrupt pin and RB6 and RB7 can be used as in-circuit debugger pins.

PIC 16F8XX MICROCONTROLLER ARCHITECTURE:


PIC Microcontroller architecture is based on Harvard architecture and supports RISC
architecture (Reduced Instruction Set Computer). PIC microcontroller architecture consists of
memory organization (ram, rom, stack), CPU, timers, counter, ADC, DAC, serial
communication, CCP module and I/O ports. PIC microcontroller also supports the protocols
like CAN, SPI, UART for interfacing with other peripherals.

St. Joseph’s College of Engineering 5 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Block Diagram of PIC 16F8XX

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
St. Joseph’s College of Engineering 6 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Registers (GPR). The lower locations of each bank are reserved for the Special Function
Registers and upper locations are for General Purpose Registers.

Memory Organization

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, and EEADRH).

3. BUS:
BUS is used to transfer and receive the data from one peripheral to another. It is classified
into two types such as data bus and address.
 Data Bus: It is used for only transfer or receive the data.
 Address Bus: Address bus is used to transmit the memory address from the peripherals
to the CPU. I/O pins are used to interface the external peripherals; UART and USART
both are serial communication protocols which are used for interfacing serial devices like
GSM, GPS, Bluetooth, IR etc.

St. Joseph’s College of Engineering 7 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

BUS

4. 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

5. 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.

St. Joseph’s College of Engineering 8 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

6. I/O PORTS:
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 16-bit wide and can be used for both input and output. The status of
TRISA (Tradoc Intelligence Support Activity) 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.

7. 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.

8. TIMERS:
PIC 16F877A has three Timer Modules; Timer0, Timer1 and Timer2. These are registers
whose value increases up to 255 and then starts again from 0. Timers 0 and 1 are 8-bit timers
while Timer2 is a 16-bit timer. We can set when the timer will increment with the help of
Prescaler. It divides the oscillator clock before it will reach logic that increases timer status. For
example, a value of the Prescaler id of 32 will mean that the Timer will increment by one after
32 pulses. The timer increments till it reaches a value of 255 after which it triggers an interrupt
and initializes itself to zero again. This interrupt is called Timer Interrupt.

9. 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.

10. 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

St. Joseph’s College of Engineering 9 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

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.

PIC 16F877AXX MC FAMILY: OVERVIEW OF INSTRUCTION SETS AND


ADDRESSING MODES:
Introduction: Each midrange instruction is a 14-bit word divided into an OPCODE
which specifies the instruction type and one or more operands which further specify the
operation of the instruction.
The instruction set is highly orthogonal and is grouped into three basic categories:
• Byte-Oriented Instruction
 F: File Register (or RAM)
 D: Destination
 D=0: Destination  W
 D=1: Destination  File Register
• Bit-Oriented Instruction
 B: Bit Field
 F: Register File where the Bit is located
• Literal and Control Operation
 K: 8-bit constant
For byte-oriented instructions, 'F' represents a file register designator and 'D' represents
a destination designator. The file register designator specifies which file register is to be used
by the instruction. The destination designator specifies where the result of the operation is to be
placed. If 'D' is zero, the result is placed in the W register. If 'D' is one, the result is placed in
the file register specified in the instruction.
For bit-oriented instructions, 'B' represents a bit field designator which selects the
number of the bit affected by the operation, while 'F' represents the number of the file in which
the bit is located.
For literal and control operations, 'K' represents an eight or eleven bit constant or literal
value.
All instructions are executed in one single instruction cycle, unless a conditional test is
true or the program counter is changed as a result of an instruction. In these cases, the execution
takes two instruction cycles with the second cycle executed as an NOP. One instruction cycle
consists of four oscillator periods. Thus, for an oscillator frequency of 4 MHz, the normal
instruction execution time is 1ms. If a conditional test is true or the program counter is changed
as a result of an instruction, the instruction execution time is 2ms.
Examples:
D=0: Destination  W
D=1: Destination  File Register (Default)

addwf PORTD ; // Add content of PORTD to content of the W and store the result back
into PORTD
addwf PORTD, 0 ; // Add content of PORTD to content of the W and store the result into W

St. Joseph’s College of Engineering 10 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

INSTRUCTION SETS: PIC Microcontroller

INSTRUCTION SETS IN PIC


Instruction sets are the source codes that are written by the programmer for performing
the desired operations in a PIC chip. These codes can be usually written in any of the
programming languages such as C, C++, assembly languages, and so on. The instruction set
commands are pre-determined for each and every function with its own command syntaxes and
are executed by the PIC chip. PIC chips are normally use Reduced Instruction Set Programming
that only contain 35 simple instruction sets that are much easier to learn by the programmer as
compared to CISC instruction set. According to the type of instruction, the instruction sets can
be classified into 5 groups.

The instruction sets in PIC is developed by the basis of RISC structure. The instruction
sets can be classified into 5 separate categories (depends on the basis of type of operation). They
are
 Data Transfer Group
 Arithmetic and Logic Operations Group
 Bit Operation Group Instructions

St. Joseph’s College of Engineering 11 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

 Program Flow Control


 Other Instructions.

DATA TRANSFER GROUP INSTRUCTIONS IN PIC


Data transfer group instructions are one of the major instructions widely used in PIC
programming for data transfer purposes. By using these types of instructions, we can move or
change the value (bits) from one location to another.
Transfer data in a MC is done between W register and F register.

Data Transfer Instructions with Syntaxes


i. MOVLW
MOVLW instruction is used to write constant in W register (move the value from literal to W
register).
 Syntax: Label MOVLW k
 Description: 8 bit constant is written in W reg.
 Operation: k to (W)
 Operand: 0 < k < 255
 No. of words: 1
 No. cycles: 1
 Flags: Nil

ii. MOVWF
MOVWF instruction is used to move the data (bits) from W register to flag register F (copy/move
the value from W register to F register).
 Syntax: Label MOVWF f
 Description: Content of W is copied into f register (flag register).
 Operation: W to (f) (W register to Flag register)
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: Nil

iii. MOVF
MOVF command is used for copy/move the contents (bits) in the flag register to D register (Copy
f to d register).
D register (destination register) is a special register which can be switchable in its destination
according to its status. If the status of D register is ‘0’, the destination is W register and if the
status is ‘1’, the destination of D register became F register (flag)
 Syntax: Label MOVF f, d
 Description: Content of f is copied into destination.
If d = 0, the destination is W register
If d = 1, the destination is f register
St. Joseph’s College of Engineering 12 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

 Operation: F to (D)
 Operand: 0 < k < 127
 No. of words: 1
 No. cycles: 1
 Flags: Z

iv. CLRW
CLRW is a clearing instruction that helps to reset the values of W register to ‘0’ (write ‘0’ in W
register).
 Syntax: Label CLRW
 Description: Zero is copied into W register. Z flag in status register is set to one.
 Operation: 0 to (W)
 Operand: nil
 No. of words: 1
 No. cycles: 1
 Flags: Z

v. CLRF f
CLRF f Write ‘0’ in F register that helps to reset the current status to ‘0’
 Syntax: Label CLRF f
 Description: Zero is copied into f register
Z flag in status register is set to one
 Operation: 0 to (f)
 Operand: nil
 No. of words: 1
 No. cycles: 1
 Flags: Z

vi. SWAPF
SWAPF used for swap (interchanging functions) functions which Swap the nibbles (4bits).The
destination of this function depends on the destination register status.
 Syntax: Label SWAPF f, d
 Description: Upper, Lower nibbles are exchanged
If d = 0, the destination is W register
If d = 1, the destination is f register
 Operation: f (0:3) to d(4:7) and f(4:7) to d(0:3)
 Operand: 0 < f < 127

ARITHMETICAL AND LOGICAL OPERATIONS GROUP INSTRUCTIONS IN PIC


Arithmetic and logic operation group instructions are used for performing all arithmetic
operations and logic operations. By using these types of instructions, the PIC chip can easily
perform all arithmetic and logic operations inside the micro controller (PIC). The arithmetic
operations are addition (ADD), subtraction (SUB), multiplication (MUL), division (DIV) and
logical operations are AND, OR, NOT, XOR, and so on. The basic Arithmetical and Logical
operations that are performed by a PIC is given below.

St. Joseph’s College of Engineering 13 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

i. ADDLW
“ADDLW” instruction is used for performing addition operation (adding a constant with
W register). By using this instruction, we can add two bits easily and the result value can be stored
in another register or memory location.
 Syntax: Label ADDLW k
 Description: Given constant is added with W reg.
 Operation: (w) + k to w
 Operand: 0 < k < 255
 No. of words: 1
 No. cycles: 1
 Flags: C, DC, Z

ii. ADDWF
“ADDWF” is also used for performing the addition operation. This ADDWF instruction
adds the constant with W register.
 Syntax: Label ADDWF f, d
 Description: Add W reg. content with f register
 Operation: (w) + (f) to w if d = 0 and (w) + (f) to f if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: C, DC, Z

iii. SUBLW
“SUBLW” used for performing subtraction function which can be subtracting two values
and can be stored to another memory location. This instruction helps to Subtract W content from
given constant.
 Syntax: Label SUBLW k
 Description: W reg. content is subtracted from k
 Operation: k – (w) to w
 Operand: 0 < k < 255
 No. of words: 1
 No. cycles: 1
 Flags: C, DC, Z

iv. SUBWF
SUBWF is used for performing subtraction operation. In SUBLW, this instruction Subtracts
W content from f register.
St. Joseph’s College of Engineering 14 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

 Syntax: Label SUBWF f


 Description: W reg. content is subtracted from f
 Operation: f – (w) to w if d = 0 and f – (w) to f if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: C, DC, Z

v. ANDLW
ANDLW is a logical instruction which used for performing Logic AND. By using this
instruction helps AND the constant with W.
 Syntax: Label ANDLW k
 Description: Given constant is .and. with W reg.
 Operation: (w) .and. k to w
 Operand: 0 < k < 255
 No. of words: 1
 No. cycles: 1
 Flags: Z

vi. IORLW
This command is used for performing logical OR operation. By using this instruction, it
will perform Logical OR operation with W register.
 Syntax: Label IORLW k
 Description: Given constant is .or. with W reg.
 Operation: (w) .or. k to w
 Operand: 0 < k < 255
 No. of words: 1
 No. cycles: 1
 Flags: Z

vii. IORWF
Logic OR the W reg. with f
 Syntax: Label IORWF f, d
 Description: W reg. is .or. with f reg.
 Operation: (w) .and. f to w, if d = 0 and (w) .and. f to f, if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: Z

viii. XORLW
This command is used for performing logical XOR operation. By using this command, it
will perform logical XOR with Logic constant and W register.
 Syntax: Label XORLW k
 Description: Given constant is .XOR. with W reg.
 Operation: (w) .xor. k to w
 Operand: 0 < k < 255
 No. of words: 1
 No. cycles: 1
 Flags: Z

St. Joseph’s College of Engineering 15 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

ix. XORWF
This command used to perform Logic XOR the W reg. with f
 Syntax: Label XORWF f, d
 Description: W reg. is .xor. with f reg.
 Operation: (w) .and. f to w, if d = 0 and (w) .and. f to f, if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: Z

x. INCF
INCF command used for performing increment operations.(Increment f registers content)
 Syntax: Label INCF f, d
 Description: Increment the content of f register
 Operation: (f) + 1 to w, if d = 0 and (f) + 1 to f, if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: Z

xi. DECF
DECF command used for performing Decrement f register content
 Syntax: Label DECF f, d
 Description: Decrement the content of f register
 Operation: (f) – 1 to w, if d = 0 and (f) – 1 to f, if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: Z

xii. RLF
RLF command is used for performing rotate register content left through Carry
 Syntax: Label RLF f, d
 Description: Rotate f content left through Carry
 Operation: Result to w, if d = 0 and Result to f, if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: C

xiii. RRF
RRF command used for perform Rotate register content right through Carry
 Syntax: Label RRF f, d
 Description: Rotate f content right through Carry
 Operation: Result to w, if d = 0 and Result to f, if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: C

St. Joseph’s College of Engineering 16 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

xiv. COMF
COMF command for perform Complement f registers content
 Syntax: Label COMF f, d
 Description: Complement the register content
 Operation: Result to w, if d = 0 and Result to f, if d = 1
 Operand: 0 < f < 127
 No. of words: 1
 No. cycles: 1
 Flags: Z

BIT OPERATION GROUP INSTRUCTIONS IN PIC

i. BCF
BCF is a resetting command instruction used for performing reset operations for a specified
bit or specified register (simply called bit clearing flag or bit clearing command). Normally BCF
resets the specified bit in f registers content.
 Syntax: Label BCF f, b
 Description: Reset the specified bit of register f
 Operation: Result to f
 Operand: 0 < f < 127 and 0 < b < 7
 No. of words: 1
 No. cycles: 1
 Flags: nil

ii. BSF
BSF is the inversing operation of BCF. This is also a bitwise operation. The BSF instruction
will set the specified bit in the f register (simply called Bit Set Flag or Bit Set command).
 Syntax: Label BSF f, b
 Description: Set the specified bit of register f
 Operation: Result to f
 Operand: 0 < f < 127 and 0 < b < 7
 No. of words: 1
 No. cycles: 1
 Flags: nil

PROGRAM FLOW CONTROL GROUP INSTRUCTIONS IN PIC


i. BTFSC
BTFSC is a special type program flow instruction which control the current program flow.
Normally BTFSC Test the bit in f, skip if it is zero.
 Syntax: Label BTFSC f, b
 Description: Test the specified bit of register f, skip the next instruction if it is zero
 Operation: Skip the next instruction if f (b) = 0
 Operand: 0 < f < 127 and 0 < b < 7
 No. of words: 1
 No. cycles: 1 or 2 depends on bit value
 Flags: NIL

St. Joseph’s College of Engineering 17 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

ii. BTFSS
BTFSS also program flow control instruction. This instruction Test the bit in f, skip if it is
one
 Syntax: Label BTFSS f, b
 Description: Test the specified bit of register f, skip the next instruction if it is one
 Operation: Skip the next instruction if f (b) = 1
 Operand: 0 < f < 127 and 0 < b < 7
 No. of words: 1
 No. cycles: 1 or 2 depends on bit value
 Flags: nil

iii. INCFSZ
INCFSZ is a content increment command which Increment f content, skip if it is zero
 Syntax: Label INCFSZ f, d
 Description: Increment the f content, skip the next instruction if f is zero
 Operation: Skip the next instruction if f = zero
 Operand: (f) + 1 = w if d = 0 and (f) + 1 = f if d = 1
 No. of words: 1
 No. cycles: 1 or 2 depends on bit value
 Flags: nil

iv. DECFSZ
DECFSZ command Decrement f content, skip if it is zero
 Syntax: Label DECFSZ f, d
 Description: Decrement the f content, skip the next instruction if f is zero
 Operation: Skip the next instruction if f = zero
 Operand: (f) – 1 = w if d = 0 and (f) – 1 = f if d = 1
 No. of words: 1
 No. cycles: 1 or 2 depends on bit value
 Flags: nil

v. GOTO
GOTO instruction is used for Jump to specified address locations.
 Syntax: Label GOTO Label
 Description: Unconditional jump to specified label
 Operation: k to PC(10:0), PCLATH(4:3) to PC(12:11)
 Operand: 0 < k < 2048
 No. of words: 1
 No. cycles: 2
 Flags: nil

vi. CALL
CALL command is used for Call the required sub-program or other values.
 Syntax: Label CALL Label
 Description: Unconditional call the label
 Operation: (PC) + 1 to Top of stack, k to PC(10:0), PCLATH(4:3) to PC(12:11)
 Operand: 0 < k < 2048
 No. of words: 1
 No. cycles: 2
 Flags: nil

St. Joseph’s College of Engineering 18 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

vii. RETURN
RETURN command is used for Return to main program from any other sub programs
 Syntax: Label RETURN
 Description: Unconditional return from subroutine
 Operation: Top of stack to (PC)
 Operand: nil
 No. of words: 1
 No. cycles: 2
 Flags: nil

viii. RETLW
RETLW is also a return command. By using this command, Return to main program with
k in w reg.
 Syntax: Label RETLW k
 Description: Unconditional return from subroutine
 Operation: Top of stack to (PC) and k loaded in w register
 Operand: 0 < k < 255
 No. of words: 1
 No. cycles: 2
 Flags: nil

ix. RETFIE
RETFIE used to return from interrupt routine
 Syntax: Label RETFIE
 Description: Unconditional return from subroutine
 Operation: Top of stack to (PC) and Global Interrupt bit is enabled
 Operand: nil
 No. of words: 1
 No. cycles: 2
 Flags: nil

OTHER INSTRUCTIONS IN PIC


i. NOP
NOP command used for denoting No Operation
 Syntax: Label NOP
 Description: No operation
 Operation: nil
 Operand: nil
 No. of words: 1
 No. cycles: 1
 Flags: nil

ii. CLRWDT
CLRWDT command used for Initialize watchdog time feature.
 Syntax: Label CLRWDT
 Description: Watchdog timer and pre-scalar is reset and TO and PD are set
 Operation: 0 to WDT, 0 to pre-scalar and Status bits TO and PD are set
 Operand: TO and PD
 No. of words: 1
 No. cycles: 1
 Flags: nil

St. Joseph’s College of Engineering 19 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

iii. SLEEP
SLEEP command used for initialize Standby mode.
 Syntax: Label SLEEP
 Description: Goes into low consumption, OSC is stopped, Watchdog timer and pre-scalar
is reset and TO and PD bits are set
 Operation: 0 to WDT, 0 to pre-scalar and Status bits, TO is set and PD is reset
 Operand: TO and PD
 No. of words: 1
 No. cycles: 1
 Flags: nil

ADDRESSING MODES OF PIC MICROCONTROLLER


To know the working principal and data handling, we need to have clear knowledge on
addressing modes of pic microcontroller. In PIC microcontroller, it having mainly five addressing
modes. Those are
 1. Immediate addressing mode
 2. Register operand addressing mode
 3. Memory operand addressing mode
 4. Direct addressing
 5. Indirect addressing.

IMMEDIATE ADDRESSING MODE:


In this addressing mode, the operand is a number or constant not an address as MOVLW
43h, the operand here is data not address. So in this addressing mode of pic microcontroller data
is directly transfer. And data is immediate after the opcode. That is why this type of addressing
is called immediate addressing. This way is fast in execution.

REGISTER OPERAND ADDRESSING MODE:


In this addressing mode, the operand is a Register which holds the data to be execute.
Register operand addressing mode deals with the registers like: CLR W.

MEMORY OPERAND ADDRESSING MODE:


In this addressing mode, the operand is an address of Memory location which holds the data
to be execute. Again memory operand addressing mode is under two category
1) Direct addressing like CLRF 13h. We deal with the address or the memory location.
2) Indirect addressing. we use in it INDF and FSR registers.

DIRECT ADDRESSING:
Direct Addressing is done through a 9-bit address. This address is obtained by connecting
7th bit of direct address. By using an instruction with two bits (RP1, RP0) from STATUS register.
This is shown on bellow Figure. Any access to SFR registers can be an example of direct
addressing.

St. Joseph’s College of Engineering 20 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

INDIRECT ADDRESSING:
It does not take an address from an instruction. But it derives from IRP bit of STATUS and
FSR registers. Addressed location is accessed through INDF register. And INDF register in fact
holds the address indicated by the FSR. Indirect addressing is very convenient for manipulating
data arrays located in GPR registers. In this case, it is necessary to initialise FSR register with a
starting address of the array, and the rest of the data can be accessed by increment the FSR
register. Figure shows the indirect addressing concept.

INTRODUCTION TO ARM PROCESSOR


The ARM microcontroller stands for Advanced RISC Machine; it is one of the extensive
and most licensed processor cores in the world. The first ARM processor was developed in the
year 1978 by Cambridge University, and the first ARM RISC processor was produced by the
Acorn Group of Computers in the year 1985. These processors are specifically used in portable
devices like digital cameras, mobile phones, home networking modules and wireless
communication technologies and other embedded systems due to the benefits, such as low power
consumption, reasonable performance, etc.

St. Joseph’s College of Engineering 21 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

PIN CONFIGURATION of LPC2148 Microcontroller


The Pinout and Features of LPC2148 Microcontroller. For developing different
microprocessor based applications, the designer of embedded systems and SOC (system on chip)
are used different processor cores, libraries, and tools. On these processors, libraries, and tools,
the ARM7 is one of the best processors for embedded system designers. It has become so much
popular in the last few years. It is easily available on the local market or online shops. This global
ARM7 processor technology has developed so many microcontrollers such as LPC2144,
LPC2146, and LPC2148, etc. But LPC2148 microcontroller is the most famous microcontroller
which has been currently using in different applications such as in automatic braking systems and
mobile phones etc.

Features of LPC2148 Microcontroller


LPC2148 microcontroller has developed by Philips (NPX semiconductor) company. It has so
many built-in peripherals and features. Therefore it has become so efficient and reliable as
compared to other microcontrollers. It is 16 bit or 32 bit ARM 7 based microcontroller which as
different features.

1. It is 16 or 32 bit ARM 7 family-based microcontrollers and is available in market in small


packages such as LQFP64.
2. Its programming time is 1 millisecond for 256 bytes and 400 millisecond for erasing the
on full chip data.
3. It is used on-chip bootloader software during the ISP (in system programming) and IAP
(in application programming).
4. It has 8 kB to 40 KB on chip static RAM and 32 kB to 512 kB on chip flash memory.
5. It offers the high speed operation at frequency 60 MHz with wide range of interface almost
128 bit.
6. LPC2148 has clock input with 32 K Hz frequency and low power RTC (real time clock).
7. It has embedded ICE RT and embedded trace interface which offers the tracing of
instruction execution with high speed with real time debugging.
8. It offers a changeable output with 10 bit DAC (digital to analog converter).
9. For counting the external events it has two 32 bit timers, watchdog timer and PWM unit.
10. LPC2148 offers the changeable input with 10 bit ADC (analog to digital converter) with
very conversion time such as 2.44μs / channel.
11. The modes, which are used for power conversion are called idle and power down.
12. It has several serial interfaces such as two 12C buses, two 16C550 UARTs with 400 Kbit
speed.
13. It has 1 MHz to 25 MHz on chip incorporated oscillator which works as an exterior crystal.
14. It also has individual enable or disable peripheral function and peripheral SLK scaling for
extra power optimization.
15. Single power supply chip with Power-On Reset (POR) and BOD circuits: CPU operating
voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V tolerant I/O.

LPC2148 Microcontroller Pinout Diagram


LPC2148 microcontroller consists of 64 pins and the group of these pins is called a port.
It consists of two ports and registers. These ports could be used as input or output ports therefore
the pins of these ports are called GPIO (general purposes input-output) pins. LPC2148
microcontroller pin configuration is shown in figure.

GPIO Pins Details


Pin1 (P0.21/PWM5/AD1.6/Cap1.3): It is a general-purpose pin and it could be used for four
multiple ways such as it could be as input output data pin, as a pulse width modulation generator,
as an analog to digital converter and as a capture input for timer l channel 3.
St. Joseph’s College of Engineering 22 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Pin 2 (P0.22/AD1.7/CAP0.0/MAT0.0): It could be for used for four purposes. First one P0.21,
it could be used for input output data pin, second one AD1.7 , it could be used as analog to digital
converter with ADC 1, input 7. Third one CAP0.0, it could be used as a capture input for timer 0
and channel 0. Fourth one MAT 0.0, it could be used as match output for timer 0 and channel 0.
Pin 3 (RTC X1): Pin3 is used as input pin for RTC oscillator circuit.
Pin 4 (P1.19/TRACEPKT3): Pin 4 could be as GPIO pin as well as with 3 bit input output pin
for inner pull up.
Pin 5 (RTCX2): Pin 4 is used as output pin for RTC oscillator circuit.
Pin (6,18,25,42,50): These pins are used as references pins for grounding the microcontroller.
Pin7 (VDDA): This pin is used as voltage source pin with 3.3 Volts. These voltages could be
useful for on chip digital to analog converter and analog to digital converter.
Pin8 (P1.18/TRACEPKT2): This pin is used as GPIO pin and 2 bit input output pin for inner
pull up.
Pin9 (P0.25/AD0.4/AOUT): This pin is used as GPIO pin, as input 4 for AD0 and as output pin
for digital to analog converter.
Pin (10,11): Pin10 is used for D+ line bidirectional USB. Similarly the pin11 is used for D-line
bidirectional USB.

Pin Configuration of LPC 2148 Microcontroller

Pin12 (P1.7/TRACEPKT1): This pin is used as a GPIO pin and as a standard input/output port
for inner pull up.

St. Joseph’s College of Engineering 23 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Pin13 (P0.28/AD0.1/CAP0.2/MAT0.2): This pin is used as a GPIO pin, analog to digital


converter pin for ADC-0 input 1, capture input pin for timer 0 channel 2 and as a match output
pin for timer 2 channel 1.
Pin14 (P0.29/AD0.2/CAP0.3/MAT0.3): This pin could be used as a GPIO pin, converter input
pin for ADC-0 input 2, capature input for timer 0 channel 3 and as a match output pin for timer 0
channel 3.
Pin15 (P0.30/AD0.3/CAP0.3/EINT3/CAP0.0): This pin could be used as GPIO pin, converter
pin for ADC-0 timer input 3, external interrupt with input 3 and as capture input pin for timer 0
channel 0.
Pin16 (P1.16/ TRACEPKT0): This pin could be used as a trace packet pin as well as GPIO pin.
Pin (17,19,20,21): All these pins are used as GPIO pins. Pin17 is used as UP_LED pin, means it
is used as indicator pin. Pin19 is used as a transmitter output for UART0 and as a pulse width
modulator for output 1. Pin20 is used as a reset pin for JATG interface. Similarly the pin21is uses
as receiver input for UART0, as PWM generator for output 3 and as external interrupt with input
0.
Pin (22,24,26,27,28,29,30): These are GPIO pins. Pin 22 is used as clock input output and capture
input pin, pin 24 is used as CLK output during JATG interface. Pin 26 is used as matched output
for timer 0 channel 0 and as external interrupt for input1. Pin 27 is used as a serial clock for
transferring data from master bus to slave bus and as a digital converter ADC-0.6 for input 6. Pin
28 could be used as external trigger input with inner pullup. Pin 29 is used as MISO for
transferring data form mater to slave bus and used as a converter ADC-0 with input 7. Pin 30 is
also used as MISO output and as a capture input for timer 0 channel 2.
Pin (23,43,51): These pins are used for suppling input voltages to internal core and input output
ports.
Pin (31,32,33): These pins are used as GPIO pins. Pin 31 is used as SSEL0, PWM2 and as
external interrupt for input 2. Pin 32 is used as a trace CLK for standard input output port with
inner pull up. Similarly, pin 33 is used as transmitter TXD1 for UART1 and as a pulse width
modulator PWM4.
Pin (34,35,36,37): Pin 34,35,36 and 37 are GPIO pins. Pin 34 could be used as input receiver
such as RDX1 for UART1, as output pulse modulator such as PWM6 for output 6, as an external
interrupt pin for input 3. Pin 35 could be used as a request pin for sending request to UART1, as
a capture input pin for timer 1 channel 1, as an anlage to digital converter ADC-1 for input 1. Pin
36 could be used as a 2-bit pipe line status pin for standard input output port. Pin 37 could be used
as a clear input pin for UART1, as a capture pin for timer 1 channel and as a clear output input
pin for 12C bus observer.
Pin (38,39,40,41): Pin 38,39,40 and 41 could be used as GPIO pin. Pin 38 could be used as an
output data terminal ready pin for UART1, as match output pin for timer 1 channel 0 and as an
analog to digital converter ADC-1 for input1. Pin 39 could be used as an input data terminal ready
pin for UART1, as an output match pin for terminal 1 channel 1 and as a converter ADC-1 for
input 4. Pin 40 could be used a bit-1 pipe line status pin for standard input output port. Pin 41
could be used as input data carrier detector pin for UART1, as an external interrupt pin for input
1 and as an input output open drain pin for 12C bus observer.
Pin (44,45,46,47): These pins are also used as GPIO pin. Pin 44 could be used as a bit-0 pipe line
pin for standard input output port. Pin 45 could be used as an input ring pointer pin for UART1,
as an external interrupt pin for input 2 and as a pulse width modulator generator ADC-1.5 for
input 5. Pin 46 could be used as external interrupt pin for input 0, as a match output pin for timer
0 channel 2 and as a capture input pin for timer 0 channel 2. Pin 47 could be used as capture input
pin for timer 1 channel 2, as a serial CLK pin for sending output from master but to slave bus.
So, the remaining pins of this LPC 2148 microcontroller are work same as explained pins.

St. Joseph’s College of Engineering 24 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

ARM PROCESSOR ARCHITECTURE


The ARM processor architecture is an Advanced Reduced instruction set computing
[RISC] Machine and it’s a 32bit reduced instruction set computer (RISC) microcontroller. It was
introduced by the Acron computer organization in 1987. This ARM is a family of microcontroller
developed by makers like ST Microelectronics, Motorola, and so on. The ARM architecture
comes with totally different versions like ARMv1, ARMv2, etc., and, each one has its own
advantage and disadvantages.

The ARM cortex is a complicated microcontroller within the ARM family that has ARMv7
design. There are 3 subfamilies within the ARM cortex family:
 ARM Cortex Ax-series for high-performance applications
 ARM-Cortex Rx-series for real-time systems
 ARM-Cortex Mx-series for microcontroller applications
The ARM Architecture
 Arithmetic Logic Unit
 Booth multiplier
 Barrel shifter
 Control unit
 Register file

ARM Architecture

The ARM processor conjointly has other components like the Program status register,
which contains the processor flags (Z, S, V and C). The modes bits conjointly exist within the
program standing register, in addition to the interrupt and quick interrupt disable bits; Some
special registers: Some registers are used like the instruction, memory data read and write
registers and memory address register.
Priority encoder: The encoder is used in the multiple load and store instruction to point which
register within the register file to be loaded or kept.
Multiplexers: several multiplexers are accustomed to the management operation of the processor
buses. Because of the restricted project time, we tend to implement these components in a very
behavioral model. Each component is described with an entity. Every entity has its own

St. Joseph’s College of Engineering 25 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

architecture, which can be optimized for certain necessities depending on its application. This
creates the design easier to construct and maintain.

ARM Block Diagram

Arithmetic Logic Unit (ALU)


The ALU has two 32-bits inputs. The primary comes from the register file, whereas the
other comes from the shifter. Status registers flags modified by the ALU outputs. The V-bit output
goes to the V flag as well as the Count goes to the C flag. Whereas the foremost significant bit
really represents the S flag, the ALU output operation is done by NORed to get the Z flag.
The ALU has a 4-bit function bus that permits up to 16 opcode to be implemented.
Booth Multiplier Factor
The multiplier factor has three 32-bit inputs and the inputs return from the register file.
The multiplier output is barely 32-Least Significant Bits of the merchandise. The entity
representation of the multiplier factor is shown in the above block diagram. The multiplication
starts whenever the beginning 04 input goes active. Fin of the output goes high when finishing.
Booth Algorithm
Booth algorithm is a noteworthy multiplication algorithmic rule for 2’s complement
numbers. This treats positive and negative numbers uniformly. Moreover, the runs of 0’s or 1’s
within the multiplier factor are skipped over without any addition or subtraction being performed,
thereby creating possible quicker multiplication. The figure shows the
simulation results for the multiplier test bench. It’s clear that the multiplication finishes only
in16 clock cycle.

St. Joseph’s College of Engineering 26 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Barrel Shifter
The barrel shifter features a 32-bit input to be shifted. This input is coming back from the
register file or it might be immediate data. The shifter has different control inputs coming back
from the instruction register. The Shift field within the instruction controls the operation of the
barrel shifter. This field indicates the kind of shift to be performed (logical left or right,
arithmetic right or rotate right). The quantity by which the register ought to be shifted is contained
in an immediate field within the instruction or it might be the lower 6 bits of a register within the
register file.
The shift_val input bus is 6-bits, permitting up to 32 bit shift. The shift type indicates the
needed shift sort of 00, 01, 10, 11 are corresponding to shift left, shift right, an arithmetic shift
right and rotate right, respectively. The barrel shifter is especially created with multiplexers.
Control Unit
For any microprocessor, control unit is the heart of the whole process and it is responsible
for the system operation, so the control unit design is the most important part within the whole
design. The control unit is sometimes a pure combinational circuit design. Here, the control unit
is implemented by easy state machine. The processor timing is additionally included within the
control unit. Signals from the control unit are connected to each component within the processor
to supervise its operation.

ARM7 Functional Diagram


The final thing that must be explained is how the ARM will be used and the way in which
the chip appear. The various signals that interface with the processor are input, output or
supervisory signals which will be used to control the ARM operation.

ARM Functional Diagram

St. Joseph’s College of Engineering 27 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

ARM Microcontroller Register Modes


An ARM microcontroller is a load store reducing instruction set computer architecture
means the core cannot directly operate with the memory. The data operations must be done by
the registers and the information is stored in the memory by an address. The ARM cortex-M3
consists of 37 register sets wherein 31 are general purpose registers and 6 are status registers. The
ARM uses seven processing modes to run the user task.
 USER Mode
 FIQ Mode
 IRQ Mode
 SVC Mode
 UNDEFINED Mode
 ABORT Mode
 Monitor Mode

ARM Microcontroller Register Modes


USER Mode: The user mode is a normal mode, which has the least number of registers.
It doesn’t have SPSR and has limited access to the CPSR.
FIQ and IRQ: The FIQ and IRQ are the two interrupt caused modes of the CPU. The
FIQ is processing interrupt and IRQ is standard interrupt. The FIQ mode has additional five
banked registers to provide more flexibility and high performance when critical interrupts are
handled.
SVC Mode: The Supervisor mode is the software interrupt mode of the processor to start
up or reset.
Undefined Mode: The Undefined mode traps when illegal instructions are executed. The
ARM core consists of 32-bit data bus and faster data flow.
THUMB Mode: In THUMB mode 32-bit data is divided into 16-bits and increases the
processing speed.
THUMB-2 Mode: In THUMB-2 mode the instructions can be either 16-bit or 32-bit and
it increases the performance of the ARM cortex –M3 microcontroller. The ARM cortex-m3
microcontroller uses only THUMB-2 instructions.
Some of the registers are reserved in each mode for the specific use of the core. The reserved
registers are
 Stack Pointer (SP).
 Link Register (LR).
 Program Counter (PC).
 Current Program Status Register (CPSR).
 Saved Program Status Register (SPSR).
The reserved registers are used for specific functions. The SPSR and CPSR contain the status
control bits which are used to store the temporary data. The SPSR and CPSR register have some
properties that are defined operating modes, Interrupt enable or disable flags and ALU status flag.
St. Joseph’s College of Engineering 28 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

The ARM core operates in two states 32-bit state or THUMBS state.
ARM-Cortex Microcontroller Programming

The 32-bit microcontrollers based on ARM cortex-m3 architecture. Many embedded


system developers are starting to use these 32-bit microcontrollers for their projects. The ARM
microcontrollers supports for both low-level and high level programming languages. Some of
the traditional microcontroller architectures are made with many limitations therefore, difficult to
use the high level programming language.

ARM-Cortex Microcontroller Programming


For example the memory size is limited and performance might not be sufficient. The
ARM microcontrollers runs at 100Mhz frequency and higher performance, therefore it supports
the higher level languages. The ARM microcontroller is programmed with different IDES such
as keiluvision3, keiluvision4, coocox and so on. A 8-bit microcontroller use 8-bit instructions and
the ARM cortex-M uses a 32-instructions.

Additional Uses of the Cortex Processor


It is a reduced instruction set computing Controller
 32-bit high performance central processing unit
 3-stage pipeline and compact one
It has THUMB-2 technology
 Merges optimally with 16/32 bit instructions
 High performance
It supports tools and RTOS and its core Sight debug and trace
 JTAG or 2-pin serial wire debugs connection
 Support for multiple processors
Low power Modes
 It supports sleep modes
 Control the software package
 Multiple power domains
Nested vectored interrupt controller (NVIC)
 Low latency, low noise interrupts response
 No need for assembly programming

St. Joseph’s College of Engineering 29 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

ARM INSTRUCTION SET


ARM instructions are all 32-bit long (except for Thumb mode). There are 232 possible
machine instructions.

The ARM instruction set formats are shown below.

ARM Instruction features:


• Load/Store architecture.
• 3-address instructions.
• Conditional execution of every instruction.
• Possible to load/store multiple registers at once.
• Possible to combine shift and ALU operations in a single instruction.

Instruction Set
• Data processing
• Data transfer
• Flow control
The Condition Field
In ARM state, all instructions are conditionally executed according to the state of the
CPSR condition codes and the instruction’s condition field. This field (bits 31:28) determines the
circumstances under which an instruction is to be executed. If the state of the C, N, Z and V flags
fulfils the conditions encoded by the field, the instruction is executed, otherwise it is ignored.
There are sixteen possible conditions, each represented by a two-character suffix that can
be appended to the instruction’s mnemonic. For example, a Branch (B in assembly language)
becomes BEQ for "Branch if Equal", which means the Branch will only be taken if the Z flag is
set.
St. Joseph’s College of Engineering 30 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Condition Code Summary

DATA PROCESSING
The data processing instruction is only executed if the condition is true. The instruction
produces a result by performing a specified arithmetic or logical operation on one or two
operands. The first operand is always a register (Rn). The second operand may be a shifted
register (Rm) or a rotated 8 bit immediate value (Imm) according to the value of the I bit in the
instruction. The condition codes in the CPSR (Current Program Status Registers) may be
preserved or updated as a result of this instruction, according to the value of the S bit in the
instruction.
They are move, arithmetic, logical, comparison
and multiply instructions.
• Most data processing instructions can process one of
their operands using the barrel shifter.
• General rules:
– All operands are 32-bit, coming from registers or
literals.
– The result, if any, is 32-bit and placed in a register
(with the exception for long multiply which produces a
64-bit result).
– 3-address format.

St. Joseph’s College of Engineering 31 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Encoding data processing instructions


Simple Register Operands
 Arithmetic Operations
ADD r0, r1, r2 ;r0:=r1+r2
ADC r0, r1, r2 ;r0:=r1+r2+C
SUB r0, r1, r2 ;r0:=r1–r2
SBC r0, r1, r2 ;r0:=r1–r2+C–1
RSB r0, r1, r2 ;r0:=r2–r1, reverse subtraction
RSC r0, r1, r2 ;r0:=r2–r1+C–1
– By default data processing operations do no affect the condition flags.
 Bit-wise Logical Operations
AND r0, r1, r2 ;r0:=r1ANDr2
ORR r0, r1, r2 ;r0:=r1ORr2
EOR r0, r1, r2 ;r0:=r1XORr2
BIC r0, r1, r2 ;r0:=r1AND(NOT r2), bit clear
 Comparison Operations
– Not produce result; omit the destination from the format
– Just set the condition code bits (N, Z, C and V) in CPSR
CMP r1, r2 ;set cc on r1 - r2, compare
CMN r1, r2 ;set cc on r1 + r2, compare negated
TST r1, r2 ;set cc on r1 AND r2, bit test
TEQ r1, r2 ;set cc on r1 XOR r2, test equal
 Register Movement Operations
– Omit 1st source operand from the format
MOV r0, r2 ;r0:=r2
MVN r0, r2 ;r0:=NOT r2, move 1’s complement

St. Joseph’s College of Engineering 32 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

DATA TRANSFER
The instruction is only executed if the condition is true. Block data transfer instructions
are used to load (LDM) or store (STM) any subset of the currently visible registers. They support
all possible stacking modes, maintaining full or empty stacks which can grow up or down
memory, and are very efficient instructions for saving or restoring context, or for moving large
blocks of data around main memory.
 Three basic forms to move data between ARM registers and memory.
– Single register load and store instruction
• A byte, a 16-bit half word, a 32-bit word
– Multiple register load and store instruction
• To save or restore workspace registers for procedure entry and exit
• To copy blocks of data
– Single register swap instruction
• A value in a register to be exchanged with a value in memory
• To implement semaphores to ensure mutual exclusion on accesses

Single Register Data Transfer


 Word transfer
– LDR (load) / STR (store)
 Byte transfer
– LDRB / STRB
 Halfword transfer
– LDRH / STRH
 Load single byte or halfword-load value and sign extended to 32 bits
– LDRSB / LDRSH
 All of these can be conditionally executed by insert-ing the appropriate condition code
after STR/LDR
– LDREQB

ARM INSTRUCTION SET SUMMARY

St. Joseph’s College of Engineering 33 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

St. Joseph’s College of Engineering 34 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Setting up an embedded development environment using the Micro-C compiler and Keil
IDE:
Setting up an embedded development environment using the Micro-C compiler and Keil
IDE involves several steps, including the installation of necessary software components and
configurations. Below is a general guide to help you set up the development environment:

1. Install Keil IDE:


 Download the Keil MDK (Microcontroller Development Kit) from the official Keil website.
 Run the installer and follow the on-screen instructions.
 During installation, you can choose the components you want to install, including the Keil
µVision IDE, debugger, and other tools.
2. Install Micro-C Compiler:
 Keil MDK typically comes with the ARM Compiler integrated, so a separate installation of
the Micro-C compiler might not be necessary.
 Verify the installed toolchain versions in Keil to ensure compatibility with your target
microcontroller.
3. Configure Keil µVision:
 Open Keil µVision IDE.
 Configure the IDE settings:
 Select the target microcontroller device: Project -> Manage -> Device.
 Configure target options like the oscillator frequency, memory model, etc.: Project ->
Options for Target.
 Set up the debug interface: Debug -> Settings.
 Specify the output directory and file names: Project -> Options for Target -> Output.
4. Create a New Project:
 Create a new project: Project -> New µVision Project.
 Choose a project name and location.
 Select your microcontroller device from the list.
5. Configure Project Settings:
 Configure the project settings:
 Set up C/C++ compiler options: Project -> Options for Target -> C/C++.
 Specify include paths, defines, and other compiler options.
 Configure linker options: Project -> Options for Target -> Linker.
 Specify memory regions, stack/heap sizes, etc.
6. Write and Import Code:
 Write your embedded C code or import existing source files into the project.
 Add source files to the project: Project -> Add Files to Project.
7. Build the Project:
 Build the project: Project -> Build Target or use the toolbar icon.
 Check the build output window for any errors or warnings.
8. Debugging:
 Configure and start the debugger:
 Set breakpoints, watch variables, and configure other debugging options.
 Debug -> Start/Stop Debug Session.
9. Flash Programming:
 If you have a target board with a debugger or flash programmer, configure flash programming
settings.
 Program the microcontroller: Flash -> Download.
10. Verify and Debug:
 Verify the code execution on the target hardware.
 Use the debugging features to inspect variables, step through code, and diagnose issues.

St. Joseph’s College of Engineering 35 Department of EIE


EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

Additional Tips:
 Ensure that you have the appropriate device support pack installed for your microcontroller.
Keil provides these packs for various microcontroller families, and you can download and
install them through the Pack Installer.
 Refer to the specific documentation for your microcontroller and Keil version for any
platform-specific considerations or configurations.

Common Issues and Troubleshooting:


 Compiler/Toolchain Issues:
 Ensure the Micro-C compiler and Keil MDK versions are compatible.
 Check for updates and patches on the Keil website.
 Target Hardware Connection:
 Ensure that your target hardware is properly connected to the debugger.
 Check the device and connection settings in Keil.
 Memory Configuration:
 Verify that the memory regions and sizes are correctly configured in the project settings.
 Include Paths and Libraries:
 Confirm that the necessary include paths and libraries are specified in the project settings.
 Startup Code and System Initialization:
 Check the correctness of the startup code and system initialization in your project.

Embedded C applications using Micro-C and Keil compilers:


Developing and deploying embedded C applications using Micro-C and Keil compilers
involves a series of steps, from writing code to flashing the program onto the target
microcontroller. Below is a typical workflow for embedded C application development with
Micro-C and Keil compilers:
1. Project Setup:
• Create a new project in Keil µVision IDE.
• Select the target microcontroller device for your project.
• Configure project settings, including memory model, stack size, and peripheral
configurations.
2. Write Embedded C Code:
• Write the embedded C code for your application using the Keil µVision IDE.
• Organize code into source files, and include any necessary libraries.
• Implement initialization routines for peripherals, system clocks, and other hardware-
specific configurations.
3. Configure Compiler Options:
• Set compiler options in Keil µVision for your project:
• Specify include paths for header files.
• Define preprocessor macros and constants.
• Configure compiler optimization levels.
4. Build the Project:
• Build the project to compile the source code into machine code:
• Click on Project -> Build Target or use the toolbar icon.
• Check the build output window for any errors or warnings.
5. Debugging and Testing:
• Configure the debugger settings:
• Set up breakpoints and watchpoints.
• Configure variable and memory views.
• Start a debug session to test and debug your application:
• Click on Debug -> Start/Stop Debug Session.
St. Joseph’s College of Engineering 36 Department of EIE
EE1672 Embedded Systems (Integrated Lab) Unit II – Introduction to Embedded Processors

• Use debugging features like stepping through code, inspecting variables, and monitoring
peripherals.
6. Flash Programming:
• Configure flash programming settings to specify the programming algorithm and
memory regions.
• Connect the debugger to the target hardware.
• Program the microcontroller with the compiled code:
• Click on Flash -> Download or use the appropriate programming command.
7. Verify Operation on Hardware:
• Power up the target hardware with the flashed code.
• Verify the correct execution of the application on the hardware.
• Use debugging features to troubleshoot and fix any issues encountered during runtime.
8. Optimization and Refinement:
• Fine-tune your code for performance and efficiency.
• Optimize critical sections of code.
• Refactor and improve code structure and readability.
9. Documentation:
• Document your code, including comments and explanations of key functions.
• Create a README file detailing the project, hardware setup, and any specific
instructions for other developers or users.
10. Version Control:
• Use a version control system (e.g., Git) to track changes in your project.
• Commit code changes with meaningful messages.
11. Release and Deployment:
• Package your embedded C application for deployment:
• Ensure that all necessary files (binary, configuration files, etc.) are ready.
• Create a release build if necessary, ensuring that optimizations are applied.
12. Testing in Different Environments:
• If applicable, test your embedded C application on various hardware configurations or
environments.
• Ensure compatibility with different microcontroller models and configurations.
13. Documentation and User Guides:
• Provide comprehensive documentation for your embedded C application.
• Include user guides, installation instructions, and troubleshooting tips.
14. Maintenance and Updates:
• Monitor your project for bug reports and user feedback.
• Address issues and release updates as needed.
15. Collaboration and Teamwork:
• If working in a team, collaborate through version control and communicate effectively.
• Share knowledge and best practices among team members.

Note: The specifics of the workflow may vary based on the project requirements, the
microcontroller architecture, and the features provided by the Keil µVision IDE.

St. Joseph’s College of Engineering 37 Department of EIE

You might also like