Вы находитесь на странице: 1из 15

SEE 3223

MICROPROCESSOR SYSTEM
ASSIGNMENT 1
5/24/2014

GROUP MEMBERS:
MOHD NIZAM BIN SAMAD (SX111612EES04)
AZALELA BINTI PUNARI (SX095332EED04)
ZAIREY LEE (SX110611EES04)

LECTURER NAME : EN ISMAIL BIN ARIFFIN

SEE 3223

INTRODUCTION

ATmega32 is very much similar to ATmega16 microcontroller with certain differences which
are discussed below. ATmega32 is an 8-bit high performance microcontroller of Atmels
Mega AVR family. Atmega32 is based on enhanced RISC (Reduced Instruction Set
Computing) architecture with 131 powerful instructions. Most of the instructions execute in
one machine cycle. Atmega32 can work on a maximum frequency of 16MHz.
The differences between ATmega32 and ATmega16 can be summarized as follows:
1. ATmega32 has 32 KB programmable flash memory, static RAM of 2 KB and
EEPROM of 1 KB. The endurance cycle of flash memory and EEPROM is 10,000
and 100,000, respectively.

RAM
Flash
EEPROM

ATmega32
2 KB
32 KB
1 KB

ATmega16
1 KB
16 KB
512 bytes

2. The Bootloader area, the NRWW section starts at word 0x3800 in ATmega32 while in
ATmega16 it starts at 0x1C00.
3. ATmega32 has a different interrupt table, the table given below shows the difference.
More details can be obtained from the respective datasheets.

SEE 3223

Vector #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

ATmega32
Reset
INT0
INT1
INT2
Timer2 COMP
Timer2 OVF
Timer1 CAPT
Timer1 COMPA
Timer1 COMPB
Timer1 OVF
Timer0 COMP
Timer0 OVF
SPI, STC
USART, RXC
USART, UDRE
USART, TXC
ADC
EE_RDY
ANA_COMP
TWI
SPM_RDY

ATmega16
Reset
INT0
INT1
Timer2 COMP
Timer2 OVF
Timer1 CAPT
Timer1 COMPA
Timer1 COMPB
Timer1 OVF
Timer0 OVF
SPI, STC
USART, RXC
USART, UDRE
USART, TXC
ADC
EE_RDY
ANA_COMP
TWI
INT2
Timer0 COMP
SPM_RDY

4.
In MCUCR register, the SM2 and SE bits are swapped, i.e., the SM2 bit is bit7 and SE
bit is bit6 in MCUCR register in ATmega32.

Pin Diagram

SEE 3223

Pin Description:
Pin No.

Pin name

Description

Alternate Function

(XCK/T0)
PB0

I/O PORTB, Pin 0

T0: Timer0 External Counter Input.


XCK : USART External Clock I/O

(T1) PB1

I/O PORTB, Pin 1

T1:Timer1 External Counter Input

(INT2/AIN0)
I/O PORTB, Pin 2
PB2

(OC0/AIN1)
PB3

I/O PORTB, Pin 3

(SS) PB4

I/O PORTB, Pin 4

(MOSI) PB5

I/O PORTB, Pin 5

(MISO) PB6

I/O PORTB, Pin 6

(SCK) PB7

I/O PORTB, Pin 7

RESET

10

Vcc

Reset Pin, Active


Low Reset
Vcc = +5V

11

GND

GROUND

12

XTAL2

Output to Inverting Oscillator Amplifier

13

XTAL1

Input to Inverting Oscillator Amplifier

14

(RXD) PD0

I/O PORTD, Pin 0

15

(TXD) PD1

I/O PORTD, Pin 1

16

(INT0) PD2

I/O PORTD, Pin 2

External Interrupt INT0

17

(INT1) PD3

I/O PORTD, Pin 3

External Interrupt INT1

18

(OC1B) PD4

I/O PORTD, Pin 4

19

(OC1A) PD5 I/O PORTD, Pin 5

20

(ICP) PD6

I/O PORTD, Pin 6

Timer/Counter1 Input Capture Pin

21

PD7 (OC2)

I/O PORTD, Pin 7

Timer/Counter2 Output Compare Match


Output

22

PC0 (SCL)

I/O PORTC, Pin 0

23

PC1 (SDA)

I/O PORTC, Pin 1

24

PC2 (TCK)

I/O PORTC, Pin 2

25

PC3 (TMS)

I/O PORTC, Pin 3

26

PC4 (TDO)

I/O PORTC, Pin 4

AIN0: Analog Comparator Positive I/P


