Engr2105 Lab3
Engr2105 Lab3
Engr2105 Lab3
Abstract
The Atmel ATiny2313/4313 microcontroller was used to program a 7-segment display as a stop
clock. This helped to better familiarize with the I/O interfacing capabilities of the Atmel
ATtiny2313/4313 microcontroller. This also gave the opportunity to understand timing in
assembly and C programming and multiplexing digital signals
Introduction
There are many programming languages used to design and implement digital circuits. Two of
such programming languages used are assembly (more outdated) and C (more popular). These
codes can be programmed on a microcontroller. A microcontroller (MCU) is a compact
integrated circuit designed to govern a specific operation in an embedded system.
Microcontrollers come in many shapes and sizes depending on its need. For example: for a small
operation like designing a stop clock, an Atmel ATiny2313/4313 can be used; or for a bigger
operation like automated robot., which requires more I/O ports and memory to implement.
To become familiar with timing and digital multiplexing using assembly and C
To write assembly and C code for implementing the 7-segemt stop clock.
To become familiar with the I/O interfacing capabilities of the Atmel ATtiny2313/4313
microcontroller
To program the MCU to run the 7-segment stop clock
Results
.ORG 0
LDI R16, 0xFF
OUT DDRB, R16
OUT DDRD, R17
M: RCALL DELAY
SBIC PinD,2
RJMP M
RET
ISR (INT0_vect){
if (!(PIND & (1<<2)))
{
count++;
if (count==2)
count=0;
_delay_ms(20);
int main()
{
PORTB = 0x3F;
while (1){
for (i=cnt2;i<10;i++){
cnt2=i;
if (count==1){
PORTB = num[i];
_delay_ms(1000);
}
else
break;
if (count==0){
_delay_ms(1000);
}
if (i==10)
{cnt2=0;}
}
return 0;
}
ISR (INT0_vect){
int main()
{
while (1){
for (i=cnt2;i<100;i++){
cnt2=i;
if (count==1){
for (y=0;y<50;y++) {
_delay_ms(10);
j=i/10;
PORTD &= ~(1<<4);
PORTD |= (1<<5);
PORTB=num[j];
_delay_ms(10);
z=i%10;
PORTD |= (1<<4);
PORTD &= ~(1<<5);
PORTB=num[z];
}
}
else
break;
if (count==0){
PORTD |= (1<<4);
PORTD &= ~(1<<5);
PORTB=num[z];
_delay_ms(10);
}
if (i==100)
{cnt2=0;}
return 0;
}
Discussion
The MCU used a operation called polling to check whether the button was pressed or not. While
polling, the CPU constantly inspects the status of the system to find whether it meets the
requirements. In the case of the button, it keeps running the while loops to check if the button
was pressed; this results in a waste of CPU cycles. In other to mitigate that, interrupts can be
used. When using interrupts, the system informs the CPU that it met the requirement without
constantly checking. In the case of the button, as it is pressed, the interrupt is instantly triggered
and fetched before the next completes.
Literature cited
No literature cited.