Procedure:
- Arrange all the components required as mentioned.
- With the help of a suitable programming board (Example: Arduino UNO or Any USBASP) burn the Atmega328p IC with the code of up-down counter
- Embed all the circuit elements, IC and the Display module on a breadboard. Make proper connection as shown in the circuit design.
- Provide proper controlled bias voltage of 5 volts to the Vcc terminal and ground to the GND terminal.
- Execute the circuit, go back to the 1st step in case of any error. \
Conclusion: A two digit Up-Down counter was made with the helpof Atmega328p Microcontroller and a 4-Digit 7 Segment Display. The counter indefault mode operated as an Up-Counter. To operate it in down counter mode weneed to press RESET push Button and the hold the Down-Count Push Button
int a = 6, b = 7, c = 8, d = 9, e = 10, f = 11, g = 12, dp = 13; //Display pins
int d1 = 5, d2 = 4, d3 = 3, d4 = 2; //Common pins
int time = 50; //speed of the counter in ms
int buttonPin = 14;
int val = 0;
void setup() {
int i = 1;
for(; i<13; i++)
pinMode(i, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP) }
void loop() {
val = digitalRead(buttonPin);
offd(d1);
offd(d2);
offd(d3);
offd(d4);
int i, j;
if ( val == HIGH ){ //The counter
for(i = 0; i<1000; i++) {
for(j = 0; j <= (time/20); j++) {
ond(d2);
num(i/10 - 10*(i/100));
delay(5);
offd(d2);
ond(d3);
num(i/100 - 10*(i/1000));
delay(5);
offd(d3); } } }
if ( val == LOW )
{ //The counter
for(i = 1000; i>=0; i--)
{ for(j = 0; j <= (time/20); j++) {
ond(d2);
num(i/10 - 10*(i/100));
delay(5);
offd(d2);
ond(d3);
num(i/100 - 10*(i/1000));
delay(5);
offd(d3); } } } }
void on(int i) {
digitalWrite(i, HIGH);}
void off(int i){
digitalWrite(i, LOW); }
void ond(int i) {
digitalWrite(i, LOW);}
void offd(int i){
digitalWrite(i, HIGH); }
void num(int n) {
if(n < 0)
n = 0;
switch(n) {
case 0:
on(a);
on(b);
on(c);
on(d);
on(e);
on(f);
off(g);
break;
case 1:
off(a);
on(b);
on(c);
off(d);
off(e);
off(f);
off(g);
break;
case 2:
on(a);
on(b);
off(c);
on(d);
on(e);
off(f);
on(g);
break;
case 3:
on(a);
on(b);
on(c);
on(d);
off(e);
off(f);
on(g);
break;
case 4:
off(a);
on(b);
on(c);
off(d);
off(e);
on(f);
on(g);
break;
case 5:
on(a);
off(b);
on(c);
on(d);
off(e);
on(f);
on(g);
break;
case 6:
on(a);
off(b);
on(c);
on(d);
on(e);
on(f);
on(g);
break;
case 7:
on(a);
on(b);
on(c);
off(d);
off(e);
off(f);
off(g);
break;
case 8:
on(a);
on(b);
on(c);
on(d);
on(e);
on(f);
on(g);
break;
case 9:
on(a);
on(b);
on(c);
on(d);
off(e);
on(f);
on(g);
break;}