Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save urmil0071/d9f6ad9c7bfd9cfbe38eb938f5291651 to your computer and use it in GitHub Desktop.
Save urmil0071/d9f6ad9c7bfd9cfbe38eb938f5291651 to your computer and use it in GitHub Desktop.
0 to 99 Counter Using Arduino and cc Type 7 Segment Display
#include <Arduino.h>
byte lut[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
byte disp[]={B111110,B111101};
byte d=0;
byte x=0;
byte x1,x2,xx;
void setup()
{
DDRB=0xFF;
DDRD=0xFF;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1=0xF2F7; /// Timer 1 preset value
bitWrite(SREG,7,1); /// Enable global interrupt
bitWrite(TIMSK1,0,1); /// Enable TIMER1_OVF interrupt
TCCR1B=0x05; /// Timer 1 ON
}
ISR(TIMER1_OVF_vect)
{
TCCR1B=0x00; /// Timer 1 off
TCNT1=0xF2F7;
xx=x;
x1=0;
x2=0;
while(xx != 0)
{
xx=xx-1;
x1=x1+1;
if(x1>9)
{
x2=x2+1;
x1=0;
}
}
x=x+1;
if(x==100)
{
x=0;
}
bitSet(TIFR1,2); /// TOV1 Clear
TCCR1B=0x05; /// Timer 1 ON
}
void loop()
{
digitalWrite(13,LOW);
delay(1);
PORTB=disp[d];
if (d==0)
{
PORTD=lut[x2];
}
else if (d==1)
{
PORTD=lut[x1];
}
delay(1);
d=d+1;
if (d>1)
{
d=0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment