Download Programming 8-bit PIC Microcontrollers in C 2008
Transcript
260
Answers
4. The WHILE loop tests the control condition before the loop statements are
executed. The DO..WHILE tests after they have been executed at least once. The
FOR loop executes a loop a fixed number of times.
5.
Port D bits initially go on for 1 sec. If the switch is active, the high 4 bits then
go off, and the program waits until the switch goes inactive, at which point all
the outputs go off. If the switch is inactive, all the LEDs go off after 1 sec.
6.
(a) 255
7.
(a) 8-bit precision 1/28 100% 0.39%.
(b) 32-bit FP precision 1/223 100% 0.000012%.
8.
Mantissa 011 → 1 4 1 8 0.25 0.125 0.375 → 1.375.
Exponent 1000 0010 130 → 130 127 3 → 23 8.
Sign 0 → positive.
Number 8 1.375 11.000000.
(b) 32,767
(c) (2 – 1/223) 2128 6.8 1038
9. a = n + 0x30;
putc(a);
10.
11.
n 5 01012, m 7 01112.
(a) 6, 0110 (b) 8, 1000 (c) 5, 0101
(d) 7, 0111
(e) 2, 0010
Continue means restart a loop, Break means quit a loop, Goto means jump to
a label unconditionally.
12. switch(x)
{
case 1: fun1();
break;
case 2: fun2();
break;
case 3: fun3();
break;
}
13.
Local variables are allocated memory only when a function is called and are
discarded when the function has finished. The memory can then be used for
other purposes, saving on overall memory requirements.
14.
Functions are self-contained blocks that implement a clearly defined set of
operations, receiving data for processing and returning results to the calling
routine. A structured program is a nested or hierarchical set of functions that
www.n ewn es p res s .c o m
Exm-H8960.indd 260
6/10/2008 9:40:27 AM