Counter Circuit DiagramsFeatured

2 Digit Up/Down Counter Circuit

Typically, when buttons on scoreboards are pressed, digital score displays are used to show the score. These displays consist of two digits, and the core of this scoreboard’s functionality is the 2-Digit Up/Down Counter Circuit.

In this project, I will guide you through the process of creating a two-digit up-down counter circuit using both an 8051 microcontroller and an ATmega8 microcontroller.

Outline

  • 2 Digit Up/Down Counter Circuit Principle
  • 2 Digit Up/Down Counter Circuit Diagram
    • Circuit 1: Using 8051 Microcontroller
    • Components Required
    • Circuit 2: Using ATmega8 Microcontroller
    • Components Required
  • Circuit Design of 2 Digit 7-Segment Up Down Counter 
  • Two Digit Up Down Counter – Circuit Simulation Video
  • How to Operate 2 Digit Up Down Counter Circuit?
  • Algorithm for Programming
  • CODE 
    • Code for 8051 Microcontroller 
    • Code for ATmega8 Microcontroller
  • 2 Digit Up Down Counter Circuit using ATmega8 Output
  • 2 Digit Up Down Counter Circuit Applications
  • Limitations of this Circuit

2 Digit Up Down Counter Circuit Principle

The central concept behind the 2 Digit Up/Down Counter Circuit is to use buttons for incrementing and decrementing the values displayed on the seven-segment displays. When button 1 is pressed, the displayed value increases by one, and when button 2 is pressed, the displayed value decreases by one.

Given the limitation of only two displays, the value shown on the display can range from 0 to 99. To display three digits, i.e., three 7-Segment Displays, you would need to employ three screens. While there are multiple circuit designs available for a two-digit up/down counter, using a microcontroller simplifies the component count and board space requirements, albeit it requires straightforward programming.

Two Digit Up Down Counter Circuit Diagram

Two Digit Up Down Counter Circuit Diagram

Circuit 1: Using 8051 Microcontroller

2 Digit Up/Down Counter Circuit

Components Required

  • AT89C51 (8051 Microcontroller)
  • 2 X 7-Segment Displays (Common Anode)
  • 2 X 2N2222 NPN Transistors
  • 3 X Push Buttons
  • 2 X 10KΩ Resistors
  • 2 X 470Ω Resistors
  • 8 X 100Ω Resistors
  • 11.0592 MHz Crystal
  • 2 X 33pF Capacitor
  • 10μF/16V Capacitor
  • 1KΩ X 8 Resistor Pack
  • Mini Breadboard
  • 5V Power Supply
  • 8051 Programmer

Circuit 2: Using ATmega8 Microcontroller

Components Required

  • ATmega8 Microcontroller
  • 2 X 7-Segment Displays (Common Anode)
  • 2 X 10KΩ Resistors
  • 2 X 330Ω Resistors
  • 2 X Push Buttons

Circuit Design of 2 Digit 7-Segment Up Down Counter 

To create the 2-digit Up/Down counter, we’ve linked two seven-segment displays to the ATMEGA8 microprocessor. Each display consists of eight pins and one common pin.

Seven-segment displays are typically categorized into two types: 1) common cathode, and 2) common anode. The one utilized in this project is a common cathode display. Typically, with common cathode displays, you should connect the common pin to ground, whereas with common anode displays, you’d connect the common pin to VCC.

A seven-segment display comprises seven segments, which are essentially seven LEDs. These segments are represented by seven pins, with an additional pin for the center dot of the display. To illuminate a specific segment in a common cathode display, you apply logic 1 to the corresponding segment pin. Conversely, for common anode displays, you set the segment pin to logic 0 to light up the segment. Each segment is assigned a unique name, typically starting from ‘a’ and ending with ‘h’.

In our circuit, the seven-segment display is linked to the microcontroller through a current-limiting resistor of 330 ohms. Additionally, two buttons are connected in a pull-down configuration.

The rationale behind connecting the buttons in pull-down mode is to prevent the buttons from floating in an undetermined state. By connecting the buttons in pull-down mode, we ensure that they initially register a logic 0 state.

