You are on page 1of 7

THE COLLEGE OF ELECTRICAL AND ELECTRONIC TECHNOLOGY

Embedded System Lab

Experiment #5

7 Seg Display

Purpose of Experiment:.
-Learn new tools used in the embedded systems and control it using AVR microcontrollers.

-Learn how to use 7-segment display and program AVR microcontroller to use it.

What is 7-segment display?


7segment "" is a seven-county -For a small rectangle contains 7 clips with luminous
diodes Light (available in red, green, blue). Used in the presentation Numbers and
some letters of English.
This piece is available in the electronic market in different sizes What is very
small, such as a Used in digital clocks cheap and what is a large size, such as used in
the Traffic lights (luminous painting that displays the time remaining to open the traffic
signal).
7-segment displays are available in two different configurations: common cathode and
common anode. in common cathode displays the cathodes of all the segment LEDs are
tied together and then this common point is connected to ground. A required segment is
then turned on by applying a logic 1 to the anode of this segment. Here, the output pin
of the microcontroller is in current sourcing mode .
In a common-anode display, the anodes of all the segment LEDs are tied together and
then this common point is connected to V supply voltage. A required segment is turned
on by applying a logic 0 to the cathode of this segment. Here, the output pin of the
microcontroller is in current sinking mode.

The following table contains the displayed number and data by using common cathode :

Prepared by: Eng. HUDA ELSUAYSI


‫كيف تعمل المقاطعة الخارجية‬
‫فً جمٌع المعالجات والمتحكمات الدقٌقة ٌتم تصمٌم الكود المسؤول عن معالجة المقاطعات بصورة مستقلة‬
‫تماما عن البرنامج )‪ . (main program‬فنجد دائما ا أن برنامج المقاطعة وٌسمى‬
‫)‪ (interrupt service Routing‬ويختصر بكلمة (‪ )ISR‬يكتب في جزء بعيد عن دالة‬
‫)(‪main‬فمثال ٌمكنك أن تكتب برنامج )‪ ) main‬لٌقوم بعمل محدد إلى االبد ثم تكتب برنامج ال ‪ISR‬‬
‫ليقىم بىظيفة هحذدة وسزيعة عنذ تشغيل حسبس أو سر هعين‪.‬‬
‫يوتلك الوتحكن الذقيق هن فئة ‪ ATMEGA328P‬عذد ‪ 3‬أطزاف الوقبطعة الخبرجية يوكن تىصيلهب بأي‬
‫حسبس أو هفتبح رقوي وهذه االطزاف هي‪:‬‬
‫)‪INT0 (pin 2 on port D‬‬

‫)‪INT1 (pin 3 on port D‬‬

‫عند ادخال اشارة رقمٌة على هذه االطراف تحدث المقاطعة ‪ .‬وعندها ٌترك المتحكم الدقٌق البرنامج‬
‫الرئٌسً الذي ٌنفذه و ٌنتقل الً برنامج ‪ ISR‬لٌقوم بمعالجة المقاطعة‪.‬‬

‫‪Prepared by: Eng. HUDA ELSUAYSI‬‬


‫الكود التالً ٌمثل التركٌب بسٌط لل ‪ ISR‬مع ال ‪. Main program‬‬

‫خطوات تفعيل المقاطعة الخارجية‬


‫ٌتم تفعٌل ال م مقاطعة الخارجٌة بمجموعة من االعدادات كالتالً‪:‬‬

‫‪.1‬ضبط االطراف التً ستستخدم للمقاطعة مثل ‪ INT 1‬أو ‪ INT 0‬لتعمل كدخل ‪.input‬‬

‫‪ .2‬ضبط نوع االشارة الكهربٌة التً ستسبب المقاطعة على حسب نوع الحساس أو‬

‫المفتاح الذي سٌولد إشارة المقاطعة‪.‬‬

‫‪ٌ.3‬تم تفعٌل قبول استقبال ال م مقاطعة على الطرف المطلوب مثل ‪.INT 0‬‬

‫‪.4‬تفعٌل قبول استقبال ال م مقاطعة بشكل عام ‪.‬‬

‫‪.5‬كتابة البرنامج الخاص بالمقاطعة ‪.ISR.‬‬

‫‪Programs Practice‬‬
‫‪Example 1: make the circuit on proteus :‬‬

‫‪Prepared by: Eng. HUDA ELSUAYSI‬‬


Parts used for this circuit :
DEVICES => [7SEG_COM_Anode, Atmega328p ,Button]

Writing a program to control the circuit :


Const unsigned char
led7seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x82,0xf8,0x80,0x90};
unsigned char cnt=0;
void up_isr() org IVT_ADDR_INT0
{
SREG_I_bit = 0;
cnt++;
SREG_I_bit = 1;

Prepared by: Eng. HUDA ELSUAYSI


}
void down_isr() org IVT_ADDR_INT1
{
SREG_I_bit = 0;
cnt--;
SREG_I_bit = 1;

}
void main(){
//IO init
DDRB=0xff; //PORTB is output
DDRD.B2=0; //PD2 is input
PORTD.B2=1; //Enable pullup on PD2
DDRD.B3=0; //PD3 is input
PORTD.B3=1; //Enable pullup on PD2
//interrupt init
EICRA.ISC01=1; //int0,falling edge
EICRA.ISC00=0;
EICRA.ISC11=1; //int1,falling edge
EICRA.ISC10=0;
EIMSK.INT1=1; //Enable Int0

Prepared by: Eng. HUDA ELSUAYSI


EIMSK.INT0=1; //Enable Int1
SREG_I_bit=1; //Enable Global interrupt

while(1){
PORTB =led7seg[cnt];
}
}

Prepared by: Eng. HUDA ELSUAYSI

You might also like