(8%) Consider Program 11-2C on pages 435 and 436 Look at these lines of code fro
ID: 3552492 • Letter: #
Question
(8%) Consider Program 11-2C on pages 435 and 436
Look at these lines of code from this program
T0CON=0x0;
TMR0H=0x35;
TMR0L=0x00;
T1CON=0x88;
TMR1H=0x35;
TMR1L=0x00;
Suppose XTAL = 10M Hz, compute how long in milliseconds (or microseconds) it takes for Timer 0 to interrupt. Compute also how long it takes for Timer 1 to interrupt.
Repeat part (a) with XTAL = 16M Hz now.
(12%) Consider now Program 11-3C on pages 437 and 438.
Some lines of code for timer configuration and count are as follows:
T0CON=0x08;
TMR0H=0;
TMR0L=0;
T1CON=0x06;
TMR1H=255;
TMR1L=-200;
Near the top of page 437, it is stated that program11-3C has two interrupts: (1) PORTC counts up every time Timer0 overflows and (2) a 1-Hz pulse is fed into Timer 1 used as a counter. When the count reaches 200, it will toggle pin RB6.
Explain why the code of program11-3C toggles pin RB6 when timer 1 count reaches 200. Note you may need to use 1 or 2 lines of code not shown above. You do not have to explain the chk_isr, T0_ISR, T1_ISR functions and also the My_HiPrio_Int function with the #pragma code etc.
With the code of program 11-3C, compute when Timer0 overflows (in milliseconds) and also when Timer1 overflows.
Is it possible to change code so that Timer 1 toggles RB6 when it reaches count 400? If so, how? If not, why?
Explanation / Answer
timer0 =0x3500 or 13568 in decimal
so now count tis incresed from 0x3500to 0xFFFF ---> 65535-13568=51877 counts
T0CON =0x0 hence it is in 16 bit mode with prescalar of 1:2
we know that The CPU clock speed is the oscillator speed divided by four. also it will be divided by prescalar
clock frequency = (XTAL/4)/2 =XTAL/8
time taken by timer0 to interrupt = 51877 /(XTAL/8)
= 415016/XTAL
now XTAL = 10 Mhz
time taken by timer0 to interrupt= 415016/10000000 s = 41.5016 ms
count tis incresed from 0x3500 to 0xFFFF ---> 65535-13568=51877 counts
T1CON =0x88
hence timer1 is started with 16bit mode and no prescalar
clock frequency = (XTAL/4) =XTAL/4
time taken by timer0 to interrupt = 51877 /(XTAL/4)
= 207508/XTAL
now XTAL = 10 Mhz
time taken by timer1 to interrupt= 207508/10000000 s = 20.7508ms
2 Xtal =16Mhz
time for timer0 = 415016/16000000 = 25.9385 ms
time for timer1 = 207508/16000000 = 12.96925 ms
2.
1.
Note that TMR1H =255 and TML1H =-200
-200 in hex =0x38
hence TIMER1 counts from 0xFF38 to 0xFFFF which is 199 counts nearly equal to 200 counts
When the timer1 overflows a interrupt is triggered. The program would jump to TIMER1 Interrupt Service Routine.where the PIN RB6 is toggled.
2
Timer 0 counts from 0 to 65535 = 65535 counts
T0CON=0x08; timer 0 16 bit mode prescalar off.
clock frequency = (XTAL/4) =XTAL/4
time taken by timer0 to interrupt = 65535/(XTAL/4)
= 262140/XTAL
Assuming XTAL = 10 Mhz for second question
time taken by timer1 to interrupt= 262140/10000000 s = 26.214 ms
timer 1 counts 200 counts
external sourc =1 HZ
time taken =200/1 = 200sec
3
yes it is possible we just want timer1 to have 400 counts hence timer1 = 65535-400 =65135 =0xFE6F in hex
hence
TMR1H=0xFE
TMR1L=0x6F
for 400 count
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.