ECET 340 WEEK 1 HOMEWORK
1. Indicate what data type you would use for the following variables:
(a) the temperature (signed char)
(b) the number of days in a week (unsigned char)
(c) the number of days in a year (unsigned char)
(d) the number of months in a year (unsigned char)
(e) the counter to keep the number of people getting on a bus (unsigned int)
(f) the counter to keep the number of people going to a class (unsigned char)
(g) an address of 64K RAM space (Unsigned int)
(h) the age of a person (unsigned char)
(i) a string for a message to welcome people to a building (unsigned int)
2. Give the hex value that is sent to the port for each of the following C statements:
(a) PORTB=14; (44)
(b) PORTB=0x18; (40, 38)
(c) PORTB=′A′; (A)
(d) PORTB=7; (37)
(e) PORTB=32; (62)
(f) PORTB=0x45; (70,35)
(g) PORTB=255; (FF)
(h) PORTB=0x0F; (15)
3. Give two factors that can affect time delay code size in the HCS12 microcontroller.
1. The crystal frequency connected to the HCS12 board is the most important factor in the time delay calculation. The duration of the clock period for the instruction cycle is a function of this crystal frequency.
2. The second factor that affects the time delay is the compiler used to compile the C program. When we program in Assembly language, we can control the exact instructions and their sequences used in the delay subroutine. In the case of C programs, it is the C compiler that converts the C statements and functions to Assembly language instructions. As a result, different compilers produce different code. In other words, if we compile a given C program with different compilers, each compiler produces different-size hex code.
4. Of the two factors in Problem 3, which can be set by the system designer?
The second, since we control the delay subroutine.
5. Can the programmer set the number of clock cycles used to execute an instruction? Explain your answer.
Yes, this can be done through...