INT2: External Interrupt 2 Input
AIN1: Analog Comparator Negative I/P
OC0 : Timer0 Output Compare Match
Output

In System Programmer (ISP)


Serial Peripheral Interface (SPI)

USART Serial Communication Interface

PWM Channel Outputs

TWI Interface

JTAG Interface

SEE 3223

27
28
29

PC5 (TDI)
PC6
(TOSC1)
PC7
(TOSC2)

I/O PORTC, Pin 5


I/O PORTC, Pin 6

Timer Oscillator Pin 1

I/O PORTC, Pin 7

Timer Oscillator Pin 2

30

AVcc

Voltage Supply = Vcc for ADC

31

GND

GROUND

32

AREF

Analog Reference Pin for ADC

33

PA7 (ADC7) I/O PORTA, Pin 7

ADC Channel 7

34

PA6 (ADC6) I/O PORTA, Pin 6

ADC Channel 6

35

PA5 (ADC5) I/O PORTA, Pin 5

ADC Channel 5

36

PA4 (ADC4) I/O PORTA, Pin 4

ADC Channel 4

37

PA3 (ADC3) I/O PORTA, Pin 3

ADC Channel 3

38

PA2 (ADC2) I/O PORTA, Pin 2

ADC Channel 2

39

PA1 (ADC1) I/O PORTA, Pin 1

ADC Channel 1

40

PA0 (ADC0) I/O PORTA, Pin 0

ADC Channel 0

This an application program an AVR microcontroller (ATmega32 especially with 8 MHz


crystal frequency) to make animated LED running from pin 33 to 40. The circuit used is
shown in Figure 1, the LEDs are arranged in CA intentionally or common anode, so as to turn
on the LED should be sent logic '0 '.

SEE 3223
SCHEMATIC DIAGRAM

SEE 3223

FLOWCHART
start

Set R17 = 12
Set R18 = A1
Set R19 = D3

Decrease R17
Decrease R18
Decrease R19

YES

R17 0
R18 0
R19 0

NO
End

SEE 3223

LIST FILE .LST


AVRASM ver. 2.1.42 D:\mikrop2\ijamm.asm Thu May 22 12:01:36 2014
D:\mikrop2\ijamm.asm(7): Including file 'C:\Program Files (x86)\Atmel\AVR
Tools\AvrAssembler2\Appnotes\m32def.inc'
;LED running lights
;untuk microcontroller Atmel AVR ATMega32
;frekuensi kristal 8MHz
;-----------------------------------------.list
;----------constant and initial register
.equ led=0b01111111
;portb-7 on
.def temp=r16
;temp sebagai alias untuk R16
;====== program utama ====================
.cseg
.org 0000
;intial program code at address 0x0000
;address SP - Stack Pointer
;initial SP at RCALL
;if not the program will HANG.
000000 e50f
000001 bf0d
000002 e008
000003 bf0e

ldi temp,low(ramend)
out spl,temp
ldi temp,high(ramend)
out sph,temp

;----------- port initial--------------------000004 ef0f


000005 bb0a

ldi

temp,0b11111111
out
ddra,temp

;all bit register temp are set


;write to register DDRA

;--------setting portb as output -----000006 e70f


000007 9408

ldi

putar:
000008 bb0b
000009 d002
00000a 9507
00000b cffc
rjmp

temp,led
sec
out
rcall
ror
putar

;put register temp with led7


;set carry flag (carry=1, LED OFF)

porta,temp
;sent data to porta (LED)
tunda
;delay 0.25 s
temp
;rotate one bit right through carry
;jump to label putar

; =============================
; delay loop generator
; 1843200 cycles:
; for freq 8MHz
; delay until 0.25 s
7

SEE 3223

; ----------------------------; delaying 1843182 cycles:


