You are on page 1of 5

Tutorial No.

: 3
Tutorial Name: 7-segment display



Content: page
1. Bill of Materials --------------------------------------------------- 3
2. Circuit connection------------------------------------------------- 4
2.1 Proteus components------------------------------------------4
3. Code----------------------------------------------------------------- 5

1-Bill of Materials:
# Name Quantity
1 ATmega16A-pu 40pin 1
2 Crystal Oscillator 8MHz 1
3 Resistance 10K 1
4 Resistance 330 14
5 22pF Capacitor 2
6 7 segment display (comm. anode) 2
7 7447 BCD-to-Seven-Segment
Decoder
2















2- Circuit Connection:














2.1 Proteus components:
1. ATmega16.
2. Resistance.
3. Capacitor.
4. Crystal.
5. 7 seg-comm. Anode .
6. 7447 bcd to 7 seg decoder.



3- Code:

#ifndef F_CPU
#define F_CPU 8000000UL // "set the clock to 8MHz"
#endif


#include <avr/io.h> //io.h is AVR ports Header file
#include <util/delay.h> //delay.h is Delay Function Header file
#include <avr/iom16.h> //iom16.h is atmega16 ports Header file


int main(void)
{
unsigned int count=0,count1=0; //Initialize two variables to act as
//two counters

DDRC=0xff; // SET ALL PORTC pins as Output
DDRD=0xff; // SET ALL PORTD pins as Output
PORTD=0x00; // Initialize PORTC to zero
PORTC=0x00; // Initialize PORTD to zero


while(1)
{count++; // Increase the value of "count" by one
_delay_ms(50); // delay by 50ms to see the increment
if (count==10) // check if "count" reach number 10
{count=0; // set it's value back to zero
count1++;} // then increase the value of "count1" by one
if (count1==10) // check if "count1" reach number 10
{count1=0; // set it's value back to zero
}

PORTD=count; //Assign the value of "count" to PORTD
PORTC=count1; //Assign the value of "count1" to PORTC

}

}

You might also like