Question: I am having probelms with the question below. I've attached two attempts at solving the problem. I think attempt number two is going to be

I am having probelms with the question below. I've attached two attempts at solving the problem. I think attempt number two is going to be closer to correct. The code is written in assembly .asm. You can see from attempt two that the code i am struggling to write is checking the value of portb is equal to 7 and incrementing a variable named count. In addition, I am slightly confused as to how to return from an interrupt.

Write an interrupt service routine (ISR) that does the following:

Stores the contents of the W register into a variable named WCopy

Stores the contents of the STATUS register into a variable named StatCopy

Checks to see if the value on PORTB is equal to 7, if it is, increment a variable named COUNT

Restore the value of the STATUS register

Restore the value of the W register

Return from interrupt

Attempt1:

MOVWF W_TEMP ;Copy W to TEMP register

SWAPF STATUS,W ;Swap status to be saved into W

;Swaps are used because they do not affect the status bits

MOVWF STATUS_TEMP ;Save status to bank zero STATUS_TEMP register

:

:(ISR) ;Insert user code here

:

SWAPF STATUS_TEMP,W ;Swap STATUS_TEMP register into W

;(sets bank to original state)

MOVWF STATUS ;Move W into STATUS register

SWAPF W_TEMP,F ;Swap W_TEMP

SWAPF W_TEMP,W ;Swap W_TEMP into W

ATTEMPT2:

ORG

WCopy EQU 0x21

StatCopy EQU 0x22

COUNT EQU 0X23

MOVWF WCopy ;Copy W to WCopy register

SWAPF STATUS,W ;Swap status to be saved into W

;Swaps are used because they do not affect the status bits

MOVWF StatCopy ;Save status to bank zero StatCopy register

WRITE CODE HERE ;Check to see if the value on portb is equal to 7

WRITE CODE HERE ;If it is increment a variable named COUNT

;where would by return from interrupt go?

SWAPF StatCopy,W ;Swap StatCopy register into W

;(sets bank to original state)

MOVWF STATUS ;Move W into STATUS register

SWAPF WCopy,F ;Swap WCopy

SWAPF WCopy,W ;Swap WCopy into W

END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!