Anda di halaman 1dari 6

;===========================================================================

; Lab_2_1_student.s - Template for DAT Lab 2_2


;
; Description : A more complete template for Lab 2_2
; Reference(s) : ARM IAR Assembler Reference Guide
; Course
: Datorteknik (DAT) DT4009
;
; Authors
: Sleyman Savas
;
;
;===========================================================================
NAME
main
PUBLIC main
SECTION .text : CODE (2)
THUMB
;===========================================================================
; TODO: Find and add the correct addresses,
; Check sam3x datasheet - chapter 30 to find the addresses.
PIOA_WPMR EQU 0x400E0EE4
; Write Protect Mode Register
PIOA_PER
PIOA_ODR
PIOA_IDR
PIOA_PUER
PIOA_PDSR

EQU
EQU
EQU
EQU
EQU

0x400E0E00
0x400E0E14
0x400E0E44
0x400E0E64
0x400E0E3C

;0x0000
;0x0014
;0x0044
;0x0064
;0x003C

;
;
;
;
;

PIO Enable Register


Output Disable Register
Interrupt Disable Register
Pull Up Enable Register
Pin Data Status Register

; C port - (leds)
PIOC_WPMR EQU 0x400E12E4

; Write Protect Mode Register

PIOC_PER
PIOC_OER
PIOC_SODR
PIOC_PUDR
PIOC_CODR
PIOC_ODSR

;0x0000
;0x0010
;0x0030
;0x0060
;0x0034

EQU
EQU
EQU
EQU
EQU
EQU

0x400E1200
0x400E1210
0x400E1230
0x400E1260
0x400E1234
0x400E1238

; PIO Enable Register - Arduino Due


; Output Enable Register
; Set Output Data Register
; Pull Up Disable Register
; Clear Output Data Register

; PMC
PMC_WPMR EQU

0x400E06E4

; PMC Write Protect Mode Register

PMC_PCER EQU
PMC_PCDR EQU
PMC_PCSR EQU

0x400E0610
0x400E0614
0x400E0618

; Peripheral Clock Enable Register 0


; Peripheral Clock Disable Register 0
; Peripheral Clock Status Register 0

;===========================================================================

; Initialization of Peripheral Clock


main
LDR R0,=PMC_PCER

LDR
STR

R1,=(5 << 11) ; Peripheral Identifier: bit11=PIOA, bit13=PIOC


R1,[R0]

;===========================================================================
; Initialization InPort
; TODO: Write your code here
LDR

R1, =0xC000

LDR R0,=PIOA_PDSR ; Adress till PortA:s dataregister


Data Status Register)
STR R1,[R0]
; Lser frn adress i R1 till R0

