Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <p18F458.h> #define myPB1bit PORTBbits.RB1 #define myPB7bit PORTBbits.R

ID: 1846612 • Letter: #

Question

 #include <p18F458.h> #define myPB1bit PORTBbits.RB1 #define myPB7bit PORTBbits.RB7 void T0_ISR(void); void T1_ISR(void); #pragma interrupt chk_isr                                                 void chk_isr (void) {         if (INTCONbits.TMR0IF==1)                        T0_ISR();                                if(PIR1bits.TMR1IF==1)                   T1_ISR();                        } #pragma code My_HiPrio_Int=0x08 void My_HiPrio_Int (void) {   _asm     GOTO chk_isr   _endasm } #pragma code void main(void)   {     TRISBbits.TRISB1=0;      TRISBbits.TRISB7=0;      TRISC = 255;                     TRISD = 0;               T0CON=0x0;               TMR0H=0x35;              TMR0L=0x00;              T1CON=0x88;              TMR1H=0x35;              TMR1L=0x00;              INTCONbits.TMR0IF=0;             PIR1bits.TMR1IF=0;       INTCONbits.TMR0IE=1;             INTCONbits.TMR0IE=1;             T0CONbits.TMR0ON=1;      T1CONbits.TMR1ON=1;      INTCONbits.PEIE=1;     INTCONbits.GIE=1;       while(1)          {        PORTD=PORTC;           }   } void T0_ISR(void)   {     myPB1bit=~myPB1bit;      TMR0H=0x35;                      TMR0L=0x00;                      INTCONbits.TMR0IF=0;           } void T1_ISR(void)   {     myPB7bit=~myPB7bit;      TMR1H=0x35;                      TMR1L=0x00;                      PIR1bits.TMR1IF=0;     } 
   
(a) Show the loop in the code that keeps looping until interrupt comes.
(b) What happens if Timer0 interrupts happens?
(c) What happens after processing Timer0 interrupt?
(d) What happens if Timer1 interrupts happens?
(e) What happens after processing Timer1 interrupt?

Explanation / Answer

a.)

while(1)

{

PORTD=PORTC;

}

b.)

If a timer 0 interrupt is occured, TMR0IF is set and the instrucrion GOTO chk_isr is executed. and function chk_isr is called. Inside that it checks for TMR0IF and jumps to T0_ISR where PB1 bit is toggeled, timer 0 values are reloaded and the flag is cleared.

c.)

after the T0_ISR is executed, the while loop which has been stopped due to interrupt is again continued.

d.)

If a timer 1 interrupt is occured, TMR1IF is set and the instrucrion GOTO chk_isr is executed. and function chk_isr is called. Inside that it checks for TMR1IF and jumps to T1_ISR where PB7 bit is toggeled, timer 1 values are reloaded and the flag is cleared.

e.)

after the T1_ISR is executed, the while loop which has been stopped due to interrupt is again continued.

Please reply if any further explanation is reuired.:)