Professional Documents
Culture Documents
HoDucDongPhuong EEEEIU21047 Lab1
HoDucDongPhuong EEEEIU21047 Lab1
HoDucDongPhuong EEEEIU21047 Lab1
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING
EE084IU
Micro-processing Systems Lab
LAB 1
Date: 02/04/2024
- Header/Footer Yes No
- Grammar Yes No
- Spelling Yes No
Signature:
Date:
International University School of Electrical Engineering
Table of Contents
List of Figures........................................................................................................................................................ ii
1 Theoretical Background................................................................................................................................1
2 Experimental Procedure............................................................................................................................... 2
2.1 Experiment 1............................................................................................................................................ 2
2.2 Experiment 2............................................................................................................................................ 2
2.3 Experiment 3............................................................................................................................................ 2
3 Experimental Results..................................................................................................................................... 3
3.1 Experiment 1............................................................................................................................................ 3
3.2 Experiment 2............................................................................................................................................ 3
3.3 Experiment 3............................................................................................................................................ 3
4 Discussion of Results...................................................................................................................................... 4
List of Figures
Figure 1: Circuit diagram 1........................................................................................................................... 2
Figure 2: Circuit diagram 2........................................................................................................................... 2
Figure 3: Simulation for experiment 1......................................................................................................3
List of Tables
Table 1: Comparison of circuit parameters............................................................................................1
Table 2: Data of experiment 1...................................................................................................................... 3
2 Experimental Procedure
Problem 1: Follow step by step the AVRStudio tutorial to create a new project and carry
out the simulation
Check point:
Problem 2: List contents of the related registers and SREG (Status) register for each line
of the following program.
For home work lab report activity, translate each line of this program into binary
machine code.
[Course’s 1 [Course
name] number]
International School of Electrical
University Engineering
.include "m32def.inc"
ldi r16,high(ramend)
out sph, r16
ser r20
dec r20
r20, -7 inc
r20
neg r20
com r20
clr r20
ldi r20,0x77
ldi r21,0x33
ldi r22,0xAA
Ldi r23,0xEE
r22,R23 adc
r21,r20 push
r22
push r21
Pop r22
Pop r21
[Course’s 2 [Course
name] number]
International School of Electrical
University Engineering
Signature of Lab Instructor Remarks
Problem 3: List contents of the R17 and SREG (Status) registers for each line of the
following program.
For home work lab report activity, translate each line of this program into binary
machine code.
.include "m32def.inc"
andi r17,0x55
ori r17,0xAA
Problem 4 : Give the comment for eachline of the program, Draw the flow chart for
following program, explain the function of this program. Simulate and Run to test this code in
[Course’s 3 [Course
name] number]
International School of Electrical
University Engineering
Proteus. For home work lab report activity, translate each line of this program into binary
machine code.
.ORG 00
LDI
R18,0xFF OUT
R16, 15
LDI R17, 0
DEC R16
CPI
R15,0x05 BRNE
L1
STS
0x600,R17 OUT
PORTC,R17:
L2: RJMP L2
Problem 5 : Give the comment for eachline of the program, Draw the flow chart for
following program, explain the function of this program. Simulate and run to test this code in
[Course’s 4 [Course
name] number]
International School of Electrical
University Engineering
Proteus.
.include "m328pdef.inc"
.equ numB = 20
[Course’s 5 [Course
name] number]
International School of Electrical
University Engineering
.def loopCt= r17
.dseg
.org SRAM_START
sArr: .BYTEnumB
.cseg
.org 0x00
ldi
XL,LOW(sArr)
ldi XH,HIGH(sArr)
ldi
ZL,LOW(pArr<<1)
ldi ZH,HIGH(pArr<<1)
ldi loopCt,numB
arrLp:
lpm tmp,Z+
st X+,tmp
dec
loopCt
brne arrLp
[Course’s 6 [Course
name] number]
International School of Electrical
University Engineering
ldi
XL,LOW(sArr)
ldi XH,HIGH(sArr)
ldi loopCt,numB
ldi findnum,0x00
F_Lp:
LD R16,X+
CP findnum,R16
BRCC CHECK_counter
[Course’s 7 [Course
name] number]
International School of Electrical
University Engineering
MOV findnum,R16
CHECK_counter:
DEC loopCt
BRNE F_Lp ;
pArr: .db
0,1,2,3,4,5,6,7,8,9,\
10,11,12,13,14,15,16,\
17,18,19
Problem 6: Analyze the following code. How would the Port I/O pins behave if this code was
downloaded to and running on the microcontroller. Calculate the time delay for the delay
subroutine if the system has an AVR with a frequency of 1MHz. Run the code in AVR Proteus,
using virtual oscilloscope monitor Port C, compare the calculated time delay and the testing
delay time. Using Burn-E software and Programming Circuit to download and run on the
microcontroller Kit.
.include "m32def.inc"
LDI R16,
low(RAMEND) OUT SPL,
R16
[Course’s 8 [Course
name] number]
International School of Electrical
University Engineering
LDI R16, high(RAMEND)
OUT SPH, R16
call delay
[Course’s 9 [Course
name] number]
International School of Electrical
University Engineering
OUT PORTB, R16
call delay
RJMP mloop
d
elay: LDI R20, 200
NO
P DEC
R18 NOP
BRNE
dloop NOP
DEC R20
BRNE
back RET
Problem 7: : Give the comment for eachline of the program, what is the function of
following program? Simulate and Run to test this code in proteus.
[Course’s 10 [Course
name] number]
International School of Electrical
University Engineering
.INCLUDE "M32DEF.INC"
.DEF a = R1
[Course’s 11 [Course
name] number]
International School of Electrical
University Engineering
.DEF b = R2
.DEF c = R3
.DEVICE ATmega32 ;
.DSEG ;
.ORG 0x0060 ;
data: .BYTE 1
.CSEG
.ORG 0x0000
RJMP START
.ORG
0x2A
START:
LDI R20 ,
,R20;
STS data ,
,data ;
[Course’s 12 [Course
name] number]
International School of Electrical
University Engineering
LDI XH, HIGH(SRAM_Address);
LD a, X+ ;
LD b, X+ ;
LD c, X ;
ST X , R20;
MAIN:
RJMP MAIN
[Course’s 13 [Course
name] number]
International School of Electrical
University Engineering
Problem 8: Give the comment for eachline of the program, what is the function of
following program? Simulate and Run to test this code in Proteus.
.INCLUDE "M32DEF.INC"
.DEVICE ATmega32
START
.ORG
0x002A
START:
Ldi r19,0x66
Ldi r20,0x33
cp r19,r20
breq IF
ELSE:
RJMP ENDIF
IF :
ENDIF :
MAIN:
[Course’s 14 [Course
name] number]
International School of Electrical
University Engineering
RJMP MAIN
[Course’s 15 [Course
name] number]
International School of Electrical
University Engineering
Problem 9: Write a Assembly program to monitor the PB3 bit. When it is LOW, send $38 to
PORTC. If it is HIGH, send $43 to PORTC.
3 Experimental Result
3.1 Experiment 1
Problem 1: Follow step by step the AVRStudio tutorial to create a new project and carry out the
simulation
Check point:
[Course’s 16 [Course
name] number]
International School of Electrical
University Engineering
3.2 Experiment 2
List contents of the related registers and SREG (Status) register for each line of the following program.
For home work lab report activity, translate each line of this program into binary machine code.
out spl, r16 Output write the value of r16 to stack pointer low
[Course’s 17 [Course
name] number]
International School of Electrical
University Engineering
neg r20 ;two’s complement negation – negates the value of
register r20
add r20,R22 ;add the values of register r20 and r22 and store it into r20
adc r22,R23 ;add with carry -add the values of r22 and r23 and carry
flag, storing the result in r22
adc r21,r20 ;add with carry-add the values of r21 and r20 and carry
flad, storing the result in 21
push r22 ;push the value of register r22 onto the stack
push r21 ;push the value of register r21 onto the stack
Pop r22 ;Pop-Pops the top value from mthe stack into register r22
Pop r21 ;Pop-pops the top value from the stack into register r21
Check point:
3.3 Experiment 3
List contents of the R17 and SREG (Status) registers for each line of the following program.
For home work lab report activity, translate each line of this program into binary machine code.
[Course’s 18 [Course
name] number]
International School of Electrical
University Engineering
. include "m32def.inc"
[Course’s 19 [Course
name] number]
International School of Electrical
University Engineering
andi r17, 0x65 ; 0111 0110 0001 0101
3.4 Experiment 4
Give the comment for eachline of the program, Draw the flow chart for following program, explain the
function of this program. Simulate and Run to test this code in Proteus. For home work lab report activity,
translate each line of this program into binary machine code.
.ORG 00
LDI R18,0xFF ;set program counter to address 0, indicating the start of the program
OUT DDRC, R18 ;Loads the immediate value 0xFF into register r18.sets all pins of port
C as output pins
CPI R15,0x05 ;Compares the value of R15 with the immediate value 0X05
This software configures port C for output and initializes two registers, R16 and R17. It then enters
a loop in which the value of R16 is continuously added to R17 and decremented until R16 reaches
5. Once R16 equals 5, the value of R17 is saved in memory address 0x600 and sent to port C.
Finally, it goes into an unending cycle.
The simulation:
The flowchart:
[Course’s 21 [Course
name] number]
International School of Electrical
University Engineering
3.5 Experiment 5
: Give the comment for eachline of the program, Draw the flow chart for following program, explain
the function of this program. Simulate and run to test this code in Proteus.
.include "m328pdef.inc"
[Course’s 22 [Course
name] number]
International School of Electrical
University Engineering
.org SRAM_START ;Start of SRAM
sArr: .BYTE numB ;Define byte array sArr with size numB
ldi ZL,LOW(pArr<<1) ; Load low byte of pArr address shifter left by 1 into ZL
ldi ZH,HIGH(pArr<<1) ; Load high byte of pArr address shifter left by 1 into ZH
10,11,12,13,14,15,16,\
17,18,19
This program first replicates the contents of the byte array'sArr' to program memory 'pArr', after
which it gets the maximum value within the array 'pArr'. It accomplishes this by iterating through
the array, comparing each element to the current maximum value ('findnum'), and updating
'findnum' if a higher value is discovered. Finally, it goes into an unending cycle.
The flowchart:
[Course’s 24 [Course
name] number]
International School of Electrical
University Engineering
3.6 Experiment 6
Analyze the following code. How would the Port I/O pins behave if this code was downloaded to and
running on the microcontroller. Calculate the time delay for the delay subroutine if the system has an AVR
with a frequency of 1MHz. Run the code in AVR Proteus, using virtual oscilloscope monitor Port C,
compare the calculated time delay and the testing delay time. Using Burn-E software and Programming
Circuit to download and run on the microcontroller Kit.
.include "m32def.inc" ; directive includes a predefined macro file for
the ATmega32 microcontroller
[Course’s 25 [Course
name] number]
International School of Electrical
University Engineering
LDI R16, low(RAMEND) ; loads the low byte of the RAM end address
into register R16
OUT SPL, R16 ; sets the stack pointer low byte (SPL) to
the value in R16
LDI R16, high(RAMEND)
; set the high byte of the stack pointer.
[Course’s 26 [Course
name] number]
International School of Electrical
University Engineering
call delay ; subroutine introduces a delay.
LDI R16, 0xFF
OUT PORTB, R16 ; R16 is set to 0xFF (all pins high) and written to
PORTB.
call delay ; subroutine introduces a delay.
RJMP mloop ; Repeat the loop indefinitely
NOP
[Course’s 27 [Course
name] number]
International School of Electrical
University Engineering
RET ; instruction returns from the delay subroutine.
Port I/O pin behavior: • Port B's pins are initially set to low.
• After a wait, all pins on port B will be set to high.
3.7 Experiment 7
Give the comment for eachline of the program, what is the function of following program? Simulate
and Run to test this code in proteus.
START:
LDI R20, 0xFF; ; Load immediate value 0xFF into register R20
OUT DDRB , R20; ; Output the value of R20 to the Data Direction Register
B
LDI R20 , 0xAA; ; Load immediate value 0xAA into register R20
OUT PORTB ,R20; ; Output the value of R20 to the PORTB register
STS data , R20; ; Store the value of R20 into the variable 'data'
LDS R19 ,data ; ; Load the value of 'data' into register R19
MAIN:
_The program initializes some registers and performs basic input/output operations, memory
operations, and looping.
[Course’s 29 [Course
name] number]
International School of Electrical
University Engineering
Signature of Lab Instructor Remarks
3.8 Experiment 8
Give the comment for eachline of the program, what is the function of following program? Simulate
and Run to test this code in Proteus.
[Course’s 30 [Course
name] number]
International School of Electrical
University Engineering
.ORG 0x002A ; Sets the reset vector to address
0x0000, indicating where the program execution begins after a reset.
LDI R16 , 0x11 ; Loads the value 0x11 into register R16.
[Course’s 31 [Course
name] number]
International University School of Electrical Engineering
3.9 Experiment 9
Write a Assembly program to monitor the PB3 bit. When it is LOW, send $38 to PORTC. If it is
HIGH, send $43 to PORTC.
3.10 Experiment 10
Write an Assembly program to control 32 LEDs connected to PORTA, PORTB, PORTC, and
PORTD with different Scenarios, using the Delay following function to delay the lighting time
of each LED.
Delay_1s:
LDI R20,68 ;
DL3: LDI R21,100 ;
DL2: LDI R22,48 ;
DL1: DEC R22 ;
BRNE DL1 ;
DEC R21 ;
BRNE DL2 ;
DEC R20 ;
BRNE
DL3
3.11 Experiment 11
4 Discussion of Results
In conclusion, learning convolution via these three ways gives you a thorough understanding of
both the theoretical basis and practical applications in micro-processing systems. It also
improves my expertise in using AVR Studio and Proteus, allowing me to comprehend exactly
what the code is doing. Thank you to our teacher, M.Eng.V.M. Thanh, who was very helpful
during the lab session.