HW3

advertisement
STM32 PROGRAMMING IN C
SECTION A: DATA TYPES IN C
Note: For all exercises, assume that the GPIOs are 8-bit wide, unless otherwise stated.
1. Consider for this exercise you can choose among these data types.
Size
8
16
32
64
8
16
32
64
Signed
Unsigned
Data type
uint8_t
uint16_t
uint32_t
uint64_t
int8_t
int16_t
int32_t
int64_t
Range of values
a) Find the range of values for each data type.
b) Indicate what data type you would use for the following variables:
1)
2)
3)
4)
5)
6)
7)
8)
9)
the temperature
the number of days in a week
the number of days in a year
the number of students in the ITESM CEM
the Mexican population
the world population
an address of 64K RAM space
an address of 4G RAM space
the difference between the number of persons
entering and leaving Mexico during the year
2. Give the hex value that is sent to the GPIO for each of the following C statements:
(a) GPIOB=14;
(b) GPIOB=0x18;
(c) GPIOB='A';
(d) GPIOB=7;
(e) GPIOB=32;
(f) GPIOB=0x45;
(g) GPIOB=255;
(h) GPIOB=0x0F;
SECTION B: LOGIC OPERATIONS IN C
3. Indicate the data on the GPIOs for each of the following:
Note: The operations are independent of each other.
(a) GPIOB=0xF4&0x45;
(b) GPIOB=0xF4&0x56;
(c) GPIOB=0xF4^0x76;
(d) GPIOA=0xF4&0x90;
(e) GPIOA=0xF4^0x90;
(f) GPIOA=0xF4|0x90;
(g) GPIOA=0xF4|0xFF;
(h) GPIOA=0xF4|0x99;
(i) GPIOA=0xF4^0xEE;
(j) GPIOA=0xF4^0xAA;
4. Find the contents of the GPIO after each of the following operations:
(a) GPIOB=0x66&Ox76;
(b) GPIOB=0x71|0x6B;
(c) GPIOA=0x96^0xAA;
(d) GPIOA=0x5E&0x78;
(e) GPIOA=0xC6|0x12;
(f) GPIOE=0x6B^0x6E;
(g) GPIOB=0x38|0x26;
5. Find the GPIO value after each of the following is executed:
(a) GPIOB=0x66>>2;
(b) GPIOA=0x3A<<2;
(c) GPIOB=0xD6>>3;
(d) GPIOB=0xA8<<2;
SECTION C: I/O BIT MANIPULATION AND DATA SERIALIZATION C
6. Elaborate a C statement to set only PC1 (GPIOC BIT 1), without affecting the other port bits, using masks
and bitwise operators.
7. Elaborate a C statement to clear only PC7 (GPIOC BIT 7).
8. Elaborate a C statement to set only PC2 (GPIOC BIT 2) and PC4 (GPIOC BIT 4).
9. Elaborate a C statement to clear only PC3 (GPIOC BIT 3) and PC5 (GPIOC BIT 5).
10. Express in C the following: if (PC7 == 0 and PC4 == 1) then PA1 = 0;
11. Express in C the following: if (PB3 == 1 or PB2 == 0) then PC2 =0 else PC2=1;
12. Elaborate a C statement to toggle bits PA1 and PA7.
13. Elaborate a C statement to toggle only bit PA0.
14. Write a C program to count up GPIOA from 0-99 continuously.
SECTION D: I/O BIT MANIPULATION AND DATA SERIALIZATION C ON 32-BIT GPIOs
Repeat Section C exercises assuming that the GPIOs are 32-bit wide.
Download