Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using MPLAB PIC 3 2 MM Curiousity Board Pressing S 2 at any point should toggle whether the LEDs are blinking. Pressing the switch the
Using MPLAB PICMM Curiousity Board Pressing S at any point should toggle whether the LEDs are blinking. Pressing the switch the first time pauses blinking; pressing it again restartsresumes blinking. When paused, one or both LEDs may be off, depending on the mode of operation described below.
Pressing S should change between three modes of operation, which are:
LEDs blinking simultaneously initial
Only LED blinking, with LED paused either on or off
Only LED blinking, with LED paused either on or off
Repeated presses of S should cycle between the modes in the order above then After leaving mode the program should return to mode Port Test with added stuff from Lecture
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
Including xch allows use of SFR names, bit masks, etc.
#include
main:
Configure IO portsLEDs on Port A & C; switches on Port B
sw zero, TRISA ## TRISA all PORTA bits output
sw zero, ANSELA ## ANSELA all PORTA bits digital
not t zero
sw t TRISB ## TRISB xFFFFFFFF all PORTB bits input
sw zero, ANSELB ## ANSELB all PORTB bits digital
sw zero, TRISC ## TRISC all PORTC bits output
sw zero, ANSELC ## ANSELC all PORTC bits digital
li tPORTARAMASK ## tx control LED
li tPORTCRCMASK ## tx control LED
li tPORTBRBMASK ## tx saved state of S
li tPORTBRBMASK ## tx saved state of S
li t
Repeatedly read poll switches; turn on LED if button pressed;
turn off LED if button released
Start with state of S
pollS:
lw t PORTB ## Read Port B
andi t tPORTBRBMASK ## Check S
## If button isn't pressed, tx
## If button is pressed, tx
bne t zero, copyS ## If button not pressed RB
nop ## copy state and check S
beq t t pollS ## If button pressed but hasn't changed
nop ## check state of S
## Must be a new button presswait ~ sec and check it again
jal delay ## Call debounce function for delay
nop
## Check if button still pressed
lw t PORTB
andi t tPORTBRBMASK
bne t zero, copyS
nop
sw t LATAINV ## Toggle LED if this is a new button press
addi tt
div t
mfhi t
copyS:
add t t zero ## t saved state of S
Check state of S
pollS:
andi t tPORTBRBMASK ## Check S
bne t zero, copyS ## If button not pressed RB
nop ## copy state and go back to checking S
beq t t pollS ## If button pressed but hasn't changed
nop ## check state of S
## Must be a new button presswait ~ sec and check it again
jal delay ## Call debounce function for delay
nop
## Check if button still pressed
lw t PORTB
andi t tPORTBRBMASK
bne t zero, copyS
nop
sw t LATCINV ## Toggle LED if this is a new button press
copyS:
add t t zero ## t saved state of S
beq t toggle
nop
beq tpause
nop
toggle:
implement toggling
j pollS
nop
pause:
implement pause
j pollS
nop
j pollS ## Return to test S
nop
spin:
j spin
nop
end main
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 ## NOTE: This function originally branched
## to "done" if t zero, which means
## the delay loop was really no loop at all!
jr ra
nop
end delay
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