Saksham - ES Lab File

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Embedded systems Lab File

Department of Electronics
&
Communication Engineering

Submitted to: Submitted By:


Mr. Vikram Kardam Saksham Singh
(Assistant Professor) 01113302818
(Dept. ECE, HMRITM) ECE-7A

*1*
Experiment -1
Aim: Introduction to PIC Microcontroller, 8051 Microcontroller and ARM 7 processor.

Theory:

PIC Microcontroller:

PIC (Programmable Interface Controllers) microcontrollers are the world’s smallest microcontrollers that
can be programmed to carry out a huge range of tasks. These microcontrollers are found in many electronic
devices such as phones, computer control systems, alarm systems, embedded systems, etc. Various types of
microcontrollers exist, even though the best are found in the GENIE range of programmable
microcontrollers. These microcontrollers are programmed and simulated by a circuit-wizard software.

Fig: Block diagram of 16f877A PIC microcontroller

The PIC microcontroller architecture comprises of CPU, I/O ports, memory organization, A/D converter,
timers/counters, interrupts, serial communication, oscillator and CCP module.

CPU (Central Processing Unit):

It is not different from other microcontrollers CPU and the PIC microcontroller CPU consists of the ALU,
CU, MU and accumulator, etc. Arithmetic logic unit is mainly used for arithmetic operations and to take
logical decisions. Memory is used for storing the instructions after processing. To control the internal and
external peripherals, control unit is used which are connected to the CPU and the accumulator is used for
storing the results and further process.

Memory Organization:

The memory module in the PIC microcontroller architecture consists of RAM (Random Access Memory),
ROM (Read Only Memory) and STACK.

*2*
Random Access Memory (RAM):

RAM is an unstable memory which is used to store the data temporarily in its registers. The RAM memory
is classified into two banks, and each bank consists of so many registers. The RAM registers are classified
into two types: Special Function Registers (SFR) and General Purpose Registers (GPR).

General Purpose Registers (GPR):

These registers are used for general purpose only as the name implies. For example, if we want to multiply
two numbers by using the PIC microcontroller. Generally, we use registers for multiplying and storing the
numbers in other registers. So these registers don’t have any special function,- CPU can easily access the
data in the registers.

Special Function Registers:

These registers are used for special purposes only as the name SFR implies. These registers will perform
according to the functions assigned to them , and they cannot be used as normal registers. For example, if
you cannot use the STATUS register for storing the data, these registers are used for showing the operation
or status of the program. So, user cannot change the function of the SFR; the function is given by the retailer
at the time of manufacturing.

Read Only Memory (ROM):

Read only memory is a stable memory which is used to store the data permanently. In PIC microcontroller
architecture, the architecture ROM stores the instructions or program, according to the program
the microcontroller acts. The ROM is also called as program memory, wherein the user will write the
program for microcontroller and saves it permanently, and finally the program is executed by the CPU. The
microcontrollers performance depends on the instruction, which is executed by the CPU.

Electrically Erasable Programmable Read Only Memory (EEPROM):

In the normal ROM, we can write the program for only once we cannot use again the microcontroller for
multiple times. But, in the EEPROM, we can program the ROM multiple times.

Flash Memory:

Flash memory is also programmable read only memory (PROM) in which we can read, write and erase the
program thousands of times. Generally, the PIC microcontroller uses this type of ROM.

Stack:

When an interrupt occurs, first the PIC microcontroller has to execute the interrupt and the existing process
address. Then that is being executed is stored in the stack. After completing the execution of the interrupt,
the microcontroller calls the process with the help of address, which is stored in the stack and get executes
the process.

I/O Ports:

• The series of PIC16 consists of five ports such as Port A, Port B, Port C, Port D & Port E.
• Port A is an 16-bit port that can be used as input or output port based on the status of the TRISA
(Tradoc Intelligence Support Activity) register.
• Port B is an 8- bit port that can be used as both input and output port.
• Port C is an 8-bit and the input of output operation is decided by the status of the TRISC register.