tunda:
00000c e112
ldi R17, $12
00000d ea21 WGLOOP0: ldi R18, $A1
00000e ed33 WGLOOP1: ldi R19, $D3
00000f 953a WGLOOP2: dec R19
000010 f7f1
brne WGLOOP2
000011 952a
dec R18
000012 f7d9
brne WGLOOP1
000013 951a
dec R17
000014 f7c1
brne WGLOOP0
; ----------------------------; delaying 18 cycles:
000015 e016
ldi R17, $06
000016 951a WGLOOP3: dec R17
000017 f7f1
brne WGLOOP3
; =============================
000018 9508
ret
; =============================
RESOURCE USE INFORMATION
-----------------------Notice:
The register and instruction counts are symbol table hit counts,
and hence implicitly used resources are not counted, eg, the
'lpm' instruction without operands implicitly uses r0 and z,
none of which are counted.
x,y,z are separate entities in the symbol table and are
counted separately from r26..r31 here.
.dseg memory usage only counts static data declared with .byte
ATmega32 register use summary:
r0 : 0 r1 : 0 r2 : 0 r3 : 0 r4 : 0 r5 : 0 r6 : 0 r7 : 0
r8 : 0 r9 : 0 r10: 0 r11: 0 r12: 0 r13: 0 r14: 0 r15: 0
r16: 9 r17: 4 r18: 2 r19: 2 r20: 0 r21: 0 r22: 0 r23: 0
r24: 0 r25: 0 r26: 0 r27: 0 r28: 0 r29: 0 r30: 0 r31: 0
x : 0y : 0z : 0
Registers used: 4 out of 35 (11.4%)
ATmega32 instruction use summary:
.lds : 0 .sts : 0 adc : 0 add : 0 adiw : 0 and : 0
andi : 0 asr : 0 bclr : 0 bld : 0 brbc : 0 brbs : 0
brcc : 0 brcs : 0 break : 0 breq : 0 brge : 0 brhc : 0
brhs : 0 brid : 0 brie : 0 brlo : 0 brlt : 0 brmi : 0
brne : 4 brpl : 0 brsh : 0 brtc : 0 brts : 0 brvc : 0
brvs : 0 bset : 0 bst : 0 call : 0 cbi : 0 cbr : 0
8

SEE 3223

clc : 0 clh : 0 cli : 0 cln : 0 clr : 0 cls : 0


clt : 0 clv : 0 clz : 0 com : 0 cp : 0 cpc : 0
cpi : 0 cpse : 0 dec : 4 eor : 0 fmul : 0 fmuls : 0
fmulsu: 0 icall : 0 ijmp : 0 in : 0 inc : 0 jmp : 0
ld : 0 ldd : 0 ldi : 8 lds : 0 lpm : 0 lsl : 0
lsr : 0 mov : 0 movw : 0 mul : 0 muls : 0 mulsu : 0
neg : 0 nop : 0 or : 0 ori : 0 out : 4 pop : 0
push : 0 rcall : 1 ret : 1 reti : 0 rjmp : 1 rol : 0
ror : 1 sbc : 0 sbci : 0 sbi : 0 sbic : 0 sbis : 0
sbiw : 0 sbr : 0 sbrc : 0 sbrs : 0 sec : 1 seh : 0
sei : 0 sen : 0 ser : 0 ses : 0 set : 0 sev : 0
sez : 0 sleep : 0 spm : 0 st : 0 std : 0 sts : 0
sub : 0 subi : 0 swap : 0 tst : 0 wdr : 0
Instructions used: 9 out of 113 (8.0%)
ATmega32 memory use summary [bytes]:
Segment Begin End Code Data Used Size Use%
--------------------------------------------------------------[.cseg] 0x000000 0x000032 50 0 50 32768 0.2%
[.dseg] 0x000060 0x000060 0 0 0 2048 0.0%
[.eseg] 0x000000 0x000000 0 0 0 1024 0.0%
Assembly complete, 0 errors, 0 warnings

Simulation
Circuit simulation was done by using Proteus 8.0. The main purpose of this simulation was to ensure
that the circuit can be run as required.

SEE 3223
The screenshot below shows the interface for Proteus Software.

Setting up the ATmega 32 by using .hex file. This setting also allows us to introduce the crystal
oscillator frequency.

10

SEE 3223
Process simulation is in progress. The Blue sign indicated LEDs are in switched ON while the red
sign shows LED off.

CONCLUSION
The compiler AVR Studio version 4.0 can be obtained download FREE from
http://www.atmel.com. Program's start with some kind of declaration, we accidentally enter
information in the listing program to facilitate learning directly from the listing, note the
instructions that begin with '.' Is a directive of the AVR Studio, AVR microcontroller
assembly instructions instead:
;-----------------------------------------;LED running light
;untuk Atmel AVR ATMega32
;frekuensi kristal 8MHz
;-----------------------------------------.nolist ;bahagian ini
.include "m32def.inc"
.list
; list

Remember the file "m32def.inc" we include (directive. Include) because it will be utilized in
our program ATMega32 library, simply do not ask to be included in the results of the LIST
file (the result of compiling the program) using the directive. Nolist and. Lists.
11

SEE 3223

Furthermore done early initialization:


