Page 1 of 6
University of the West Indies
Faculty of Engineering
ENGR2105
Engineering Laboratory and Design III
Laboratory #3
7-Segment LED Stop Clock in Assembly and C
Laboratory date: March X, 2021
Deadline for presentation of working circuit and Lab report: March X, 2021
Faculty of Engineering, UWI, Mona ENGR2105 Lecturer: Lindon Falconer
Page 2 of 6
Introduction
In this experiment, students will use the ATtiny2313/4313 microcontroller (MCU) to create a one-digit
and two-digit digital stop clock that increments at one-second intervals. The electronic clock is designed
with a microcontroller, a push-button and one or two 7-segment LEDs.
Objectives
This laboratory objective is for the student to become familiar with the I/O interfacing capabilities of the
Atmel ATtiny2313/4313 microcontroller, understand timing in assembly and C programming languages,
and multiplex digital signals realtime.
Specifications
1. When the circuit is powered on, it should display “0” continuously.
2. When the push button is pressed, the counter should start counting from “0” – “9” at a rate of
one second. When the count reaches “9”, it should reset to “0” and continue counting.
3. If the push button is pressed again (the second time after power-on), the counter should stop at
the last digit that was displayed.
4. If the push button is pressed for a third time, the counter should continue counting from the
number that was on display.
Faculty of Engineering, UWI, Mona ENGR2105 Lecturer: Lindon Falconer
Page 3 of 6
Pre-Laboratory Preparations
1. Review ECSE2104 Lectures 11 to 15 and Chapters 0 – 7 of text “M. A. Mazidi, S. Naimi, and S.
Naimi, The AVR Microcontroller and Embedded System: Using Assembly and C. New Jersey, USA:
Pearson Education, 2011.”
2. Acquire and become familiar with the LSD3221 7-Segment LED display datasheet.
3. Acquire the datasheet for the Attiny2313/ATtiny4313 and become familiar with its pin-out and
microcontroller’s features.
Components and Equipment
Components Quantity Supplied by Equipment Supplied by
ATtiny2313/ATtiny4313 1 Student Atmel AVR Programmer Student/Department
Microcontroller
7-Segment Common 2 Student Computer loaded with Student/Department
Cathode LED Display (LSD- Atmel Studio 6 or 7
C302RI)
220 or 330 Ω Resistor 7 Student
10k Ω Resistor 2 Student
Push Button 1 Student
Breadboard 1 Student
+5V Power Supply 1 Student
Connecting wires Student
Procedures
1. Using the datasheets for the LDS-C302RI Common Cathode 7-Segment LED display and the
ATTiny2313/4313 and the diagram in Figure 1, draw the schematic diagram for the one digits stop
clock circuit.
2. Ensure the internal oscillator of the microcontroller is set to 1 MHz.
3. Implement the circuit on breadboard.
Faculty of Engineering, UWI, Mona ENGR2105 Lecturer: Lindon Falconer
Page 4 of 6
VCC
10k ATTiny2313 or 4313
7 x 220Ω
VCC RESET PB0
VCC PB1
10k VCC PB2
PB3
PD2 (INT0) PB4
Push
Button PB5
GND PB6
Common cathode
Figure 1: Schematic diagram of a one-digit digital stop clock
Faculty of Engineering, UWI, Mona ENGR2105 Lecturer: Lindon Falconer
Page 5 of 6
1 One-Digit Stop Clock Assembly Language
Programming
1. You will use the assembly routine (function) in Figure 2 to implement a delay of “one second” on
the MCU. In the code ‘a’, ‘b’ and ‘c’ are variables that control the loops in the routine so that
the one second delay is achieved.
2. Derive a formula in terms of variables ‘a’, ‘b’ and ‘c’ that indicates the number of machine cycles
required to execute the delay routine in Figure 2.
3. From the formula derived in 2, and the time for one machine cycle select values for variables ‘a’,
‘b’ and ‘c’ that will enable the assembly function in Figure 2 to implement a delay of one second.
Show all working.
DELAY: LDI R16,c
L1: LDI R17,b
L2: LDI R18,a
L3: NOP
NOP
NOP
NOP
DEC R18
BRNE L3
DEC R17
BRNE L2
DEC R16
BRNE L1
RET
Figure 2: Assembly code routing for generating 1-second delay
4. Using the delay routine and information provided above, write an assembly language program
that implements the one-digit digital stop clock.
5. The stop clock should operate as follows:
a. When the circuit is powered on, it should display “0” continuously.
b. When the push button is pressed, the counter should start counting from “0” – “9” at a
rate of one second. When the count reaches “9”, it should reset to “0” and continue
counting.
c. If the push button is pressed again (the second time after power-on), the counter should
stop at the last digit that was displayed.
d. If the push button is pressed for a third time, the counter should continue counting from
the number that was on display.
Faculty of Engineering, UWI, Mona ENGR2105 Lecturer: Lindon Falconer
Page 6 of 6
6. Verify your code works by typing it in Atmel Studio, generating the hex file, and downloading it
to the attiny2313/attiny2413 microcontroller.
7. Ensure you demonstrate the working circuit to the Lecturer or the Lab Administrator.
2 One Digit Stop Clock C-Language Programming
1. Implement the same one-second one-digit stop clock using the AVR C programming language.
The program should use external interrupt INT0 to detect the button press, and Timer1 output
compare interrupt to implement a one-second timing.
2. Verify that your code works by typing it in Atmel Studio, generating the hex file, and
downloading it to the attiny2313/4313 microcontroller.
3. Ensure that you demonstrate the working system to the Lecturer or the Lab Administrator.
3 Two Digits Digital Stop Clock
1. Modify the schematic in Figure 1 to include a second 7-Segment LED. The data lines (PB0-PB6)
should be shared (multiplexed) between the two 7-segment LEDs. Connect PD6 and PD7 to the
cathode of 7-Segment LEDs one and two, respectively; these will serve as control lines. Draw
the modified schematic of the circuit and place it in your report.
2. Implement the circuit on your development board.
3. Write a C-program that implements a two-digit stop clock. The clock should operate as
described in Section 1.5; however, it will count from 0 to 99 and back to 0.
4. Ensure that you demonstrate the working system to the Lecturer or the Lab Administrator.
4 Presentation and File Upload
A laboratory report must be written in the standard format for course ENGR2105. The report must
contain the final assembly and C programs that were used in the demonstration. The document for the
report must be given a file name in the following format ENGR2105_LAB3_IDNUMBER.pdf and uploaded
to the ENGVLE website in the LAB3 Solution folder.
The deadline for uploading the file is March X, 2021, at 11:59 PM.
Faculty of Engineering, UWI, Mona ENGR2105 Lecturer: Lindon Falconer