How to make a timer with 7-segment

8

  • 5
  • 0
  • 0.015
  • Reply

  • Open in the desktop app ADD TO PLAYLIST

    asgeng

    Published on Aug 08, 2020
    About :

    7-SEGMENT
    Untitled.jpg
    A seven-segment display is a form of electronic display device for displaying decimal numerals.
    Seven-segment displays are widely used in digital clocks, electronic meters, basic calculators, and other electronic devices that display numerical information.
    Common Anode:
    Untitled0.jpg
    Common cathode:
    Untitled1.jpg
    Common pins in both 7-segment:
    Untitled2.jpg
    In common anode, VCC is connected to COM terminal.
    In common cathode, GND is connected to COM terminal.
    Untitled3.jpg
    In common cathode, if VCC is connected to every pin, a to g, the corresponding segment will be ON.
    In common anode, if GND is connected to every pin, a to g, the corresponding segment will be ON.
    The following table shows the truth table, the equal hexadecimal and binary format for common cathode 7-segment display.
    Untitled4.jpg
    Now we’re going to learn to make two counters using a 7-segment.
    We have to declare the 7-segment numbers in flash memory of ATMEGA16 as the following matrix. When a data will be stored in flash memory, it will be defined as retentive.
    The counting process starts via a button.
    In AVR Codevision
    The data type of every element in display matrix is char that includes 8 bits.

    flash char display0[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
    flash char display1[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

    Now it is time to set initial value and data direction of PORTD and PORTB.
    PINB.0 of PORTB is utilized as input with initial value of 1.
    PORTB=0x01; //declaring initial logical value of 1 for PINB.0
    DDRB=0x00; //setting PINB.0 as input

    PORTB and PORTD are utilized as output with initial value of 0.
    PORTB=0x00; //declaring initial logical value of 1 for PORTB
    DDRB=0xFF; //setting PORTB as output
    PORTD=0x00; //declaring initial logical value of 1 for PORTD
    DDRD=0xFF; //setting PORTD as output

    Now it is time to write code.
    // First of all, declaring two local values as a counter like i and j with initial value of 0.
    int i = 0; // counter for common anode 7-segment
    int j = 0; // counter for common cathode 7-segment
    // Inside while loop:
    while(1)
    {
    if (PINB.0 == 0) //when button is pressed PINB.0 is equal to 0
    {
    PORTC = display0 [i];
    PORTD = display1 [j];
    i = i + 1;
    j = j + 1;
    delay_ms(500);
    }
    }

    Finally reset i and j
    Both matrixes have 10 elements. When reaching the last element of the matrixes, the counters must be reset.
    As the counter values are equal to 10 by using conditional command if, it is necessary to set initial value 0 for i and j.
    if(i == 10, j == 10)
    {
    i = 0;
    j = 0;
    }

    The final code is:
    flash char display0[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
    flash char display1[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
    int i = 0; // declaring counter variable i
    int j = 0; // declaring counter variable j
    PORTB = 0x01; // setting initial value for PORTB
    DDRB = 0x00; // setting data direction for PORTB
    PORTD = 0x00; // setting initial value for PORTB
    DDRD = 0xFF; // setting data direction for PORTB
    While (1)
    {
    If (PINB.0 == 0)
    {
    PORTC = Display0 [ i ];
    PORTD = Display1 [ j ];
    i = i + 1;
    j = j + 1;
    }
    if( i == 10, j == 10) // resetting counter values of i and j
    {
    i == 0;
    j == 0;
    }
    }

    In proteus 8
    In project tab select “build all”.
    Double click on ATMEGA16.
    Download EXE file to ATMEGA16.
    In proteus click on play.

    When button is pressed, the value of PINA.0 is equal to “0”.
    You did it!!!
    Good luck

    Tags :

    life engineer neoxian build creative

    Woo! This creator can upvote comments using 3speak's stake today because they are a top performing creator! Leave a quality comment relating to their content and you could receive an upvote worth at least a dollar.

    Their limit for today is $0!
    Comments:
    Time until asgeng can give away $0 to their commenters.
    0 Days 0 Hours 0 Minutes 0 Seconds
    Reply:

    To comment on this video please connect a HIVE account to your profile: Connect HIVE Account

    asgeng has no more videos yet.

    More Videos

    12:11
    17 views a year ago $
    01:00:35
    1 views 8 months ago $
    04:37
    1 views 3 years ago $
    01:49
    18 views a year ago $
    11:54
    4 views 2 years ago $
    07:46
    6 views a year ago $