*3*
• Port D is an 8-bit port acts as a slave port for connection to the microprocessor BUS.
• Port E is a 3-bit port which serves the additional function of the control signals to the analog to
digital converter.

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.

A/D converters:

The main intention of this analog to digital converter is to convert analog voltage values to digital voltage
values. A/D module of PIC microcontroller consists of 5 inputs for 28 pin devices and 8 inputs for 40 pin
devices. The operation of the analog to digital converter is controlled by ADCON0 and ADCON1 special
registers. The upper bits of the converter are stored in register ADRESH and lower bits of the converter are
stored in register ADRESL. For this operation, it requires 5V of an analog reference voltage.

Timers/ Counters:

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.

Interrupts:

PIC microcontroller consists of 20 internal interrupts and three external interrupt sources which are
associated with different peripherals like ADC, USART, Timers, and so on.

Serial Communication:

Serial communication is the method of transferring data one bit at a time sequentially over a communication
channel.

• USART: The name USART stands for Universal synchronous and Asynchronous Receiver and
Transmitter which is a serial communication for two protocols. It is used for transmitting and
receiving the data bit by bit over a single wire with respect to clock pulses. The PIC microcontroller
has two pins TXD and RXD. These pins are used for transmitting and receiving the data serially.

• SPI Protocol: The term SPI stands for Serial Peripheral Interface. This protocol is used to send data
between PIC microcontroller and other peripherals such as SD cards, sensors and shift registers.
PIC microcontroller support three wire SPI communications between two devices on a common
clock source. The data rate of SPI protocol is more than that of the USART.

• I2C Protocol: The term I2C stands for Inter Integrated Circuit , and it is a serial protocol which is
used to connect low speed devices such as EEPROMS, microcontrollers, A/D converters, etc. PI.

*4*
Oscillators:

Oscillators are used for timing generation. Pic microcontroller consist of external oscillators like RC
oscillators or crystal oscillators. Where the crystal oscillator is connected between the two oscillator pins.
The value of the capacitor is connected to every pin that decides the mode of the operation of the oscillator.
The modes are crystal mode, high-speed mode and the low-power mode. In case of RC oscillators, the value
of the resistor & capacitor determine the clock frequency and the range of clock frequency is 30KHz to
4MHz.

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.

• Capture Mode: Capture mode captures the time of arrival of a signal, or in other words, when the
CCP pin goes high, it captures the value of the Timer1.

• Compare Mode: Compare mode acts as an analog comparator. When the timer1 value reaches a
certain reference value, then it generates an output.

• PWM Mode: PWM mode provides pulse width modulated output with a 10-bit resolution and
programmable duty cycle.

The ARM Architecture:

• Arithmetic Logic Unit


• Booth multiplier
• Barrel shifter
• Control
• Register

Fig: Block diagram of ARM 7processor

*5*
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 architecture, which can be
optimized for certain necessities depending on its application. This creates the design easier to construct
and maintain.

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 NOR ed to get the Z flag. The ALU has a 4-bit function bus that
permits up to 16 opcode to be implemented

ADDRESS REGISTER

Address Register (MAR) is CPU register that either stores the memory address from which data will be
fetched to the CPU or the address to which data will be sent and stored.

Booth Multiplier

The multiplier factor has 3 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

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

*6*
8051 Microcontroller:

The Intel 8051 is a very popular general purpose microcontroller widely used for small scale embedded
systems. Many vendors such as Atmel, Philips, and Texas Instruments produce MCS-51 family
microcontroller chips. The 8051 is an 8-bit microcontroller with 8 bit databus and 16-bit address bus. The
16 bit address buscan address a 64K( 216) byte code memory space anda separate 64K byte of data
memory space. The 8051has 4K on-chip read only code memory and 128bytes of internal Random Access
Memory (RAM).

Fig: Block Diagram of 8051 microcontroller


The CPU has many important registers. The Program Count(PC) always holds the code memory location
of next instruction. The CPU is the heart of any computer which is in charge of computer operations. It
fetches instructions from the code memory into the instruction Register (IR), analyzes the op code of the
instruction, updates the PC to the location of next instruction,fetch the operand from the data memory if
necessary, and finally performs the operation in the Arithmetic-Logic Unit(ALU) within the CPU.