;----------constant and initial register
.equ led=0b01111111 ;portb-7 ON
.def temp=r16
;temp sebagai alias untuk R16
;====== program utama ====================
.cseg
.org 0000
;kod awalan program pada alamat 0x0000

LED variable used to store data that will be released through PORTA, initially filled 0b01111111, 0
means the LED will be lit first. The program begins by declaring a segment of code (. Cseg) and start
address 0 0000 (. Org).

Next we perform the initialization STACK:


;address SP - Stack Pointer
;initial SP pada RCALL
;if not done the program will hang
ldi temp,low(ramend)
out spl,temp
ldi temp,high(ramend)
out sph,temp

Initialize the program with stack, there is a strong likelihood of congestion on the
program, meaning the program as if struck. If you are using a kind of Proteus 8.0 simulator.
The program will run without error, but when it attempted to program the actual circuit will
stop (stuck). Here are excerpts of the program to initialize the stack at the end of RAM space
(RAMEND).

Because STACK on 16bit or 2byte ATMega32 size, then charging SP performed


twice for SP and SP Low or High SPL or SPH. Function Low () and High () are utilized for
each division to get LOW or HIGH RAMEND of variables stored in the " m32def. INC ".
Completion of registers in the AVR cannot be exercised immediately, in this case through the
TEMP variable and then proceeded to the SPL and SPH. This applies also to the following
related explanation.

12

SEE 3223

Since we are using the AVR microcontroller, it is compelled to specify a PORT as


input or outputs, if each bit in the register DDRx given a value of '1 ' means the consequence
(if '0 ' as an input). Because it uses registers used PORTA DDRA (writing to DDRA (out
ddra, temp) can not be directly, so use variable TEMP ( ldi temp , 0b01111111 ) :

;-----------port initial--------------------ldi
temp,0b11111111 ;set semua bit register temp
out
ddra,temp
;tuliskan ke register DDRA

Furthermore, the main program is written:


;--------portb telah di seting menjadi keluaran -----ldi
sec
putar:
out
rcall
ror
rjmp

temp,led ;isi register temp dengan led7


;set carry flag (agar carry=1, LED mati)
porta,temp
tunda
temp
putar

;hantar data ke porta (LED)


;delay 0.25 s
;putar satu bit ke kanan melalui carry
;lompat ke label putar

Data stored on the variable TEMP (ldi temp, LED), then the newly issued to PORTA
(out porta, temp), can not be directly sent to PORTA. Furthermore, the main program is
written:Repetition is done by skipping backward to the labels 'rotate' use rjmp swivel.
The last portion of the program is just about 0:25 seconds delay subroutine (see the complete
program listing) by using the AVR program Loop Delay Generator, as screen shoot shown in
Figure 2.
It uses repetition registers, 0:25 Sec delay would not be exact, but tolerable for any
delay shortly. If we want accurate, use the facilities Timer / Counter on AVR microcontroller
is concerned.

13

SEE 3223

More programs as follows (remember to terminate the program with. Exit)


;-----------------------------------------;LED running lights
;untuk microcontroller Atmel AVR ATMega32
;frequensi kristal 8MHz
;-----------------------------------------.nolist
.include "m32def.inc"
.list
;----------constant and initial register
.equ
led=0b01111111 ;portb-7 on
.def
temp=r16
;temp for R16
;====== program utama ====================
.cseg
.org
0000
;initial program code at address 0x0000
;address SP - Stack Pointer
;initial SP on RCALL
;if not the program will HANG.
ldi temp,low(ramend)
out spl,temp
ldi temp,high(ramend)
out sph,temp
;----------- port initial--------------------ldi
temp,0b11111111
;set all bit register temp
out
ddra,temp
;write to register DDRA
;--------setting portb as output -----ldi
temp,led
;put register temp with led7
sec
;set carry flag (carry=1, LED OFF)
putar:
out
porta,temp
;sent data to porta (LED)
rcall tunda
;delay 0.25 s
ror
temp
;rotate one bit al right through carry
rjmp
putar
;jump to label putar
; =============================
;
delay loop generator
;
1843200 cycles:
;
for freq 8MHz
;
delay by 0.25 s
; ----------------------------; delaying 1843182 cycles:
tunda:
ldi R17, $12
WGLOOP0: ldi R18, $A1
WGLOOP1: ldi R19, $D3
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
; ----------------------------; delaying 18 cycles:
ldi R17, $06
WGLOOP3: dec R17
brne WGLOOP3
; =============================
ret
; =============================
.exit
;end program

14

Вам также может понравиться