PLP LED lights not going off after cycles of interrupts

0

I am Coding in PLP MIPS Assembly Language
I'm having trouble figuring out how to trigger a Timer interrupt (Every 200 cycles) .

Right Now it is been triggered once all LEDs gets on but on off loop not working.

The Timer interrupt is suppose to flash the LEDs on every 200 cycles and then off after another 200 cycles and so forth. The seven segment display code is already provided for so what it does is just count up from 0-9 then A-F, and then starts over with the 10s. So 11, 12, ... , 19, 1A, 1B, ... , 1F, 20, etc.

My Code is:


.org 0x10000000

li $sp, 0x10fffffc  # Stack pointer initialization
li $s0, sseg_lut    # Lookup table address used by sseg_display
lui $s1, 0xf070 # Interrupt controller register
lui $s2, 0xf0a0 # Seven segment display


# ****************************
# TODO: enable interrupts below
# ****************************

li $t2, 0b1011 #value used to enable the used interrupts
li $t4, 0b00000000 #value used to check if LEDs are off
li $t5, 0b11111111 #value used to check if LEDs are on
li $t6, 0xf0600000 #address of the Timer
li $t7, 0xC8 #number of cycles we want the timer interrupt to be triggered 
li $t7, 0xffffffff
li $t8, 0xC8
subu $t7,$t7,$t8
sw $t7, 0($t6) #Store value onto timer in order to trigger interrupt
li $t8, 0xf0200000 #address of LEDs
sw $t2, 0($s1) #set mask register to enable the used interrupts including Global Interrupt Enable 
li $iv, isr #interrupt vector 




# NOTE: Do not add or modify any code within this main loop
main:
   jal sseg_display
   nop
   addiu $a0, $a0, 1
   j main
   nop


# ****************************************
# TODO: add interrupt service routine below
# ****************************************



isr: 
   save
   li $t0, 0b0011 #value used to check for timer interrupt
   li $t1, 0b1001 #value used to check for button interrupt
   lw $i0, 0($t8) #check what is stored currently on LEDs
   lw $i1, 4($s1) #load what value is in the status register
   j mainISR
   nop
   mainISR:
       beq $i1, $t0, timerInterrupt #check if the interrupt was triggered by timer
       nop

       timerInterrupt: 
           beq $t4, $i0, turnOnLEDs  #If the LEDs are off, go to the loop to turn them on
           nop
           bne $t5, $i0, turnOffLEDs  #If the LEDs are on, go to the loop to turn them off 
           nop
           turnOnLEDs:
               sw $t5, 0($t8) #Stores the value to the LEDs to turn them all on 
               li $i1, 0b1001 #Bits used to clear interrupt in status register 
               j endISR #Jump to the end of the isr 
               nop
           turnOffLEDs:
               sw $t4, 0($t8) #Stores the value to the LEDs to turn them all off 
               li $i1, 0b1001 #Bits used to clear interrup in status register 
               j endISR #Jump to the end of the isr 
               nop
      
   j mainISR #possibly unnecessary isr loop 
   nop
   endISR:
       sw $i1, 4($s1) #clear handled interrupts
       lw $i1, 0($s1) #get the mask register
       ori $i1, $i1, 1 #set Global Interrupt Enable
       restore
       jr $ir
       sw $i1, 0($s1) #resets all interrupts

# ************************************************************
assembly
timer
mips
interrupt
asked on Stack Overflow Nov 30, 2020 by HAMZA PERVAIZ • edited Nov 30, 2020 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0