System Clock and Oscillator Circuits:

The 8051 requires an external oscillator circuit. The oscillator circuit usually runs around 12MHz. the
crystal generates 12M pulses in one second. The pulse is used to synchronize the system operation in a
controlled pace.

Memory:
The 8051 code (program) memory is read-only, while the data memory is read/write accessible. The
program memory ( in EPROM) can be rewritten by the special programmer circuit. The 8051 memory is
organized in a Harvard Architecture. The advantage of the Harvard Architecture is not only doubling the

*7*
memory capacity of the microcontroller with same number of address lines but also increases the reliability
of the microcontroller, since there are no instructions to write to the code memory which is read only.

Special Function Registers (SFRs):

The second 128 bytes are used to store Special Function Registers (SFR) that C51 program can configure
and control the ports, timer, interrupts, serial communication, and other tasks. The SFR is the upper area of
addressable memory, from address 0x80 to 0xFF. This area consists of a series of memory-mapped ports
and registers. All port input and output can therefore be performed by get
and set operations on SFR port name such as P3.

Ports:

There are 4 8-bit ports: P0, P1, P2 and P3. All of them aredual purpose ports except P1 which is only used
for I/O.
• The port P1 is a port dedicated for general I/O purpose.
• P0 acts as A0-A7 in address bus and D0-D7 for port data. It can be used for general purpose I/O if no
external memory presents.
•the port P2 can also play a role (A8-A15) in the address bus in conjunction with PORT P0 to access
external memory.
•Port 3 in addition to acting as a normal I/O port, P3.0 can be used for serial receive input pin(RXD) P3.1
can be used for serial transmit output pin (TXD) in a serial port, P3.2 and P3.3 can be used as external
interrupt pins (INT0’ and INT1’), P3.4 and P3.5 are used for external counter input pins (T0 and T1), P3.6
and P3.7 can be used as external data memory write and read control signal pins(WR’ and RD’)read and
write pins for memory access.

*8*
Experiment -2
Aim: To interface the seven-segment display with microcontroller 8051.

Software used : Keil , ISIS PROTEUS

Theory:
Seven segment displays are used to indicate numerical information. Seven segments display can display
digits from 0 to 9 and even we can display few characters like A, b, C, H, E, e, F, etc. These are very
popular and have many more applications.

Circuit Principle:

Seven segment displays internally consist of 8 LEDs. In these LEDs, 7 LEDs are used to indicate the digits
0 to 9 and single LED is used for indicating decimal point. Generally seven segments are two types, one is
common cathode and the other is common anode. In common cathode, all the cathodes of LEDs are tied
together and labeled as com. and the anode are left alone. In common anode, seven segment display all the
anodes are tied together and cathodes are left freely. Below figure shows the internal connections of seven
segment Display.

Circuit Diagram:

Circuit Components:

• AT89C51 microcontroller
• AT89C51 programming board
• programming cable
• 12V DC battery or adaptor
• Common cathode 7 segment Display

*9*
• Resistors – 10k, 330 ohm
• 2 Ceramic capacitors – 33pF
• 12 MHz crystal
• Electrolytic capacitor – 10uF
• Connecting wires.

Circuit Design:

Here, common cathode seven segment is used to display the digits. In this circuit, pins a to h of the 7
segment are connected to the PORT 2 of the microcontroller and com pin is connected to the ground
through the 330 ohm resistor. This resistor is used to drop the voltage. Since we are using common cathode
seven segment we need to send LOGIC 1 to the segments to glow. Figure shows structure of common
cathode seven segments. Here dot is used for indicating the decimal point. Here all the cathodes of LED’s
are connected to the Gnd pin. The operating voltage of this LED’s is 2 to 3V but from controller we will
get 5V so to drop the remaining voltage we have to connect a to g pins to the controller through the
resistor.

Fig: Common cathode 7 segment Display

Digit Drive Pattern:

