Group 408 Short Report Microprocessor (Digital I.O and Timer)
Group 408 Short Report Microprocessor (Digital I.O and Timer)
SEEE3732-04
SESSION 2022/2023-1
SHORT REPORT
MICROPROCESSOR
DIGITAL INPUT/OUTPUT AND TIMER ON ATMEGA32
Group: 408
Group members:
No Name No. Matric
.
1. Alexander Wong Heng Yii A20EE0009
2. Fong Jun Xian A20EE0053
3. Mohammed A.M. Abujarad A19EE4071
4. Teo Jun Long A20EE0215
Date:
Title:
Objectives:
Equipment/Software/Reference:
(a) Project ‘Lab2Exp1’ was connected to the JTAGICE mkll and Target board.
(b) ‘Selected Debugger/programmer’ was selected as JTAGICE mkll and the Interface
was JTAG.
(c) The CPU frequency was ensured to be 1MHz.
Results:
Figure 1.2: Connection of ATmega32A Target Board
For Procedure 4:
So can use 8 bit, max 255 for timer0, And to chouse suitable prescalar we use this
table and this law :
Prescale Clock Time Timer Count For 8bit timers (Timer 0 & Timer 2)
r Period (Hz)
1 1 1999999 Not Suitable because Timer Count >
1000000 255
8 8 24999 Not Suitable because Timer Count >
1000000 255
64 64 3124 Not Suitable because Timer Count >
1000000 255
256 256 780.25 Not Suitable because Timer Count >
1000000 255
1024 1024 194.3215 Suitable, Timer Count < 255
1000000
By calculation
=194.3125
TCNT0 =255-194
Switch LEDs panel display requirement when respective button is selected Remarks
Pressed
No Time delay
switches for each
pressed blinking is
800ms
#State 0 #State 1
There was nothing shown on the 7-segment display since PORTA = 0 in the code.
The Pattern 1 was successfully displayed on LEDs indicated by PORTD which
$33 = 0b00110011 displayed at the first 400ms, then $CC= 0b11001100 displayed at
the next 400ms.
SW3 Time delay
for each
blinking is
400ms
Based on the preliminary exercise, Port D is initialised as an input port and $00 is loaded,
which implies all '0's in 8-bit binary in DDRD, making PORT1 a high-active pushbutton that,
when pressed, would send a 0 signal to ATMEGA32. Port A and Port B are initialised as
output ports and $FF is loaded, which signifies all '1's in 8-bit binary in both DDRB and
DDRA, and don't forget that all 7-segment and leds are high active, which means that when
the output is 0, they will be on and when it is 1, they will be off. Therefore, PIND is used as
the switch-like input pin register. The PD0-PD7 Circuit was toggled for the experiment.
In Procedure III, we utilised the code written in the preceding exercise to demonstrate the
outcome. According to Table 1, when no push button is touched, PIND is loaded with the
value 0b1111111 and PORTB is loaded with the values $92, $89, and $86, which correspond
to the letters 'S', 'K', and 'E' displayed on the 7-Segment LED Displays Panel. Since PORTA
is also loaded with $FF = 0b1111111, none of the LEDs on the 8xLED Board will illuminate.
For the situation where SW0 is pressed, the PD0 switch at Circuit is pressed and the PIND
variable is loaded with 0b11111110, as shown in the code. Since PORTD is loaded with $FE
= 0b11111110, the first LED of PORTA, PORTA[0], will light up and blink since $FE =
0b11111110 is assigned to PORTD. The 7-Segment LED Displays Panel connected to
PORTB will not display anything due to the absence of coding for PORTB in this
circumstance.
For the situation where SW1 is pressed, the PD1 switch in our circuit is pressed and the value
0b11111101 is loaded into PIND. Since PORTC is loaded with $0F = 0b11110000, the first
four LEDs of PORTA, namely PORTA[0], PORTC[1], PORTC[2], and PORTC[3, are on
and blinking. Similar to when SW0 is pressed, the 7-Segment LED Displays Panel connected
to PORTB will not display anything in this state, as there is no coding for PORTB.
Since there is a "else" in the coding, the 7-Segment LED Displays Panel and 8xLED Board
both gave the identical result for the scenario where SW2 and SW3 are pressed individually.
However, PIND is loaded with 0b11111011 and 0b11110111 since the pressed switches in
the Circuit are PD2 and PD3.
In process IV, the issue is posed to add a new function for a 200ms delay using timer0, thus
we begin by attempting to obtain the time count using the following law:
Then, we obtain 194 as the time count and write code in the manner shown in appendix A to
obtain the code displayed above. Therefore, the Delay200msUsingTimer0 function is
calculated and programmed. Due to the fact that the specified time delay is 200ms and the
system clock is 1MHz, we chose 1024 as the prescaler, as demonstrated by the Procedure IV
calculation result. After performing the computation, we chose the value 61 (255-194) for
TCNT0, which was then programmed into the code. To set the prescaler value, the code was
written as TCCR0 = (1<<CS02) | (1<<CS00). This portion utilises a while loop. The
following code is coded to wait until the TOV0 bit is set, which indicates overflow while
TCNT0 continues to count in the background. The TOV0 bit is cleared by writing 1 to it
when it is set. TIFR = TIFR | TIFR data is used to clear the TOV0 bit once more to ensure
that it is cleared.
In procedure V, the programme code is altered to produce Table 2's output. After the changed
software is put into the circuit, the 7-Segment LED Displays Panel will display SKEE3732-
408 in a sequence with a time interval of 800ms. This means that the letter 'S' will be
displayed first, followed by the letter 'K,' and so on until the entire string is displayed. This
procedure will repeat indefinitely until a switch is toggled or the power is cut to the circuit.
When PIND2 (switch 2) is toggled, the LEDs on the 8xLED Board will illuminate according
to pattern 1 as specified by the circuit. The first state containing LED2, LED3, LED6, and
LED7 will illuminate, as indicated by the code "PORTC = 0x33." The LED0, LED1, LED4,
and LED5 will then illuminate in the second state, as indicated by the code "PORTC =
0xCC." Each state has a 400ms time interval. This procedure will repeat indefinitely until a
switch is toggled or the power is cut to the circuit.
When PIND3 (switch 3) is toggled, the LED on the 8xLED Board will illuminate as
described in the labsheet (pattern 2). After the switch is toggled and turned on, LED3 and
LED4 will illuminate in the initial condition. The second state including LED2 and LED5
will illuminate next, followed by the third state containing LED1 and LED6, the fourth state
containing LED0 and LED7, the fifth state containing LED6 and LED1, the sixth state
containing LED5 and LED2, and the seventh state containing LED3 and LED4. Similar to the
preceding procedure, each state has a 400ms time period. This procedure will repeat
indefinitely until a switch is toggled or the power is cut to the circuit.
8.0 Conclusion
In summary, we have learned how to initialise the input and output ports and how to
programme a 7-Segment LED Displays Panel to display an alphabet, number, or symbol
before assembling it into a working circuit. The programming to create a time delay in Atmel
Studio comes last. We have gained more knowledge about the Atmega32 timer and digital
input/output through this project. Since we were able to collect all of the results, we can draw
the conclusion that the experiment's stated goals were met. When no push button is hit, we
were able to display the letters "S," "K," and "E" on the 7-Segment LED Displays Panel in
Procedure III. While the first LED of PORTA is on and blinking for the state of SW0. The
first four LEDs of PORTA are on and blinking for SW1 condition. We were able to write
coding in Procedure IV to produce a 200ms time delay after the calculation, allowing it to
function smoothly and precisely in this experiment. When no push button was used, we were
able to adjust the coding in Procedure V and have our group code, "SKEE3732-420," shown
at the 7-Segment LED Displays Panel. When SW2 was present, the LEDs lit up in the pattern
1 pattern displayed on the labsheet, while SW3 was present, the pattern 2 pattern showed on
the labsheet.