Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MODIFICATIONS TO MAKE: You must change this program so that: - Initially, the LEDs blink simultaneously every 1 . 0 seconds. - Pressing switches will

MODIFICATIONS TO MAKE:
You must change this program so that:
- Initially, the LEDs blink simultaneously every 1.0 seconds.
- Pressing switches will change the timer period by 1.0 seconds, either faster (by pressing S1) or slower (by pressing S2).
- Given the timer configuration and 1.0 seconds of the adjustment period, there are only three modes: 0 second period (i.e., pause),1 second period, and 2 second period.
// Including xc.h allows use of SFR names, bit masks, etc.
#include
// Interrupt vector setup
.globl __vector_dispatch_9 ## Port B change notification = vector #9
.section .vector_9, code, keep
.align 2
.set nomips16
.ent __vector_dispatch_9
__vector_dispatch_9:
j isrvector9 ## Jump to actual ISR code, which is in text section
nop
.end __vector_dispatch_9
.size __vector_dispatch_9,.-__vector_dispatch_9
.globl __vector_dispatch_11 ## Timer 1 interrupt = vector #11
.section .vector_11, code, keep
.align 2
.set nomips16
.ent __vector_dispatch_11
__vector_dispatch_11:
j isrvector11 ## Jump to actual ISR code, which is in text section
nop
.end __vector_dispatch_11
.size __vector_dispatch_11,.-__vector_dispatch_11
// Start of text section
.text ## Text section contains code
.set noreorder ## Disable instruction reordering
.globl main ## Define main label as a global entity
.ent main ## and an entry point
main:
// Configure port A for output
sw zero, TRISA ## TRISA =0--> all PORTA bits = output
sw zero, ANSELA ## ANSELA =0--> all PORTA bits digital
li t0,_PORTB_RB7_MASK
ori t0, t0,_PORTB_RB13_MASK
sw t0, TRISB ## TRISB =0x00002080--> pins 7 & 13 inputs
sw zero, ANSELB ## ANSELB =0--> all PORTB bits digital
sw zero, TRISC ## TRISC =0--> all PORTC bits = output
sw zero, ANSELC ## ANSELC =0--> all PORTC bits digital
// Configure Timer 1
sw zero, T1CON ## Clear T1CON--disables timer to allow setup
/***
The desired initial delay is 0.5 sec between interrupts
ADD TIMER SETTINGS (PRESCALE and PR1) TO GET THE DESIRED DELAY
***/
// Configure interrupts
lui t3,0x0001
ori t3, t3,_INTCON_MVEC_MASK
sw t3, INTCON
li t3,_IPC2_T1IP_MASK
sw t3, IPC2
li t3,_IPC2_CNBIP_MASK
sw t3, IPC2SET
li t2,_IFS0_T1IF_MASK
sw t2, IEC0
li t2,_IEC0_CNBIE_MASK
sw t2, IEC0SET
add t3, t4, zero
or t3, t3, t6
sw t3, CNEN1B
sw zero, CNEN0B
li t3,_CNCONB_ON_MASK
ori t3, t3,_CNCONB_CNSTYLE_MASK
sw t3, CNCONB
ei
li t3,_T1CON_TON_MASK
sw t3, T1CONSET
// Main loop: doing nothing, just waiting for an interrupt
mainloop:
j mainloop
nop
.end main
// Delay loop for switch debouncing
.global delay
.ent delay
delay:
li t7,0x61A8
loop:
addi t7, t7,-1 ## Decrement counter
bne t7, zero, loop ## and continue doing that until we hit 0
nop
jr ra
nop
.end delay
.global isrvector9
.ent isrvector9
isrvector9:
li t4,_PORTB_RB7_MASK
li t6,_PORTB_RB13_MASK
// Check S1
lw t8, CNFB
and t9, t8, t4
beq t9, zero, checkS2
nop
// S1 pressed--clear flag, then debounce and toggle if actually pressed
sw t4, CNFBCLR
jal delay
nop
lw t2, PORTB
and t2, t2, t4
bne t2, zero, checkS2
nop
// ADD routine when a new S1 press
// Check S2
checkS2:
and t9, t8, t6
beq t9, zero, int9done
nop
// S2 pressed--clear flag, then debounce and toggle if actually pressed
sw t6, CNFBCLR
jal delay
nop
lw t2, PORTB
and t2, t2, t6
bne t2, zero, int9done
nop
// ADD routine when a new S2 press
int9done:
li t3,_IFS0_CNBIF_MASK ## Clear Port B change notification flag
sw t3, IFS0CLR ## in IFS0
eret ## Return from interrupt
.end isrvector9
.global isrvector11
.ent isrvector11
isrvector11:
li t2,_IFS0_T1IF_MASK
sw t2, IFS0CLR
modify BEHAVIOR TO IMPLEMENT THE LED STATES DESCRIBED ABOVE ***/
li t0,_PORTA_RA0_MASK
li t1,_PORTC_RC9_MASK
int11done:
eret
.end isrvector11
image text in transcribed

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

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions