Professional Documents
Culture Documents
SUBJECT CODE
SEE 3223
SUBJECT
MICROPROCESSORS
LECTURERS
EN ZULFAKAR ASPAR
COURSES
SECTIONS
TIME
2 HOURS 30 MINUTES
DATE
___________________________________________________________________________
INSTRUCTIONS:
___________________________________________________________________________
THIS PAPER CONSISTS OF 27 PAGES ONLY INCLUDING FRONT PAGE
SEE 3223
2
PART A:
QUESTION 1
1.
Write three differentiating features between a general purpose computing system and
an embedded system based on the following properties.
(6 marks)
Properties
Embedded System
Application
Size
Cost
2.
Sketch a block diagram with complete labeling of the basic structure of a computer
system.
(4 marks)
3.
How many general purpose registers does the AVR processor have?
(1 marks)
4.
What is the difference between the AND and the TST instruction?
(1 marks)
5.
(1 marks)
6.
(2 marks)
7.
8.
9.
If an address bus for a given computer has 16 lines, what is the maximum amount of
memory it can access?
(1 marks)
10.
What is the difference between a subroutine and an interrupt, based on the following
properties?
(6 marks)
Properties
Method of
occurrance/invokes
Data that are saved
to stack
Terminating
Instruction
Subroutine
(1 mark)
Interrupt
SEE 3223
3
QUESTION 2
1.
Explain the differences between C and V flag. Give the situation when each of these
flags may be used.
(4 marks)
2.
Find the contents of R22 after each of the following is executed sequentially
a)
LDI
SWAP
CLC
ROR
ROR
R22, 0x56
R22
R22
R22
(4 marks)
b)
CLC
LDI
SWAP
ROL
ASR
R22, 0x4D
R22
R22
R22
(4 marks)
3.
What is the final value of R16 after execution of the following instructions? The
instructions are executed sequentially.
Instruction
LDI
R16
R16, 52
R16
COM
R16
NEG
R16
(5 marks)
4.
Write a program in Assembly language that will interchange the nibble shown below.
Use only instruction involving indirect with post increment addressing mode.
(8 marks)
Address
$200
$201
$202
$203
$204
$205
$206
4
6
8
A
B
C
D
5
7
9
1
2
3
4
Address
$200
$201
$202
$203
$204
$205
$206
5
7
9
1
2
3
4
4
6
8
A
B
C
D
SEE 3223
4
QUESTION 3
a) There are two types of method to wait for an external event (I/O request) by a
microcontroller: by polling or by interrupt request.
Situation
a. Assuming the possibility that more than one event can
happen at the same time, name the method you will use if
you want to set a priority such the highest will be serviced,
and the rest will be ignored.
b. Name the method which requires the controller uses CPU
time while waiting for an event.
c. Name the method which requires address of the routine
service the event to be initialized in the systems vector table.
d. Name the method which has the possibility to fail to detect
an event because the period of the event pulse is too short to
be recognised.
Suitable Method
(4 marks)
b) Name the label of 2 external interrupts on the pinout of the ATMega32 chip and their
respective vector Address defined on the vector.
(4 marks)
c) Name 2 internal interrupts available on the ATMega32 microcontroller.
d) Based on the assembly code below, answer the following questions.
.INCLUDE "M32DEF.INC"
.ORG 0
JMP
MAIN
.ORG 0x02
JMP
EX0ISR
MAIN: LDI
R20,HIGH(RAMEND)
OUT
SPH,R20
LDI
R20,LOW(RAMEND)
OUT
SPL,R20
SBI
DDRC,3
SBI
PORTD,2
LDI
R20,$40
OUT
GICR,R20
SEI
LDI
R30, 3
LDI
R31, 4
ADD
R30, R31
HERE:
JMP
HERE
EX0ISR:
IN R21,PORTC
LDI
R22,0x08
EOR
R21,R22
OUT
PORTC,R21
RETI
(2 marks)
SEE 3223
5
i.
State the assembly codes which declare the content of interrupt vector address
for INT0?
(2 marks)
ii.
State the assembly codes in the program which will initialised the
ATMEGA32 External Interrupt Request 0, when pin INT0 is logic 0?
(3 Marks)
iii.
What is the purpose of the instruction RETI and how is it different from RET?
(4 marks)
iv.
Modify the code above to INT1 interrupt is triggered on a falling edge at the
INT1 pin and include an interrupt service routine for INT1 interrupt which
must be labelled as EX1. The interrupt service routine will just complement
the data at port B. Show where the relevant code is added in the program.
(6 marks)
SEE 3223
6
PART B:
QUESTION 4
There is an embedded system using microcontroller AVR ATmega32 shown in Figure Q4 (a).
The program shown in Figure Q4 (b) will cause LED0 to blink from a square wave pulse of
20s period using Timer Normal mode. (Assume XTAL pin frequency (System Clock) is 4 MHz)
Figure Q4 (a)
.INCLUDE "M32DEF.INC"
LDI
R16,0x08
SBI
DDRB,3
LDI
R17,0
OUT PORTB,R17
BEGIN: LDI
R20, $38
OUT TCNT0,R20
Section 1
LDI
R20,0x01
OUT TCCR0,R20
AGAIN: IN
R20,TIFR
Section 2
SBRS R20,TOV0
RJMP AGAIN
LDI
R20,0x0
OUT TCCR0,R20
Section 3
LDI
R20,0x01
OUT TIFR,R20
EOR
R17,R16 Figure Q4(b)
OUT PORTB,R17
RJMP BEGIN
Figure Q4 (b)
SEE 3223
7
a)
b)
Referring on the codes for Section 1, Section 2 and Section 3 indicated in the program,
identify which section:
(a) Stop the timer and reset the TOV0 flag
(b) Load the starting count of timer 0 and set timer operation mode.
(c) Implement a delay of 50s in order to get the LED blink at a period of every
100s.
(3 marks)
Identify the instruction(s) used in the program that determines Timer 0 is set to Normal
mode operation and running at 4 MHz frequency.
(2 marks)
c)
In the program which registers is initialized such that TOV0 flag in TIMER0 will be set
after a 50s delay and give starting count that will determine the delay.
(2 marks)
d)
(2 marks)
e)
(2 marks)
f)
(5 marks)
g)
The embedded system is added with extra LEDs to the total of 4 LEDs connecting to
PORTB.0 to PORTB.3.
i.
(3 marks)
ii.
Write a full program to blink the 4 LEDs in the sequence as shown in Table 4,
using Timer Normal mode. (Note: use the program in Figure Q4 (b) as reference).
(6 marks)
Table 4
PORTB.3
OFF
ON
PORTB.2
ON
OFF
PORTB.1
OFF
ON
PORTB.0
ON
OFF
SEE 3223
8
QUESTION 5
A simple robot arm is shown in Figure Q5(a). The Robot Arm has three moving parts which
are the Horizontal Shaft, Vertical Shaft and Gripper. These Horizontal Shaft, Vertical Shaft
and Gripper are controlled by motors drivers as shown in Table Q5(a). Each of these motor
drivers will determine the direction of movement of the respective Horizontal Shaft, Vertical
Shaft and Gripper as specified in Table Q5(a) which will determine the 2-dimension (vertical
and horizontal) position where the Gripper position is. Only one of the two shafts will be
moved at one time. The Gripper can be positioned at four different edge (BACK, PICK,
FRONT AND PLACE) as shown in Figure Q5(a) and described in Table Q5(b). Sensors X1,
X2, X3 and X4 in shown Figure Q5(a) and described in Table Q5(b) will signal if the Gripper
has reached the respective specified positions which are relative to the position of Horizontal
Shaft and Vertical Shaft.
Table Q5(c) defines the configurations of ATmega32 Input/Output port with respect to the
sensors and drivers. The inputs to ATmega32 port monitor the status of the respective sensor
which determines the position of the Gripper. The output from ATmega32 port controls the
respective drivers for motors which determine the direction of movement of the Horizontal
Shaft, Vertical Shaft or Gripper. All sensors and drivers are seen as digital devices by the
ATmega32 microcontroller.
Y3
Y4
X2
X1
X3
Y1
Y2
X4
Horizontal Arm
Vertical Arm
BACK
FRONT
Y5
PLACE
PICK
Platter
Platter
SEE 3223
9
Table Q5(a)
Moving Part
Name
Horizontal
Shaft
Vertical Shaft
Gripper
Direction
of
Movement
Forward
Back
Up
Down
Grip
Release
Arrow # shown in
Figure Q5(a)
4
8
1
3
2
6
Possible Direction of
Motion to reach the
respective position
Location of shaft
BACK
Vertical Shaft at
top-edge and
Horizontal Shaft at
back-edge
Back-edge sensor X1
is ON, Top-edge
sensor X3 is ON
PICK
Vertical Shaft at
bottom-edge and
Horizontal Shaft at
back-edge
Back-edge sensor X1
is ON, Bottom-edge
sensor X4 is ON
FRONT
Vertical Shaft at
top-edge and
Horizontal Shaft at
front-edge
Front-edge sensor X2
is ON, Top-edge
sensor X3 is ON
PLACE
Vertical Shaft at
bottom-edge and
Horizontal Shaft at
front-edge
Front-edge sensor X2
is ON, Bottom-edge
sensor X4 is ON
Sensor
X1
X2
X3
X4
X5
Detection
Back-edge
Front-edge
Top-edge
Bottom-edge
Gripper grip
Input to
Port A Pin 1
Port A Pin 2
Port A Pin 3
Port A Pin 4
Port A Pin 5
No.
1
2
3
4
5
Driver
Y1
Y2
Y3
Y4
Y5
Output from
Port B.1
Port B.2
Port B.3
Port B.4
Port B.5
SEE 3223
10
PlaceProcess
HomeProcess
ii.
iii.
i.
ii.
iii.
iv.
v.
i.
ii.
iii.
Draw the flow chart for the Pick process subroutine. (You may refer to Flowchart
Q5(b) which implements the Place process, as a guide)
(6 marks)
SEE 3223
11
b)
Based on the following flowchart, write the subroutine of the ATmega32 assembly
program that performs the Place process given Table Q5(d).
Place
At top-edge
Yes
At front-edge
Yes
At bottom-edge
Yes
Return
Flowchart Q5(b)
(8 marks)
c)
SEE 3223
12
QUESTION 6
Given the following components:
i.
ii.
iii.
iv.
v.
vi.
vii.
viii.
ix.
x.
xi.
xii.
Specifications:
i.
ii.
iii.
iv.
v.
vi.
vii.
SEE 3223
13
a) Using any of the component available given above (not necessarily all), design a
ATmega32 system by drawing the complete wiring diagram an ATmega32 system with
the 7-segment connected to port B of the ATmega32, which will read an analog from
0.00V to a full scale voltage of 5.00 Volts from the ADC1 of the ATmega32. (You may
use labels to show/replace wiring connections). Use a suitable potentiometer to generate
the voltage range of 0 Volt to 5 Volts. Diagram should include:
i)
(2 marks)
ii)
the circuit that implement the full scale voltage of 5.00 Volts.
(3 marks)
iii)
(3 marks)
iv)
b) Write the complete program which will display at the seven segment display according to
table Q6. Use polling method to read the ADC.
Table Q6
Analog voltage
0-0.99
1-1.99
2.2.99
3-3.99
4-4.99
5
(2 marks)
ii)
the code that initialised the port for Seven Segment Display output. (2 marks)
iii)
(2 marks)
iv)
(4 marks)
v)
the code that give the display on the seven segment display according to table
Q6.
(5marks)
SEE 3223
14
Figure Q6 (a)
Fiqure Q6 (b)
Seven
segment
code
(gfedcba)
03F
0.00
006
204.60
CD
05B
409.20
199
04F
613.80
266
066
818.40
332
06D
1023.00
3FF
Digit
Figure Q6 (c)
Voltage
(Volts)
Decimal Value of
a 10-bit
conversion
Approximate
Hex Value
0
Figure Q7 (c)
SEE 3223
15
APPENDIX
Reset & Interrupt Vector Table
SEE 3223
16
SEE 3223
17
SEE 3223
18
AVR Assembler Directive
Segment
Header
Code
EEPROM
Directive
.DEVICE
Defines the type of the target processor and the applicable set of instructions (illegal instructions for
that type trigger an error message, syntax: .DEVICE AT90S8515)
.DEF
.EQU
Defines a symbol and sets its value (later changes of this value remain possible, syntax: .EQU test =
1234567, internal storage of the value is 4-byte- Integer)
.SET
.INCLUDE
Includes a file and assembles its content, just like its content would be part of the calling file (typical
e.g. including the header file: .INCLUDE "C:\avrtools\appnotes\8515def.inc")
.CSEG
Start of the code segment (all that follows is assembled to the code segment and will go to the
program space)
.DB
Inserts one or more constant bytes in the code segment (could be numbers from 0..255, an ASCIIcharacter like 'c', a string like 'abcde' or a combination like 1,2,3,'abc'. The number of inserted bytes
must be even, otherwise an additional zero byte will be inserted by the assembler.)
.DW
Insert a binary word in the code segment (e.g. produces a table within the code)
.LISTMAC
Macros will be listed in the .LST-file. (Default is that macros are not listed)
.MACRO
Beginning of a macro (no code will be produced, call of the macro later produces code, syntax:
.MACRO macroname parameters, calling by: macroname parameters)
.ENDMACRO
.ESEG
Assemble to the EEPROM-segment (the code produced will go to the EEPROM section, the code
produces an .EEP-file)
.DB
Inserts one or more constant bytes in the EEPROM segment (could be numbers from 0..255, an
ASCII-character like 'c', a string like 'abcde' or a combination like 1,2,3,'abc'.)
.DW
Inserts a binary word to the EEPROM segment (the lower byte goes to the next adress, the higher
byte follows on the incremented address)
.DSEG
Assemble to the data segment (here only BYTE directives and labels are valid, during assembly only
the labels are used)
.BYTE
Reserves one or more bytes space in the data segment (only used to produce correct labels, does not
insert any values!)
.ORG
Defines the address within the respective segment, where the assembler assembles to (e.g. .ORG
0x0000)
.LIST
Switches the listing to the .LST-file on (the assembled code will be listet in a readable text file .LST)
.NOLIST
.INCLUDE
Inserts the content of another source code file, as if its content would be part of the source file
(typical e.g. including the header file: .INCLUDE "C:\avrtools\appnotes\8515def.inc")
.EXIT
SRAM
Everywhere
Description
SEE 3223
19
SEE 3223
20
SEE 3223
21
SEE 3223
22
SEE 3223
23
SEE 3223
24
SEE 3223
25
SEE 3223
26
SEE 3223
27
Sample Program running on a 1 Mhz clock frequency ATmega32, that read continuously a single ended input
from ADC0, which is set with an ADC frequency of 7.8125k Hz and with a full scale voltage of 2.56 volt.