Answered step by step
Verified Expert Solution
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 PICMM Curiosity Development Board MIPS using the following code as a template to:
Initially, LEDs blink every seconds.
Pressing S makes LEDs blink in seconds.
Pressing S makes LEDs blink in seconds again.
Pressing S makes LEDs pause blinking
Including xch allows use of SFR names, bit masks, etc.
#include
Interrupt vector setup
globl vectordispatch ## Port B change notification vector #
section vector code, keep
align
set nomips
ent vectordispatch
vectordispatch:
j isrvector ## Jump to actual ISR code, which is in text section
nop
end vectordispatch
size vectordispatchvectordispatch
globl vectordispatch ## Timer interrupt vector #
section vector code, keep
align
set nomips
ent vectordispatch
vectordispatch:
j isrvector ## Jump to actual ISR code, which is in text section
nop
end vectordispatch
size vectordispatchvectordispatch
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 all PORTA bits output
sw zero, ANSELA ## ANSELA all PORTA bits digital
li tPORTBRBMASK
ori t tPORTBRBMASK
sw t TRISB ## TRISB x pins & inputs
sw zero, ANSELB ## ANSELB all PORTB bits digital
sw zero, TRISC ## TRISC all PORTC bits output
sw zero, ANSELC ## ANSELC all PORTC bits digital
Configure Timer
sw zero, TCON ## Clear TCONdisables timer to allow setup
The desired initial delay is sec between interrupts
ADD TIMER SETTINGS PRESCALE and PR TO GET THE DESIRED DELAY
Configure interrupts
lui tx ## Want INTCON bit VS
## so vectors bytes apart
ori t tINTCONMVECMASK ## Enable multivectored interrupt mode
sw t INTCON
li tIPCTIPMASK ## Set T interrupt priority level to
sw t IPC ## Implicitly sets subpriority level to
li tIPCCNBIPMASK
sw t IPCSET
li tIFSTIFMASK ## t bit mask for checking Timer interrupt flag
sw t IEC ## Enable Timer interrupts uses
## same bit mask as T interrupt flag
li tIECCNBIEMASK
sw t IECSET
add t t zero ## Set bits in CNENB and CNENB
or t t t ## corresponding to switch positions
sw t CNENB ## t S bit mask; t S bit mask
sw zero, CNENB ## Will detect falling edges on these pins
li tCNCONBONMASK ## Enables Port B change notification
ori t tCNCONBCNSTYLEMASK ## Enables edge detection
sw t CNCONB
ei ## Enable interrupts globally
li tTCONTONMASK ## Enable Timer by setting ON bit in TCON
sw t TCONSET
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 txA ## Set delay counter to xA
## Since loop body has instructions,
## loop takes
## cycles
## Remaining instructions take cycles
## ~ cycles MHz clock ~ sec delay
loop:
addi t t ## Decrement counter
bne t zero, loop ## and continue doing that until we hit
nop
jr ra
nop
end delay
Handle Port B change interruptcheck switches and toggle appropriate LEDs
global isrvector
ent isrvector
isrvector:
li tPORTBRBMASK ## tx mask for S
li tPORTBRBMASK ## tx mask for S
Check S
lw t CNFB
and t t t
beq t zero, checkS ## If bit S wasn't pressed
nop
S pressedclear flag, then debounce and toggle if actually pressed
sw t CNFBCLR ## Clear flag for S
jal delay ## Delay to debounce
nop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started