Problem 5. (20 points), Clocks Time, Timers Consider the following code segment.
ID: 3729585 • Letter: P
Question
Problem 5. (20 points), Clocks Time, Timers Consider the following code segment. Assume that 1. while (1) processor clock in the active mode is set to 1,000,000 Hz. int ii for (i = 2000; i>0; i-); II one loop iteration takes 5 clock cycles // Set P3.5 / Delay /I Clear P3.5 for ( 2000; i0 i-- A. (5 points) What does the code segment do assuming that P3.5 is configured as a digital output. You may ignore delay needed to execute instructions in lines 1, 4 and 6. B. (5 points) What will happen if you connect P3.5 to the buzzer? C. (10 points) How would you implement functionality achieved by the code segment above using TimerB. Port P3.5 is multiplexed with the output signal from the capture and compare block 4 of TimerB. Give details. How would you initialize the system? What would you do in the main loop?Explanation / Answer
Answer
given by
a)
This code is congregation P3.5 high for a little time and then low designed for some time.
the delay in requisites of clock cycles =2000*5 =10000 clock cycles
since workstation frequency is 1000000 hz.
Delay time =10000/1000000 s = 0.01s =10ms
hence the code is production P3.5 high for 10ms and then low for 10ms
b)
if you tie it to a buzzer. the buzzer will beep
c)
in timer select proper clock source. TBCTL record put the value to add up in TBCCR0 register and facilitate the timer.
the main way would look like
while(1)
{
P3OUT |= BIT5; // Set P3.5
while (timer overflows);
P3OUT &= ~BIT5; // Clear P3.5
while (timer overflows);
}