Increment and decrement 7 segment through switches

Implement a 2 digit up and down counter. Use two switches for increment count & decrement count.

Description

Here we need to connect 7 segment display at one of the port pins, and 2 switches at another port pin. By Pressing the increment switch the digit displayed on 7 segments should be incremented by 1 and by pressing the decrement switch the digit displayed on 7 segments should be decremented by 1.

Required components

  • 8051 MCU
  • Common cathode 7 segment display
  • Registers 330 ohm
  • 2 Push to ON switches
  • Jumpers

Circuit Diagram

2DigitIncDecCounterbySwitch

7 segment display is connected to port 0, common terminal of 7 segments is connected to pin 2 and pin 3 of port2, a resistor is needed to limit the flow of current.

Two switches are connected to pin 0 and pin 1 of port 1. Switch connected at pin 0 is used for increment the count, switch connected at pin 1 is used for decrement the count.

Code

Header files required:- delay.h and 7seg.h

Download it from here

Code description

To increment the counter when the switch is pressed, we just need to read the switch status, and based on switch status just have to do the job.

Initially, Port1 is initialized with 0xff. so when the switch is pressed and as another terminal of the switch is connected to the ground, port 1 will receive logic 0, port 0 is initialized with 0x00 and then seg_2digit(0) will make 7 segments to display 0 at the beginning.

Once the increment/decrement switch is pressed, it will increment/decrement the counter and will call function seg_2digit, which in turn will pass particular array index data to the port and display the result on the output device.

The upper and lower limit is handed in the code through if condition.

Download Proteus Circuit and Hex File

Video

Thank you for reading…

Leave a Comment

Your email address will not be published. Required fields are marked *