To display the digits on 7 segment, we need to glow different logic combinations of segments. For
example if you want to display the digit 3 on seven segment then you need to glow the segments a, b, c, d
and g. The below table show you the Hex decimal values what we need to send from PORT2 to Display
the digits from 0 to 9.

*10*
DIGITS H G F E D C B A VALUE

0 0 0 1 1 1 1 1 1 3F

1 0 0 0 0 0 1 1 0 0B

2 0 1 0 1 1 0 1 1 5B

3 0 1 0 0 1 1 1 1 4F

4 0 1 1 0 0 1 1 0 66

5 0 1 1 0 1 1 0 1 6C

6 0 1 1 1 1 1 0 1 70

7 0 0 0 0 0 1 1 1 07

8 0 0 1 1 1 1 1 1 7F

9 0 1 1 0 0 1 0 1 F7

Program:

#include<reg51.h>

void cct_init(void);
void delay(int);
void DisplayOn7Segment(char);

int main(void)
{
char ch = '0'; // Character to be displayed on 7seg

cct_init(); // Make all ports zero

while(1)
{
DisplayOn7Segment(ch); // Display ch on 7seg
delay(30000); // About 1 sec delay

switch(ch) // Update ch with new value to be displayed


{
case '0': ch = '1'; break;
case '1': ch = '2'; break;
case '2': ch = '3'; break;
case '3': ch = '4'; break;
case '4': ch = '5'; break;
case '5': ch = '6'; break;
case '6': ch = '7'; break;
case '7': ch = '8'; break;

*11*
case '8': ch = '9'; break;
case '9': ch = '0'; break;
default: ch = '0'; break;
}
}
}
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}

void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}

void DisplayOn7Segment(char ch) // ch can have a value from '0' to 'F' only
{
switch(ch)
{
case '0': P2 = 0x3F; break;
case '1': P2 = 0x06; break;
case '2': P2 = 0x5B; break;
case '3': P2 = 0x4F; break;
case '4': P2 = 0x66; break;
case '5': P2 = 0x6D; break;
case '6': P2 = 0x7D; break;
case '7': P2 = 0x07; break;
case '8': P2 = 0x7F; break;
case '9': P2 = 0x6F; break;

default: P2 = 0x3F; break;


}}

Circuit Applications:

• Seven segments are widely used in digital clocks to display the time.
• These are used in electronic meters for displaying the numerical information.
• Used in Instrument panels
• Used in digital readout displays.

Limitations of the Circuit:

• The complexity is increased to display large information.


• It is not possible to display the symbols on seven segment

*12*
Program Code overview:

*13*
Result:

Interfacing of the seven segment display with microcontroller 8051 is done successfully.

*14*
Experiment -3
Aim: To create a series of moving lights using PIC on LEDs.

Software used : Keil , ISIS PROTEUS

Theory:
The PIC microcontroller is a family of microcontrollers manufactured by the microchip technology.
Peripheral interface controller belongs to a class of 8 bit microcontrollers of RISC architecture.
Though the family consists of large number of devices, all the devices have the same basic structure, offering
the following fundamental features.
1. Reduced instruction set (RISC) with only 35 instructions.
2. RAM data memory.
3. Bidirectional digital I/O ports
4. On-chip timer with pre-scalar.
5. Watchdog timer
6. Power on reset
7. External crystal operation
8. Power saving sleep mode

It has 8-bit ALU and 8-bit work registers. There are two registers GPR( general purpose registers) and
SFR( special function registers). ALU controls the status bits of STATUS registers.
It has two separate memory blocks, one for data and other for program.

*15*
Code:
#include “als.16f877A.in”

Int 16, i=a;

Void main()

TRIS A = 0X00;

TRIS B = 0X00;

TRIS C = 0X00;

TRIS D = 0X00;

TRIS E = 0X00;

PORT A = 0X00;

PORT B = 0X00;

PORT C = 0X00;

PORT D = 0X00;

PORT E = 0X00;

While(1)

RA1= RA2 = RA3 = RB3 = RC1 = RD1 =RE1 = 1;

For ( i=0; i < 1000; i++)

