Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN I GET AN DETAILED EXPLANATION OF THIS CODE LIKE WHAT IT DOES AND HOW IT WORKS Code: SIM_SCGC5 EQU 0x40048038 ;SIM_SCGC5 address SIM_COPC EQU

CAN I GET AN DETAILED EXPLANATION OF THIS CODE LIKE WHAT IT DOES AND HOW IT WORKS

Code:

SIM_SCGC5 EQU 0x40048038 ;SIM_SCGC5 address

SIM_COPC EQU 0x40048100 ;SIM_COPC (watchdog) address

PORTA_PCR4 EQU 0x40049010 ;PORTA_PCR4 (PTA4) address

PORTA_PCR2 EQU 0x40049008 ;PORTA_PCR2 (PTA2) address

PORTA_PCR5 EQU 0x40049014 ;PORTA_PCR5 (PTA5) address

PORTC_PCR7 EQU 0x4004B01C ;PORTA_PCR7 (PTC7) address

PORTC_PDDR EQU 0x400FF094

PORTC_PDIR EQU 0x400FF090

PORTA_PDDR EQU 0x400FF014

PORTA_PDOR EQU 0x400FF000

YELLOW_MASK EQU 0x00000010 ; PORTA_PIN 4

GREEN_MASK EQU 0x00000004 ; PORTA_PIN 2

RED_MASK EQU 0x00000020 ; PORTA_PIN 5

INIT_MASKS EQU 0x00000034 ; PORTA_PIN 2, 4 and 5

BUTTON_MASK EQU 0X00000080 ; PORTC_PIN 7

DELAY_CNT EQU 0X00800000

AREA asm_area, CODE, READONLY

EXPORT asm_main

asm_main ;assembly language entry point for C function, do not delete ; Add program code here

BL init_gpio

loop

BL greenon

LDR R0, =DELAY_CNT

BL delay

BL redon

LDR R0, =DELAY_CNT

BL delay

BL yellowon

LDR R0, =DELAY_CNT

BL delay

B loop

redon

LDR R0,=PORTA_PDOR ;Load address of PORTA_PDOR to R0

LDR R1,=RED_MASK ;Load value to R1

STR R1,[R0]. ;Put value into PORTA_PDOR

BX LR

greenon

LDR R0,=PORTA_PDOR. ;Load address of PORTA_PDOR to R0

LDR R1,=GREEN_MASK ;Load value to R1

STR R1,[R0] ;Put value into the PORTA_PDOR

BX LR

yellowon

LDR R0,=PORTA_PDOR. ;Load address of PORTA_PDOR to R0

LDR R1,=YELLOW_MASK ;Load value to R1

STR R1,[R0] ;Put value into the PORTA_PDOR

BX LR

delay

SUBS R0, #10

BNE delay

BX LR

init_gpio ;Disable watchdog timer (COP)

LDR R0,=SIM_COPC

LDR R1,=0x0

STR R1,[R0] ;Turns on the clocks for all ports

LDR R0,=SIM_SCGC5 ;Load address of SIM_SCGC5 to R0

LDR R1,[R0] ;Get original value of SIM_SCGC5

LDR R2,=0x00003E00 ;Load mask for bits to set to R2

ORRS R1,R2 ;Set bits with OR of orig val and mask

STR R1,[R0] ;Put new value back into SIM_SCGC5

; Setup the PORTA Pins 2,4 and 5 to be outputs

LDR R0,=PORTA_PDDR ;Load the address of PORTA_PDDR to R0

LDR R1,=INIT_MASKS ;Load new value to R1

STR R1,[R0] ;Put value into the PORTA_PDDR

; Setup the PORTC Pin 7 to be an input

LDR R0,=PORTC_PDDR ; Load the address of the PORTC_PDDR to R0

LDR R1,=BUTTON_MASK ;Load the new value to R1

STR R1,[R0] ;Put value into the PORTC_PDDR

BX LR

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions