Microprocessors & Interfacing Guide
Microprocessors & Interfacing Guide
INTERFACING
COURSE CODE: EEX4436
ASSIGNMENT NO: 01
NAME : S. R. P. MADUHANSA
REG NO : 416960756
DATE OF SUBMISSION : 23. 04. 2021
CENTRE : KANDY
Q1) a.
Arduino (ATmega328/p)
Q1) c.
In mechanical engineering field,
Today Micro-controller systems are widely used in automotive electronic systems. because they are very
safe and accurate than humans. in history every machine, vehicles are controlled in fully mechanically, and
its less safe and less accuracy. because of that that time all the machines and vehicles are very primary. but
now a days mechanical engineering field is used modern technology and they embedded systems for their
all the machines and vehicles.
because of micro-controller-based systems, we can take lot of advantages,
mainly improve accuracy, efficiency and cost for high scale productions.
in automotive field,
they give us safety more than humans can do. it also gives vehicle safety. and also embedded
. automotive systems make our lives are easier.
Q1) d.
In digital communication, there are two types of data transfer,
• serial communication
• parallel communication
In serial communication;
➢ I2C Protocol
I2c (Inter-integrated circuit) is a two-wire bidirectional protocol used for an exchange of data between
different devices on the same bus. I2c uses 7 bit or 10-bit address allowing to connect up to 1024 devices.
But it requires clock signal for generating start and stop conditions. The advantage is it provides data
transfer at 400 kbps. It is suitable for onboard communication.
➢ SPI Protocol
SPI (Serial peripheral interface) protocol send and receive data in a continuous stream without any
interruption. This protocol is recommended for highspeed data communication is required. The maximum
speed it can provide is 10 Mbps.
Unlike i2c, SPI has 4 wires. They are MOSI (Master out slave in), MISO (Master in slave out), Clock and
Slave select signal. Theoretically, we can connect unlimited number of slaves and practically it depends on
the load capacitance of the bus.
➢ CAN Protocol
This protocol is dedicated to vehicle systems or automobiles. It is a message-oriented protocol used for
multiplex electric wiring to economize the copper. It is a multi-master multi serial bus used in applications
such as automatic start/stop of vehicles, collision avoidance systems etc.
➢ USB
USB interface is the best alternative to serial or parallel ports. The data transfer associated with USB ports
are quite faster than the serial and parallel interface. USB supports speeds from 1.5 Mbps (USB 1.0) to 4.8
Gbps (USB 3.0). Today most of the embedded devices use USB OTG (On the Go programming) technique
for dumping the hex file to the microcontroller.
Q2) a.
All kinds of Embedded Systems need software’s to run them for performing specific functions. The
microcontroller contains the software for handling all the operations.
➢ Editors
➢ Assemblers
➢ Compilers
➢ Debuggers
➢ Simulators
➢ Emulators
-Editors:
The very first tool in the development of software for an embedded system is a text editor. we need to write
source code. In Embedded System Development Tools, Editor is used to writing code for embedded
systems applications. It is the editor where we write that code. Also, we can use various kinds of
programming languages to implement programs by using editors.
-Compiler/ Assembler:
Source code will be turned into a .HEX file by using a compiler/ assembler. Compiler/Assembler is the
second tool in your embedded system software development.
Once you are done with your source code, you need to translate that code into the instructions on the basis
of which, the microcontroller will operate. One can say that the purpose of the compiler is the conversion
of a high-level programming language into a low-level programming language
EX: ASM51
-Debugger:
The name debugger speaks itself. This tool is used for debugging your code. The debugger is actually as a
tester and is used to test whether your code contains error or not. The debugger has a complete look at the
code and test if there are any errors or bugs.
-Simulators:
It is also a software segment that make virtual 8051 microprocessor act as physically and show us how our
ALP is play.
-Terminal emulator:
Use to communicate with 8051 board. This provides the ability to transmit the. HEX code to the hardware.
AES51 board, Normally the all-hardware components such as, 8051 micro-processor,4-I/O ports, Serial
port, SFRs, Interrupts and Timers/counters that necessary for microcontroller is indicated in the boar of
AES51. It is providing facility for act to 8051.
External tools, the all peripherals that requiring for do our new design. Such as Sensors, Actuators,
Multiplexers, DE-multiplexers, decoders, Motors.
Q2) b.
80 C 310 $4.78
80 C31 $5.20
TE 502 $3.00
8XC51/80C $4.75-$5.35
C501 $4.75
Applications Basic Function Used in high Used in Used for real time
for small projects. technology like refrigerator and application
robotics low budget
project Video Games
Q2) d.
They do not provide many facilities at the hardware level. They are very close to the hardware and help to write a
program at the hardware level.
For writing programs, hardware knowledge is not required. For writing programs, hardware knowledge is a must.
A single statement may execute several instructions. The statements can be directly mapped to processor
instructions.
BASIC, Perl, Pascal, COBOL, Ruby etc. are examples Machine language and Assembly language are Low-Level
of High-Level Languages. Languages.
Q3) a.
8051 There are six types of addressing modes: -
MOVA, #0AFH;
MOVR3, #45H;
MOVDPTR, #FE00H;
In these instructions, the # symbol is used for immediate data. In the last instruction, there is DPTR. The DPTR stands
for Data Pointer. Using this, it points the external data memory location. In the first instruction, the immediate data is
AFH, but one 0 is added at the beginning. So, when the data is starting with A to F, the data should be preceded by 0.
MOVA, R5;
MOVR2, #45H;
MOVR0, A;
MOV80H, R6;
MOVR2, 45H;
MOVR0, 05H;
The first instruction will send the content of registerR6 to port P0 (Address of Port 0 is 80H). The second one
is forgetting content from 45H to R2. The third one is used to get data from Register R5 (When register bank
RB0 is selected) to register R5.
MOV0E5H, @R0;
MOV@R1, 80H
In the instructions, the @ symbol is used for register indirect addressing. In the first instruction, it is showing
that theR0 register is used. If the content of R0 is 40H, then that instruction will take the data which is located
at location 40H of the internal RAM. In the second one, if the content of R1 is 30H, then it indicates that the
content of port P0 will be stored at location 30H in the internal RAM.
MOVXA, @R1;
MOV@DPTR, A;
In these two instructions, the X in MOVX indicates the external data memory. The external data memory can only be
accessed in register indirect mode. In the first instruction if the R0 is holding 40H, then A will get the content of external
RAM location40H. And in the second one, the content of A is overwritten in the location pointed by DPTR.
MOVCA, @A+PC;
MOVCA, @A+DPTR;
The C in MOVC instruction refers to code byte. For the first instruction, let us consider A holds 30H. And the PC value
is1125H. The contents of program memory location 1155H (30H + 1125H) are moved to register A.
RLA;
SWAPA;
These are 1- byte instruction. The first one is used to rotate the A register content to the Left. The second one is used to
swap the nibbles in A.
Q3) b.
Q3) c. c)
MOV R0, #1
CJNE R0, #6 then
Acall set
Then: JNC set
MOV R1, #X
MOV A, R1
MOV B, R1
MUL AB
MOV R1, A
Acall Exit
Set : MOV R1, #X
ADD R1, #7
Q3) d.
8051 micro controller memory organization: -
This micro controller memory can be dividing in two categories.
I. Program memory (ROM)
II. Data memory (RAM)
Program memory: -
This memory used for permanent saving program (CODE) being executed. Also, this memory is a
read only memory. That mean micro-controller basic operations are doing according to this read only
memory codes. Program memory may also used to store a constant variable.
Data memory: -
RAM memory is used for temporarily storing and keeping intermediate results and variables.
Q3) e.
Memory type RAM ROM PROM EPROM EEPROM FLASH
category Read-write Read only Read only Read-mostly Read-mostly Read - mostly
Erasure Electrically, Not possible Not possible UV light Electrically Electrically
byte level
Write Electrically Masks Electrically Electrically Electrically Electrically
Mechanism
Volatility Volatile Non-Volatile Non-Volatile Non-Volatile Non-Volatile Non-Volatile
Segment Registers Segments are specific areas defined in a program for containing data, code and stack. There are
three main segments:
• Code Segment: it contains all the instructions to be executed. A 16 - bit Code Segment register or CS register
stores the starting address of the code segment.
• Data Segment: it contains data, constants and work areas. A 16 - bit Data Segment register of DS register
stores the starting address of the data segment.
• Stack Segment: it contains data and return addresses of procedures or subroutines. It is implemented as a
'stack' data structure. The Stack Segment register or SS register stores the starting address of the stack.
Q3) f.
A lookup table is a list of values that are stored in the memory of the microcontroller, which then
can be accessed using the ReadTable command. Advantage of lookup tables is that they are
memory efficient, compared to an equivalent set of alternative command statements.
Q3) g.
The main processor stops working and checks if some controller has a message for it, if it has, processes the message
and resumes operation. This is called polling. the main processor does its job, and the devices are doing their job. If
the device finishes its job or an error occurs, the device informs the main processor with an interrupt request. (The
main program is controlling the power element of the oven. The use presses a key on the front panel to cancel the
operation or change the length of cooking time. The main program is interrupted. The Interrupt Service Routine takes
over, reads the keypad and changes the cooking conditions accordingly, then finishes by passing control back to the
main program. The main program continues according to the new conditions set by the Interrupt Service Routine.)
• Polling
CPU monitors all served devices continuously, looking for a “service request flag “Whenever it sees a
request, it serves the device and then keeps polling. CPU is always “busy” with polling doing the “while any
request” loop
• Interrupts
If and when a device is ready and needs attention, it informs the CPUCPU drops whatever it was doing and
serves the device and then returns back to its original task. CPU is always “free”, when not serving any
interrupt
Q4) a.
1) Timers
The timer module, which is strictly speaking a counter module, is an important part of every microcontroller,
and most controllers provide one or more timers with 8 and/or 16-bit resolution. Timers are used for a variety
of tasks ranging from simple delays over measurement of periods to waveform generation. The most basic use
of the timer is in its function as a counter, but timers generally also allow the user to timestamp external events,
to trigger interrupts after a certain number of clock cycles, and even to generate pulse-width modulated signals
for motor control. Timers can generally raise an interrupt whenever they experience an overflow of the count
value. This can be used to implement a rudimentary periodic signal by setting the count value to a given start
value and then waiting for the overflow. some timers provide a modulus mode which automatically reloads
the start value when the timer overflows. Although the timer is generally clocked by the same source as the
microcontroller itself, this need not be the case.
2) Counters
Each timer is basically a counter which is either incremented or decremented upon every clock tick. The
direction (up- or down-counter) is either fixed or configurable. The current count value can be read through a
count register and can be set to a specific value by the user. For a timer resolution of n, the count value is
within [0, 2n − 1]. Care must be taken when the timer length exceeds the word length of the controller, e.g.,
when using a 16-bit timer on an 8-bit controller. In such a case, access to the 16-bit count value must be done
in two passes, which could lead to inconsistent values. Just think of a timer that is at value 0x00FF and will
switch to 0x0100 in the next cycle. If you read the high byte first and the low byte with the next instruction,
you will get 0x0000. If you do it the other way round, you will end up with 0x01FF, which is not any better.
To counter such problems, the ATmega16 controller for example uses a buffer register to store the high byte
of the timer. So whenever the program reads the low byte of the count register, the high byte is simultaneously
stored in the buffer and can then be read at the next cycle. Likewise, to write a new count value, the high byte
should be written first (and is stored in the buffer by the controller), and as soon as the low byte is written,
both high and low byte are written into the count register in one go.
Q4) b.
Q4) c. 1)
SOFTWARE DELAY
We got 60756µS delay as:
So the calculation can show as below,
Crystal frequency = 11.0592µHz
One machine cycle frequency = 11.0592/12 = 921.6 µHz
Time for one machine cycle = 1/921.6 = 1.085 µS
Then, total machine cycle for delay = 60756µS/1.085µS = 55996.31 ~ 55996
So, R0 = 12 = X
R1 = 20 = Y
R2 = 100 = Z
Therefor software delay 100p,
ORG 0000H
MOV TMOD < #00000001B
Now want to apply this logic in the design of automatic hand sanitizer dispenser.
The ultrasonic sensor uses ultrasonic sound waves to detect the object. The transmitter of the sensor
transmits ultrasonic waves and the receiver of the module receives those ultrasonic waves.
The following figure shows the interface of the ultrasonic sensor with the Arduino. In this, we have
connected the trigger pin of the ultrasonic sensor to the D3 of the Arduino board and the D2 pin of
the Arduino to the echo pin of the ultrasonic sensor.
This is the second option (As a distance sensor) you can use in the design of an automatic hand sanitizer
machine. This sensor uses a light source to detect the obstacle.
IR sensor
The relay is an electrotechnical switch that is used to trigger high volt applications using low volt signals. To
turn on the DC water pump, we are using this 5V relay module. The interfacing diagram of the relay module
with the Arduino is as follows.