REPORT
REPORT
ELHADJI DIOP
李哈杰
Gu Song
INTRODUCTION:
Microcontroller Units, commonly known as MCU, are compact integrated circuits that function
as a miniaturized computer system on a single chip. These small yet powerful devices are designed
to execute specific tasks and control various electronic systems. They consist of a processor core,
memory, and input/output (IO) peripherals, making them highly suitable for embedded
applications.
The primary objective of this training week is to gain proficiency in utilizing different features of
an MCU to accomplish specific goals. These goals include:
1. Controlling LEDs using IO Ports: Understanding and utilizing IO ports to manipulate LEDs, a
fundamental task in embedded systems.
2. Arranging Tasks with Interrupt Routines: Learning to implement interrupt routines, enabling
efficient task arrangement and responsiveness to external events.
4. Capturing External Interrupts: Mastering the capability to capture and respond to external
interrupts, expanding the MCU's responsiveness to real-world events.
5. Serial Communication with Other Systems: Establishing communication with external systems
using serial communication, a vital skill for data exchange between different devices.
By the end of this training, a solid foundation in these essential MCU functionalities will be
established, empowering the achievement of more complex and innovative embedded projects.
Our board(DK107Sv2.2):
During our training week we will use the Dake DK107S board v2.2, which is a very special board.
Based on its datasheet we can see that several parts of the board are connected to the P0 port of our
IAP15F2K61S2 chip and therefore to use certain part of the board it will be necessary to mention the
address of the part concerned.
CHIP IAP15F2K61S2
Controlling of LEDs:
This first task is divided into two subtasks: controlling simple LED and displaying digital
number.
Controlling simple LED:
In this subtask, we have to make L1 switch on for about 2 seconds. Then switch off L1 and
switch on L2 for about 2 seconds, and so on. (from L1 to L8).
For this we begin by defining necessary variables and including the required header files. The
`delay()` function is defined to introduce a time delay in the program.
In the `main()` function, the variable `temp` is initialized with the value `0x7F`,
representing a binary pattern to control the LEDs connected to Port 0 (P0). The value of `temp`
is then assigned to P0, lighting up the corresponding LEDs. A delay of 1000 milliseconds is
introduced using the `delay()` function.
Inside the infinite `while` loop, the code iterates through a `for` loop eight times, each time
shifting the bits in `temp` one position to the left using the `_crol_` function from the
`intrins.h` library. The updated value of `temp` is then assigned to P0, displaying the new
LED pattern. Additionally, P2 is momentarily set to 0x80 and then set to 0x00, which related
to choose the Output Y4 for control our LED. A longer delay of 20000 milliseconds is
introduced before the next iteration of the loop.
Overall, this code achieves a simple LED animation effect by shifting the lit LED pattern to the
left in a continuous loop.
In the `main()` function, an infinite loop is established. Inside the loop, another loop iterates
from 0 to 9. During each iteration, the value of `i` is used as an index to select the appropriate
binary code from `leddata[]`. The selected code is then sent to Port 0 (P0), which is connected
MCU TRAINING WEEK
3
to the seven-segment display.
Before and after displaying a digit, P2 is briefly set to certain values (0xE0 and 0xC0), which
related to controlling other of the display of the digital numerical leds.
Overall, the code continuously cycles through digits 0 to 9, displaying them on the seven-
segment display with a delay of 20000 milliseconds between each digit.
In the main function, there is an infinite loop that continuously checks for the `timerFlag`.
When the flag is set, the program enters a loop to display digits 1 to 8 on the seven-segment
display with a short delay between each digit. The`timerFlag` function provides an approximate
2-second delay.
After displaying a digit, the program turns on all the LEDs by setting P0 to 0x00, then sets P2 to
0x80 and 0x00. Finally, it sets P0 to 0xFF to turn off all the LEDs, again followed by the P2
setting. This sequence is repeated for each digit, and the timer flag is reset after displaying all the
digits.
MCU TRAINING WEEK
4
Overall, the code achieves a sequential display of digits on the seven-segment LED display using
a timer interrupt for accurate timing and control.
Make my own kind
For this task, I chose to turn on the LEDs whose position is odd (1,3,5,7) and turn off the others and
do this in turn. For this work, we change the program of the previous subtask and replace the the
values of P0, 0x00 by 0xAA and 0xFF by 0x55.
Keyboard
For this task, we have to execute one of the last four different subtasks according to the button
pressed by the executor but we have encountered some problems in the execution of this task.
This is how the task has been replaced by a simpler task to know if the first is to press all the LEDs
lights up, if it is the button 2 all the LEDs goes out, the three the first four only lights up and for the
fourth button only the last four LEDs light up.
For this, we build a KeyScan() function who’ll check which button is pressed
The `KeyScan()` function continuously scans the keypad by sequentially setting each row to 0 and
checking if any key is pressed. If a key is detected, it determines its position using the column pins.
The corresponding `KeyValue` is updated accordingly to represent the pressed key.
In the `main()` function, the program enters an infinite loop where it continuously calls
`KeyScan()` to detect any key press. Depending on the value of `KeyValue`, the program performs
different actions:
Serial Communication
For this task, we had to write a code that allows communication between our board and our machine
but unfortunately we could not finish this task. Nevertheless, we were able to complete part of this
task thanks to the help of a SUMEN classmate.
Firstly We define two functions which are The `SendData()` and `SendString()` functions,
whose send data and strings respectively via UART. The `UartInit()` function initializes UART
communication with a specific baud rate.
In the `main()` function, "OK" and the hexadecimal value 0x4F are sent over UART. The code
then enters an infinite loop, continuously scanning the keypad. If a specific key (determined by
`KeyValue`) is pressed, a response is sent over UART, and certain actions are taken, like turning
on or off LEDs connected to P0 and P2.
Additionally, the code implements an ISR (Interrupt Service Routine) for UART communication,
handling both receiving (`RI` flag) and transmitting (`TI` flag) data.
MCU TRAINING WEEK
6
CONCLUSION
Throughout the MCU training week, I gained valuable insights and practical experience in working
with microcontroller units. I successfully achieved my goals, which included using IO ports to
control LEDs, implementing interrupt routines for task arrangement, utilizing timers for task
synchronization, capturing external interrupts, and establishing serial communication with other
systems. This hands-on experience has deepened my understanding of microcontroller functionality
and their applications in embedded systems. I am now well-equipped to undertake more complex
and innovative projects, leveraging the full potential of microcontroller units.