Two Digit Up Down Counter – Circuit Simulation Video

How to Operate 2 Digit Up Down Counter Circuit?

  1. To begin, turn on the circuit.
  2. ‘00′ is the value displayed on seven segments.
  3. In the circuit, press the 1st button. The value of each of the seven parts is increased by one.
  4. Press button 1 one more. On the screens, the value is ’02’.
  5. Press the second button now. The value is decrementing to 01 as you can see.
  6. The value on the displays can be increased up to 99 times; after that, pressing button 1 will begin incrementing from ‘01′. After decrementing to ’00,’ pressing the second button displays ’00.’ This value can only be altered after it has been increased to at least ‘01′.

Algorithm for Programming

  1. Declare the corresponding PORTS of the microcontrollers as input or output.
  2. Declare an array with the seven segment codes i.e, if number one is to be displayed, then the binary value that should be passed is as follows:

dp  g  f   e   d   c   b  a
1     1  1   1   1   0   0  1

I’m utilising a Common Anode 7-Segment Display since the b and c segments should be assigned with logic 0 to display ‘1′. As a result, the binary value 0b11111001 or the hexadecimal value 0xf9 is allocated to the port that will show the number 1. The array should be made up of binary or hexadecimal integers ranging from 0 to 9.

  1. Check the status of the buttons using if else loop.
  2. If the button 1 is pressed for first time, first seven segment (on the left) should display 0 and the other should display 1. So the output is ‘01’.
  3. If the button 1 is pressed for second time, value on second button should be incremented by one.
  4. If the second button is pressed, value on the first segment should be decremented by one value.

CODE 

  #include<reg51.h>
   
  #define SEGMENT P0
   
  sbit switch1=P3^0;
  sbit switch2=P3^1;
  sbit digit1=P2^0;
  sbit digit2=P2^1;
   
  void delay (int);
   
  int x=0,y,z;
  unsigned char ch[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
   
  void delay (int d)
  {
  unsigned char i;
  for(;d>0;d–)
  {
  for(i=250;i>0;i–);
  for(i=248;i>0;i–);
  }
  }
   
  void main()
  {
  switch1=1;
  switch2=1;
  digit1=1;
  digit2=1;
   
  while(1)
  {
  if(switch1==0)
  {
  x++;
  delay(200);
  }
  else if(switch2==0)
  {
  x–;
  delay(200);
  }
  y=x/10;
  SEGMENT=ch[y];
  digit1=0;
  delay(10);
  digit1=1;
   
  z=x%10;
  SEGMENT=ch[z];
  digit2=0;
  delay(10);
  digit2=1;
  }
  }

Code for ATmega8 Microcontroller

  /*
  * updown_counter.c
   
  * Author: ADMIN
  */
  /*#define F_CPU 8000000UL*/
  #include <avr/io.h>
  #include <util/delay.h>
   
  int main(void)
  {
  DDRB = 0x00;
  DDRC = 0xff;
  DDRD = 0xff;
  unsigned int i,x=0,y,z;
  unsigned char arr1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x18};
  while(1)
  {
  if((PINB&0x01)==0x01)
  {
  x++;
  _delay_ms(200);
  }
  else if ((PINB&0x02)==0x02)
  {
  x–;
  _delay_ms(200);
  }
   
  {
  y=x/10;
  z=x%10;
  PORTC=0x01;
  PORTD=arr1[y];
  _delay_ms(400);
  PORTC=0x02;
  PORTD=arr1[z];
  _delay_ms(800);
   
  }
   
  }
  }

2 Digit Up Down Counter Circuit using ATmega8 Output

2 Digit Up Down Counter Circuit Applications

  1. This circuit can be used in scoreboards.
  2. Up/down counter is used for counting number of objects passed through a point.
  3. It is used to count number of persons entering a room.

Limitations of this Circuit

This particular Up/Down Counter circuit is limited to 2 digits i.e. 0-99. If more than 3 digits are required, one should use another display which requires more pins from the controller.

Tags

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button
Close
Close