Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

2303ENG Programming Practice Questions

Information

These are some practice programming questions for the 2303ENG course. These questions are not representative
of the length of the exam questions but are designed to challenge and extend your knowledge. All the material has
been covered in the lectures. All the peripherals and parameters used can be found in the datasheet.

Answers will not be supplied for these questions but you may discuss them with us once you have attempted the
question.

I strongly suggest that you write functions where possible to make your code easier to test. (The functions are also
useful in that you can reuse them in the other questions).

Questions

Question A

Write a function that takes a configuration string of the format given below and configures UART0 to the
parameters given.

Argument List: (baud_rate, Number_of_data_bits,Parity,Number_of_stop_bits, Clock_Divisor)

eg

configU0(115200,8,N,1,16) ; // 115200 baud, 8 bits, No parity, 1 stop bit, div16


configU0(38400,7,E,2,8) ; // 38400 baud, 7 bits, Even parity, 2 stop bits, div8
configU0(9600,7,O,1,16) ; // 9600 baud, 6 bits, Odd parity, 1 stop bit, div16

Question B

Write a program that uses the systick subsystem as the timer for a clock. The output of the clock should be
displayed on the terminal (via UART0) in the HH:MM:SS format.
Question C

Write a program to count and display on the terminal (via Uart0) the number of times the button 1 (SW1) has been
pressed since the program started. Use the interrupts on the GPIO subsystem to solve this question.

Question D

(i) Write a program to turn on LED D4 for 1 second when button SW1 is pressed. You should use a timer in one
shot mode.
(ii) Modify (i) to use an interrupt to detect when SW1 is pressed.

Question E

Write a program to flash LED D4 with a period of 1 second and a duty cycle of 25%. Hint: Use a timer or SysTick.

Question F

Write a program that reads a character from the terminal (via UART0) and uses any of the available SSI peripherals
in Freescale mode (SPO=0, SPH=0) to transmit the character and then display the character received by the same SSI
on the terminal (via UART0). This can be achieved by using a wire to connect the MISO pin to the MOSI pin which is
known as a loop back test. If all is working correctly then the terminal should display the character that was
transmitted by the SSI.

Question G

(i) Write a program that reads AIN1 and display it on the terminal (via UART0) when button SW1 is pressed.
Hint: use the ADC in Software trigger mode and use sequencer 3. You can test the program by wiring the
AIN1 to 3.3V and it should read the maximum value. Also check what the result when you wire AIN1 to
GND.
(ii) Write a program that reads the temperature and displays it on the terminal (via UART0) when button 1 is
pressed. Hint: use the ADC in Software trigger mode and use sequencer 3.

Question H

Write a program uses one I2C peripheral in Master mode to read a single character from another I2C peripheral in
Slave Mode This character should be displayed on the terminal (via UART0). The Slave I2C peripheral should always
send the Master a ‘U’ character when the master performs a read request from the slave.
The connection can be achieved by using a wire to connect the Master’s Data pin to the Slave’s Data pin. If all is
working correctly then the terminal should display the character that was transmitted by the slave.

You might also like