Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Program 11-3C (Page 438 or PDF p. 452), you see when Timer 0 and Timer 1 overflows, the ISR (Interrupt Service Routine) are like

In Program 11-3C (Page 438 or PDF p. 452), you see when Timer 0 and Timer 1 overflows, the ISR (Interrupt Service Routine) are like below:

#include #define myPB6bit PORTBbits.RB6

void chk_isr(void); 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 = 0x0008

void My_HiPrio_Int(void) { _asm GOTO chk_isr _endasm }

#pragma code

void main(void) { TRISBbits.TRISB6 =0; TRISCbits.TRISC0 =1; TRISD =0; T0CON = 0x08; TMR0H = 0; TMR0L = 0; T1CON = 0x06; TMR0H = 255; TMR0L = -200; INTCONbits.TMR0IF = 0; PIR1bits.TMR1IF = 0; INTCONbits.TMR0IE =1; PIE1bits.TMR1IE = 1; T0CONbits.TMR0ON =1; T1CONbits.TMR1ON =1; INTCONbits.PEIE =1; INTCONbits.GIE =1; while(1); }

void T0_ISR(void) { PORTD++; TMR0H=0; TMR0L=0; INTCONbits.TMR0IF=0; }

void T1_ISR(void) { myPB6bit = ~ myPB6bit; TMR1H=255; TMR1L=-200; PIR1bits.TMR2IF=0; }

A.

Here PORTD++ increments PORTD as 0, 1, 2, 3, , until 255,and then 0, 1, again etc. for every timer 0 overflow (from FFFG 0r 65535 to 0).

Modify the code to add a switch SW so that

When SW = 0, PORTD increments 0, 1, 2, , 255, 0, 1, 2, , etc.

When SW = 1, PORTD increments by 2 as: 0, 2, 4, 6, , 252, 254, 0, 2, 4, 6, etc.

B.

Modify the code of program 11-3C to have T0_ISR called every 100 ms (milliseconds). Show the calculation.

C.

Further modify the code of program 11-3C so that the first call of T0_ISR has PORTD = 1; the second call of T0_ISR has PORTD = 10 binary = 2 decimal = 0x2, etc. (then PORTS = 4; PORTD = 8; until PORTD = 128 for next T0_ISR call, followed by PORTD = 1; etc.)

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

Step: 3

blur-text-image

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

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

How is social networking used in informal training?

Answered: 1 week ago

Question

Question Who can establish a Keogh retirement plan?

Answered: 1 week ago