Write an alternative 1-bit output statement that has the same effect, assuming all the port bits are initially 0.. Describe briefly the difference between a WHILE loop, a DO..WHILE loop,
Trang 1BÀI TẬP CHƯƠNG 3
1 List the syntax features that a minimal C program must contain if compiled for the PIC16F877A MCU
2 List the steps required to create and test a C program for a PIC MCU prior to downloading to hardware
3 Write a C statement that outputs the 8-bit value 6410 to Port C Write an alternative 1-bit output statement that has the same effect, assuming all the port bits are initially 0
4 Describe briefly the difference between a WHILE loop, a DO WHILE loop, and a FOR loop
5 Describe the effect of the following statements on active high LEDs connected to Port D,
assuming an active low switch circuit is connected to pin RC7:
output_D(255); delay_ms(1000);
while(!input(PIN_C7)) { output_D(15); }
output_D(0);
6 Calculate the highest positive number that can be represented by the following variable types: (a) 8-bit unsigned integer, (b) 16-bit signed integer, (c) 32-bit floating point number
7 Estimate the degree of precision provided by the following numerical types as a percentage, to two significant figures: (a) 8-bit integer, (b) 32-bit FP number
8 Work out the value of the FP number represented by the binary code
1000 0010 0011 0000 0000 0000 0000 0000
9 Write a C statement to convert numbers 0 to 9 to their ASCII hex code, using variables ‘n’ for the number and ‘a’ for the ASCII code and send it to serial LCD
10 State the result of each of these operations in decimal and 4-bit binary, if n=5 and m=7 :
(a) n++
(b) ~m
(c) n&m
(d) n|m
(e) n^m
11 State the effect of the jump commands continue, break, and goto label when used within a program loop
12 A menu is required with a choice of three options to be selected by a numerical variable x=1, 2,
3 Each option is implemented in a separate function, funx() Write a C code section to show how switch can be used to implement the menu
13 Explain why the use of local variables is preferable in C programs designed for microcontrollers with limited RAM
14 Explain how the use of functions leads to well-structured C programs and the benefits of this design approach
15 State the meaning of the source code items that are underlined:
int out(int16 t)
{
int16 n;
while (input(PIN_D0))
Trang 2{ outbyte++ ;
for(n=1;n<t;n++ );
}
return outbyte;
}
16 Explain the meaning of each component of the statement printf("%d " , anum[n]);
17 Explain the significance of the & and * operators in C
18 State the function of the compiler directives:
(a) #include
(b) #define
(c) #use
(d) #device
(e) #asm
19 Describe the effect of the following statements on active high LEDs connected to Port D, assuming an active low switch circuit is connected to pin RC7:
output_D(255); delay_ms(1000);
while(!input(PIN_C7)) { output_D(15); }
output_D(0);
20 Calculate the highest positive number that can be represented by the following variable types:
(a) 8-bit unsigned integer, (b) 16-bit signed integer, (c) 32-bit floating point number
21 State the meaning of the source code items that are underlined:
int out(int16 t)
{
int16 n;
while (input(PIN_D0))
{ outbyte++ ;
for(n=1;n<t;n++ );
}
return outbyte;
}
22 A menu is required with a choice of three options to be selected by a numerical variable x=1, 2,
3 Each option is implemented in a separate function, funx() Write a C code section to show how switch can be used to implement the menu