RA1 = RA2 = RA3 = RB3 = RC1 = RD1 =RE1 =0;

for ( i=0; I < 1000; i++)

Code Overview:

*16*
RESULT: The series of moving light has been created.

*17*
EXPERIMENT-04
Aim: To interface the stepper motor with microcontroller .

Software used : Keil , ISIS PROTEUS

Theory:
A stepper motor is a brushless and synchronous motor which divides the complete rotation into number of
steps. Each stepper motor will have some fixed step angle and motor rotates at this angle.
Stepper Motor Control using Microcontroller Circuit Principle:

The main principle of this circuit is to rotate the stepper motor step wise at a particular step angle. The
ULN2003 IC is used to drive the stepper motor as the controller cannot provide current required by the
motor. Unipolar stepper motors can be used in three modes namely the Wave Drive, Full Drive and Half
Drive mode. Each drive have its own advantages and disadvantages, thus we should choose the required
drive according to the application and power consumption.
Wave Drive:
In this mode only one electromagnet is energized at a time. Generated torque will be less when compared
to full drive in which two electromagnets are energized at a time but power consumption is reduced. It has
same number of steps as in the full drive. This drive is preferred when power consumption is more
important than torque. It is rarely used.

Full Drive:

In this mode two electromagnets are energized at a time, so the torque generated will be larger when
compared to Wave Drive. This drive is commonly used than others. Power consumption will be higher
than other modes.

*18*
Half Drive:

In this mode alternatively one and two electromagnets are energized, so it is a combination of Wave and
Full drives. This mode is commonly used to increase the angular resolution of the motor but the torque will
be less, about 70% at its half step position. We can see that the angular resolution doubles when using Half
Drive.

Circuit Diagram:

Circuit Components:

• AT89C51 micro controller


• ULN2003A
• Stepper Motor
• Crystal
• Resistor
• Capacitor

*19*
Program:

1. For Wave Drive

#include<reg52.h>
#include<stdio.h>

void delay(int);

void main()
{
do
{
P2=0x01; //0001
delay(1000);
P2=0x02; //0010
delay(1000);
P2=0x04; //0100
delay(1000);
P2=0x08; //1000
delay(1000);
}
while(1);
}

void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{}
}
}

2. For Full Drive

#include<reg52.h>
#include<stdio.h>

void delay(int);

void main()
{
do
{
P2 = 0x03; //0011
delay(1000);
P2 = 0x06; //0110
delay(1000);
P2 = 0x0C; //1100
delay(1000);
P2 = 0x09; //1001
delay(1000);
}

*20*
while(1);
}

void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{}
}
}

3. For half drive

#include<reg52.h>
#include<stdio.h>

void delay(int);

void main()
{
do
{
P2=0x01; //0001
delay(1000);
P2=0x03; //0011
delay(1000);
P2=0x02; //0010
delay(1000);
P2=0x06; //0110
delay(1000);
P2=0x04; //0100
delay(1000);
P2=0x0C; //1100
delay(1000);
P2=0x08; //1000
delay(1000);
P2=0x09; //1001
delay(1000);
} while(1);
}

void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<100;j++)
{}
}

*21*
Stepper Motor Controller Circuit Advantages:

• It consumes less power.


• It requires low operating voltage

Stepper Motor Control Applications:

• This circuit can be used in the robotic applications.


• This can also be used in mechatronics applications.
• The stepper motors can be used in disk drives, matrix printers, etc.

Code Overview:

1) for wave Drive:

*22*
2) For Half Wave Drive:

3) For Full Wave Drive:

*23*
Result:
Interfacing of the stepper motor with microcontroller is done successfully.

*24*
Experiment -5
Aim: To display character ‘A’ on 8*8 LED matrix .

Software used : Keil , ISIS PROTEUS

Theory:
The PIC microcontroller is a family of microcontrollers manufactured by the microchip technology.
Peripheral interface controller belongs to a class of 8 bit microcontrollers of RISC architecture.
Though the family consists of large number of devices, all the devices have the same basic structure,
offering the following fundamental features.
1. Reduced instruction set (RISC) with only 35 instructions.
2. RAM data memory.
3. Bidirectional digital I/O ports
4. On-chip timer with pre-scalar.
5. Watchdog timer
6. Power on reset
7. External crystal operation
8. Power saving sleep mode

