Est 6

328 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
328
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Est 6

  1. 1. EMBEDDED SYSTEMS TUTORIAL6- INTERFACING 7 SEGMENT DISPLAY WITH AVR Hii… friends its our next AVR tutorial this time we are going to discuss about interfacing of 7 segment display with a AVR. You must have seen 7 segment display in you house hold inverters, in a zerox machine or even on your microwave oven. So in this tutorial , We will discuss about 7 segment display , its types and its interfacing with AVR along with source code so have a look… INTROUCTION A seven segment display is the most basic electronic display device that can display digits from 0-9. They find wide application in devices that display numeric information like digital clocks, radio, microwave ovens, electronic meters etc. The most common configuration has an array of eight LEDs arranged in a special pattern to display these digits. They are laid out as a squared-off figure ‘8’. Every LED is assigned a name from 'a' to 'g' and 'dp'and is identified by its name. Seven LEDs 'a' to 'g' are used to display the numerals while eighth LED 'dp' is used to display the dot/decimal. PACKAGE AND TYPES A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs, the remaining two pins (at middle) are common and internally shorted. These segments come in two configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the negative terminals of all LEDs are connected to the common pins. The common is connected to ground and a particular LED glows when its corresponding pin is given high. In CA arrangement, the common pin is given a high logic and the LED pins are given low to display a number .
  2. 2. HOW IT WORKS Now let us suppose a digit is to be displayed on the 7 segment. Suppose the digit is 1 in such case LEDS corresponding b and c should glow, so we can say foe each and every digit a specific set of LEDs has to glow . the LEDs to be golw with corresponding digits Are as shown.
  3. 3. INTERFACING WITH AVR MICROCONTROLLER Here is step wise process for inTERfacing a 7 segment display with AVR microcontroller( ATMEGA 16) SETP 1 CICUIT CONNECTION Here we are using a common anode 7 segment display. Connect your 7 segment display with the atmega 16 as per the connections shown in the diagram below
  4. 4. STEP 2 SOURCE CODE Create the new project in AVR STUDIO4 and compile the code written below- /* A simple program for interfacing common anode seven segment display with AVR microcontroller
  5. 5. a->PD7 b->PD6 c->PD5 d->PD4 e->PD3 f->PD2 g->PD1 DP->PD0 Written by: ABHILASH DIXIT TECH_STRONG */ #include <avr/io.h> #include <util/delay.h> // You can change the 7 segement display port just by changing the port in this macro #define SEVEN_SEGMENT_PORT PORTC #define SEVEN_SEGMENT_DDR DDRC void Seven_Segment_display(uint8_t n,uint8_t dp) { /* This the Note: function decimal writes a point digit given is by n displayed to the if display dp=1
  6. 6. n must be less than 9 */ if(n<10) { switch (n) { case 0: SEVEN_SEGMENT_PORT=0b00000011; break; case 1: SEVEN_SEGMENT_PORT=0b10011111; break; case 2: SEVEN_SEGMENT_PORT=0b00100101; break; case 3: SEVEN_SEGMENT_PORT=0b00001101; break; case 4: SEVEN_SEGMENT_PORT=0b10011001; break; case 5: SEVEN_SEGMENT_PORT=0b01001001; break; case 6: SEVEN_SEGMENT_PORT=0b01000001; break;
  7. 7. case 7: SEVEN_SEGMENT_PORT=0b00011111; break; case 8: SEVEN_SEGMENT_PORT=0b00000001; break; case 9: SEVEN_SEGMENT_PORT=0b00001001; break; } if(dp) { //if decimal point //make should 0th be displayed bit Low SEVEN_SEGMENT_PORT&=0b11111110; } } else { //This symbol //so on display display tells that can't n was greater handle than 9 it SEVEN_SEGMENT_PORT=0b11111101; } } void { Wait()
  8. 8. // An approx one second delay for 1Mhz CPU uint8_t clock i; for(i=0;i<1302;i++) { _delay_loop_2(0); } } void main() { //Setup SEVEN_SEGMENT_DDR=0xFF; SEVEN_SEGMENT_PORT=0xFF; uint8_t //All //All output segments off count=0; while(1) { Seven_Segment_display(count,0); count=count+1; if(count>9) { count=0; } _delay_ms(300); } }
  9. 9. In this program first we have created a function to display digits named seven_segment_display, then we have passed two argument first to display numbers and other to display decimal point if we want. We are going to connect our 7 segment at PORT C, so we will make it output port and after that the corresponding pins connected to 7 segment pins are set to high or low according to number to be displayed. This program will display the no from 0 t0 9 and as it reaches to 9 , it will be reset to 0. You can change numbering sequence or display only odd or odd number or whatever you want just by some small changes in the source code according to your task. Now burn the microcontroller with the hex file generated and power up your circuit , you will see numbers displaying from 0 to 9. So we have learnt the basics of 7 segment display interfacing, we can more 7 seven segment display with a AVR but for that we will need multiplexing technique, we will discuss multiplexing in upcoming tutorials but before that we have to discuss about TIMER in AVR so in next tutorial we will discuss about TIMER s

×