Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

On a PIC 3 2 MM Curiosity Development Board ( MIPS 3 2 ) using the following code as a template to: Initially, LEDs blink

On a PIC32MM Curiosity Development Board (MIPS 32) using the following code as a template to:
Initially, LEDs blink every 1.0 seconds.
Pressing S2 makes LEDs blink in 2.0 seconds.
Pressing S1 makes LEDs blink in 1.0 seconds again.
Pressing S1 makes LEDs pause blinking
// 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 ## Want INTCON bit 16(VS<0>)=1
## so vectors 8 bytes apart
ori t3, t3,_INTCON_MVEC_MASK ## Enable multivectored interrupt mode
sw t3, INTCON
li t3,_IPC2_T1IP_MASK ## Set T1 interrupt priority level to 7
sw t3, IPC2 ## Implicitly sets subpriority level to 0
li t3,_IPC2_CNBIP_MASK
sw t3, IPC2SET
li t2,_IFS0_T1IF_MASK ## t2= bit mask for checking Timer 1 interrupt flag
sw t2, IEC0 ## Enable Timer 1 interrupts (uses
## same bit mask as T1 interrupt flag)
li t2,_IEC0_CNBIE_MASK
sw t2, IEC0SET
add t3, t4, zero ## Set bits in CNEN1B =1 and CNEN0B =0
or t3, t3, t6 ## corresponding to switch positions
sw t3, CNEN1B ## (t4= S1 bit mask; t6= S2 bit mask)
sw zero, CNEN0B ## Will detect falling edges on these pins
li t3,_CNCONB_ON_MASK ## Enables Port B change notification
ori t3, t3,_CNCONB_CNSTYLE_MASK ## Enables edge detection
sw t3, CNCONB
ei ## Enable interrupts globally
li t3,_T1CON_TON_MASK ## Enable Timer 1 by setting "ON" bit in T1CON
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 ## Set delay counter to 0x61A8=25,000
## Since loop body has 3 instructions,
## loop takes 25,000*3=75,000
## cycles
## Remaining 3 instructions take 3 cycles
## ~75,000 cycles /8 MHz clock ~ 0.009375 sec delay
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
//////////////////////////////////////////////////////////////////////////
// Handle Port B change interrupt--check switches and toggle appropriate LEDs
.global isrvector9
.ent isrvector9
isrvector9:
li t4,_PORTB_RB7_MASK ## t4=0x00000080--> mask for S1
li t6,_PORTB_RB13_MASK ## t6=0x00002000--> mask for S2
// Check S1
lw t8, CNFB
and t9, t8, t4
beq t9, zero, checkS2 ## If bit 7=0, S1 wasn't pressed
nop
// S1 pressed--clear flag, then debounce and toggle if actually pressed
sw t4, CNFBCLR ## Clear flag for S1
jal delay ## Delay to debounce
nop

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_2

Step: 3

blur-text-image_3

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

=+h. Hourly wages of assembly line workers.

Answered: 1 week ago

Question

=+What do you want them to think?

Answered: 1 week ago

Question

=+Why should they buy this product/service?

Answered: 1 week ago