It has 8-bit ALU and 8-bit work registers. There are two registers GPR( general purpose registers) and
SFR( special function registers). ALU controls the status bits of STATUS registers.

Circuit Diagram:

*25*
Code:
ORG 0000 H

START : LCALL DISPOFF


COL 1 : MOV P2, #08 H
MOV P1, #42 H
MOV P3, #OFFH

MOV P0, #10 H


LCALL DELAY 1
LCALL DISPOFF

COL 2: MOV P2, #01 H


MOV P1, #SE H
MOV P3, #20 H
MOV P0, #20 H
LCALL DELAY 1
LCALL DELAY 1
LCALL DISPOFF

COL 3: MOV P2, #06 H


MOV P1, #1E H
MOV P3,# 30 H
MOV P0, # 40 H
LCALL DELAY 1
LCALL DELAY 1
LCALL DISPOFF

COL 4: MOV P2,# 06 H


MOV P1,# 087 H
MOV P3,# 18 H
MOV P0,# 80 H
LCALL DELAY 1
LCALL DELAY 1
LCALL DISPOFF

*26*
COL 5: MOV P2,# 06 H
MOV P1, #1E H

MOV P3,# 30 H
MOV P0,#01 H
LCALL DELAY 1
LCALL DELAY 1

LCALL DISPOFF

COL 6: MOV P2,# 03 H


MOV P1,# SE H

MOV P3,# 20 H
MOV P0,# 02 H
LCALL DELAY 1
LCALL DELAY 1

LCALL DISPOFF

COL 7: MOV P2,# 08 H


MOV P1,# 42 H

MOV P3,# 04 H
MOV P0,# 04 H
LCALL DELAY 1
LCALL DELAY 1

LCALL DISPOFF

COL 8: LCALL DISPOFF


LCALL DELAY 1

LCALL DISPOFF
LCALL COL1
DISPOFF : MOV P0,#00 H
MOV P1,# 00 H

MOV P2,# 00 H
MOV P3,# 00 H

*27*
LCALL DELAY 1
RET
DELAY 1 : MOV R7,# OFF H

DEL 1 : DJNZ R7, DEL 1


RET

Code Overview:

*28*
Result: The character ‘A’ is successfully displayed on 8*8 LED matrix .

*29*
Experiment -6
Aim: Write an ALP to add 16-bit nos. using ARM processor.

Theory: To add two 16bit numbers using arm processor , firstly we load the first number and then the
second number . Then we will add the two numbers using ADD instruction and store the result in 16 bit
variable Result .

Architecture of ARM-7:

Block Diagram of ARM-7

Code:
TTL 16bitadd

AREA Program, CODE, READONLY


ENTRY

Main
LDR R1, Value1 ;load the first number
LDR R2, Value2 ;load the second number
ADD R1, R1, R2 ;add them together into R1 (x = x + y)
STR R1, Result ;store the result
SWI &11
Value1 DCW &C123 ;first value to be added
ALIGN
Value2 DCW &02AA ;second value to be added
ALIGN
Result DCW 0 ;storage for result
END

*30*
Program Overview:

Output & Results:

*31*
Results:

Input:
Value 1=C123
Value 2=02AA

Output:
Result =C3CD

*32*
Experiment -7
Aim: Write an ALP for multiplying two 32 bit nos. using ARM processor.

Theory :
For multiplication of two 32bit numbers using ARM processor ,firstly we load the first number to R0 and
then the second number to R1 . Then load the address of the result to R6 . Now move top half of R0 to R5
and top half of R1 to R3. Using BIC instruction , we get bottom half of R0 and R1 . Now multiply R0 and
R1 and store the result in R2. Multiply R0 and R3 and store the result in R0. Again , multiply R1 and R5
and store the result in R1. Multiply R3 and R5 and store the result the result in R5.
Now add R0 and R1 and store the result in R0.Add the carry to R3. Now we get LSB 32bits and MSB 32
bits using ADDS and ADC instruction .Store the LSB in R6. Now add R6 such that R6=R6+4. Now store
MSB to R6 .And we get result .

Code:
TTL Ch8Ex4
AREA Program, CODE, READONLY
ENTRY

Main
LDR R0, Number1 ;load first number
LDR R1, Number2 ;and second
LDR R6, =Result ;load the address of result

MOV R5, R0, LSR #16 ;Top half of R0


MOV R3, R1, LSR #16 ;Top half of R1
BIC R0, R0, R5, LSL #16 ;bottom half of R0
BIC R1, R1, R3, LSL #16 ;bottom half of R1

MUL R2, R0, R1 ;partial result


MUL R0, R3, R0 ;partial result
MUL R1, R5, R1 ;partial result
MUL R3, R5, R3 ;partial result

ADDS R0, R1, R0 ;add middle parts


ADDCS R3, R3, #&10000 ;add in any carry from above
ADDS R2, R2, R0, LSL #16 ;LSB 32 bits
ADC R3, R3, R0, LSR #16 ;MSB 32 bits

STR R2, [R6] ;store LSB


ADD R6, R6, #4 ;increment pointer

*33*
STR R3, [R6] ;store MSB
SWT &11 ;all done
AREA Data1, DATA

Number1 DCD &12345678 ;a 16 bit binary number


Number2 DCD &ABCDEF01 ;another

Program Overview:

*34*
Output & Results:

Result :
First number =2468AC16
Second number = 328108810
Result = 72ECB8C25B60 (64 bit)

*35*
EXPERIMENT-08
Aim: Write an ALP to multiply two matrices using ARM processor.

Theory :
matrix multiplication is a binary operation that produces a matrix from two matrices. For matrix
multiplication, the number of columns in the first matrix must be equal to the number of rows in the
second matrix. The resulting matrix, known as the matrix product.

A simple C implementation of the matrix multiply uses three nested loop i,j and k
#define R 40
#define S 40
#define T 40

void ref_matrix_mul(int*a,int*b,int*c)
{
unsigned int i,j,k;
int sum;

for(i=0;i<R;i++)
{
for(j=0;j<T;j++)
{

sum=0;
for(k=0;k<S;k++)
{
sum+=b[i*S+k]*c[k*T+j];

}
a[i*T+j]=sum;
}}}

Code:
R EQU 40
S EQU 40
T EQU 40
a RN 0 ;
b RN 1 ;
c RN 3 ;

*36*
sum RN 3
bval RN 4
cval RN 12

count RN 14
; void matrix_mul(int*a,int*b,int*c)
Matrix_mul
STMFD sp, {r4,1r}

MOV count , #(R-1) ; i=0


Loop_i
ADD count, count , #(T-1)<<8 ; j=0
Loop j

ADD count , count , #(S-1)<<16 ; k=0


MOV sum , #0
Loop k
LDR bval , [b] , #4 ; bval= B[I,k] , b=&B[i,k-1]

LDR cval , [c] , #4*T ; cval = C[k,j] , c=&C[k+1,j]


SUBS count , count , #1<<15 ; k++
MLA sum , bval ,cval , sum ; sum += bval*cval
BPL loop_k ; branch if k<=S-1

STR sum , [a] , #4 ; A[i,j] = sum , a=&A[I,j+1]


SUB c ,c , #4*S*T ; c - &C [0,j]
ADD c , c , #4 ; c - &C[0,j+1]
ADDS count , count , #(1<<16)-(1<<8) ; zero (S-1-K) , j++

SUBPL b, b , #4*S ; b - &B[i,0]


BPL loop_j ; branch if j<=T-1
SUB c , c , #4*T ; c- &C[0,0]
ADDS count , count , #(1>>8)-1 ; zero (T-1-j) , i++

BPL loop_i ; branch if i<=R-1


LDMFD spl , {r4 , pc}

*37*
Output:

Program Overview:

*38*
Result:
The multiplication of two matrices using ARM processor is done successfully.

*39*

You might also like