Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions