the platform draws 0.5 mA. 1. while(1) { 2. int i; 3. for(i = 2000; i>0; i--); /
ID: 3552486 • Letter: T
Question
the platform draws 0.5 mA.
1. while(1) {
2. int i;
3. for(i = 2000; i>0; i--); // one loop iteration takes 5 clock cycles
4. P3OUT |= BIT5; // Set P3.5
5. for (i = 2000; i>0; i--); // Delay
6. P3OUT &= ~BIT5; // Clear P3.5
7. }
1).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.
2).What will happen if you connect P3.5 at the buzzer?
3). 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
a) this code is making P3.5 high for sometime and then low for some time.
the delay in terms of clock cycles =2000*5 =10000 clock cycles
since processor frequency is 1000000 hz.
delay time =10000/1000000 s = 0.01s =10ms
hence the code is making P3.5 high for 10ms and then low for 10ms
b) if you connect it to a buzzer. the buzzer will beep
c)in timerB select proper clock source. TBCTL register put the value to count in TBCCR0 register and enable the timer.
them main method would look like
while(1)
{
P3OUT |= BIT5; // Set P3.5
while(timer overflows);
P3OUT &= ~BIT5; // Clear P3.5
while(timer overflows);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.