PIO_PDSR (Pin

LDR R0,=PIOA_PER
STR R1,[R0]
LDR R0,=PIOA_ODR
STR R1,[R0]
LDR R0,=PIOA_IDR
STR R1,[R0]
LDR R0,=PIOA_PUER
STR R1,[R0]

; En evig loop
;===========================================================================
; Initialization OutPort
; TODO: Write your code here
LDR
R1, =0xE

er

//Grna DLED 0011

LDR R0,=PIOC_PER
PIO_PDSR (Pin Data Status Register)
STR R1,[R0]
LDR R0,=PIOC_OER
STR R1,[R0]
LDR R0,=PIOC_SODR
STR R1,[R0]
LDR R0,=PIOC_PUDR
STR R1,[R0]
LDR R0,=PIOC_CODR

; Adress till PortA:s dataregist


; Lser frn adress i R1 till R0

STR R1,[R0]
LDR R0,=PIOC_ODSR
STR R1,[R0]
;===========================================================================
; Turn LED off
; TODO: Write your code here
;===========================================================================
; Main program
; TODO: Write your code here
;LOOP

//Huvudprogram "evig loop"


//Lser av knapparna
;Huvudprogram ------------------------------------read
;Both
BL Read_p0
CMP R3, #0
BNE Vidare
LDR R7,=0x000000E
BL Led

;0x00000010

0000 0002

;===========================================================================
vnsta knapp
Vidare
BL Read_p0
CMP R0, #0 ; Ej tryckt => 1:a
BNE Vidare2
LDR R7,=0x00000002 ;0x00000010
BL Led
;LDR R7,=1000
;BL Delay_ms

knapp
0000 0002

LDR R7,=0x00000004 ;0x00000010


BL Led
LDR R7,=0x00000008 ;0x00000010
BL Led
;LDR R7,=1000
;BL Delay_ms
;===========================================================================
hgra knapp
Vidare2
BL Read_p0
CMP R2, #0 ; Ej tryckt => 1:a
hgra knapp
BNE read
LDR R7,=0x8 ;0x00000010
BL Led
;LDR R7,=1000

0000 0002

;BL Delay_ms
LDR R7,=0x4 ;0x00000010
BL Led
LDR R7,=0x2 ;0x00000010
BL Led

/*
LDR R7,=0x000000E
3 bitar ska motsvara de tre lysdioderna.
BL Led

;Mnstret i R7:s lgsta

LDR R7,=1000
BL Delay_ms */
/* BL Read_p0
CMP R0, #0 ; Ej tryckt => 1:a
BNE read
LDR R7,=1000;11111111 ;1000 ;Mnstret i R7:s lgsta 3 bitar ska mots
vara de tre lysdioderna.
;innehller hur lng tid (i
ms) som subrutinen ska ta
BL Delay_ms
;stackpointer 0x20008000
;0x20007FF8*/

;loop

B read
B loop

Led
r

;den ska tnda resp. slcka lysdiode


STMFD SP!,{R2}
; Istllet fr Rl skriver du de register du anvnder
MOV R2,R7
;R7 skall anvndas som inparameter till funktionen
/*LDR R1,=PIOC_ODSR ; PIO PortC Output Status Register
LDR R0,[R1]
AND R0, R0,R2 ;#0x000000E ; Maska av bit 1-3*/
LDR R1,=PIOC_SODR ; PIO PortC Set Output Data Register
STR R2,[R1] ; R0 skrivs tillbaks, ettstller nollor
; LDR R7,=1000
; BL Delay_ms

LDR R1,=PIOC_CODR ; PIO PortC Clear Output Data Register

STR R2,[R1] ; R0 skrivs tillbaks, nollstller ettor


//EOR R0, R0,R2 ;#0xE ; Inventera bit 1-3
LDMFD SP!,{R2}
;Tnk p att spara undan de regis
ter som anvnds inuti funktionen.
; Istllet fr Rl skriver du de register du anvnder
BX LR
DELAY_CALIB EQU 1200;22222222

;1200

Delay_ms
STMFD SP!,{R0,R1} ;lr 200702EB
MOV R0,R7
do_delay_ms
som r inparameter
LDR R1,=DELAY_CALIB
loop_ms
SUBS R1,R1,#1
BNE loop_ms
SUBS R0,R0,#1
BNE do_delay_ms
LDMFD SP!,{R0,R1}
BX LR
Read_p0
app (USR_RIGHT) p port A.
STMFD SP!,{R1}
LDR R1,=PIOA_PDSR
LDR R0,[R1]
AND R2, R0, #0x00008000
uell knapp hgra knapp
AND R0, R0, #0x00004000
AND R0, R0, #0x0000C000
LDMFD SP!,{R1}
BX LR

;den yttre rknar upp till det tal


;Den inre loopen tar precis 1 ms

;0x200702FC
;Subrutinen Read_p0 lser av en kn

;#0x00008000 ; bitmaska fram akt


; vnsra knapp
;Both

;===========================================================================
STOP

B STOP
END

; Subrutin Delay_ms ---------------------------------------; Vnta ett antal ms


; Inparameter: R7 - delay i ms
; --------------------------------------------------------/*
DELAY_CALIB EQU 1200 ; utprovat vrde (baserat p master clock 12Mhz)
Delay_ms
STMFD SP!,{R0,R1}
MOV R0,R7
do_delay_ms
LDR R1,=DELAY_CALIB
loop_ms
SUBS R1,R1,#1
BNE loop_ms
SUBS R0,R0,#1
BNE do_delay_ms
LDMFD SP!,{R0,R1}
BX LR
; -------------------------------------------------------------------------------------------------------------------Subrutin Read_p0 --------------------------------------; Avlsning av knapp i subrutin
; Utparametrar: R0
; -----------------------------------------------------Read_p0
STMFD SP!,{R1}
LDR R1,=PIOA_PDSR
LDR R0,[R1]
AND R0,R0,#0x00008000 ; bitmaska fram aktuell knapp
LDMFD SP!,{R1}
BX LR
; -----------------------------------------------------; Huvudprogram ------------------------------------read
BL Read_p0
CMP R0, #0 ; Ej tryckt => 1:a
BNE read
LDR R7,=1000
BL Delay_ms
Loop
B loop
; ------------------------------------------------------------------*/