Книга: Advanced PIC Microcontroller Projects in C

4.5 Exercises

4.5 Exercises

1. Write a function to calculate the circumference of a rectangle. The function should receive the two sides of the rectangle as floating point numbers and return the circumference as a floating point number.

2. Write a main program to use the function you developed in Exercise 1. Find the circumference of a rectangle whose sides are 2.3cm and 5.6cm. Store the result in a floating point number called MyResult.

3. Write a function to convert inches to centimeters. The function should receive inches as a floating point number and then calculate the equivalent centimeters.

4. Write a main program to use the function you developed in Exercise 3. Convert 12.5 inches into centimeters and store the result as a floating point number.

5. An LED is connected to port pin RB0 of a PIC18F452-type microcontroller through a current limiting resistor in current sinking mode. Write a program to flash the LED in five-second intervals.

6. Eight LEDs are connected to PORTB of a PIC18F452-type microcontroller. Write a program so that the LEDs count up in binary sequence with a one-second delay between outputs.

7. An LED is connected to port pin RB7 of a PIC18F452 microcontroller. Write a program to flash the LED such that the ON time is five seconds, and the OFF time is three seconds.

8. A text-based LCD is connected to a PIC18F452-type microcontroller in 4-bit data mode. Write a program that will display a count from 0 to 255 on the LCD with a one-second interval between counts.

9. A text-based LCD is connected to a PIC microcontroller as in Exercise 8. Write a program to display the text “Exercise 9” on the first row of the LCD.

10. Repeat Exercise 9 but display the message on the first row, starting from column 3 of the LCD.

11. A two-row text-based LCD is connected to a PIC18F452-type microcontroller in 4-bit-data mode. Write a program to display the text “COUNTS:” on row 1 and then to count repeatedly from 1 to 100 on row 2 with two-second intervals.

12. Write a program to calculate the trigonometric cosine of angles from 0 to 45 in steps of 1 and store the results in a floating point array.

13. Write a function to calculate and return the length of the hypotenuse of a right-angle triangle, given its two sides. Show how you can use the function in a main program to calculate the hypotenuse of a right-angle triangle whose two sides are 4.0cm and 5.0cm.

14. Write a program to configure port pin RB2 of a PIC18F452 microcontroller as the RS232 serial output port. Send character “X” to this port at 4800 baud.

15. Port RB0 of a PIC18F452 microcontroller is configured as the RS232 serial output port. Write a program to send out string “SERIAL” at 9600 baud.

16. Repeat Exercise 15 but use the hardware USART available on the microcontroller chip.

17. Explain the differences between software-implemented serial data communication and USART hardware-based serial communication.

18. Write a function to add two arrays that are passed to the function as arguments. Store the sum in one of these arrays.

19. Write a function to perform the following operations on two-dimensional matrices:

 a) Add matrices

 b) Subtract matrices

 c) Multiply matrices

20. Write a function to convert between polar and rectangular coordinates.

21. Write functions to convert temperature expressed in Celsius to Fahrenheit and vice versa. Show how these functions can be called from main programs to convert 20°C to °F and also 100°F to °C.

22. Write a program to store the value of function f(x) in an array as x is varied from 0 to 10 in steps of 0.5. Assume that:

f(x) = 1.3x? – 2.5x? + 3.1x – 4.5

Оглавление книги


Генерация: 0.053. Запросов К БД/Cache: 0 / 2
поделиться
Вверх Вниз