Created
August 16, 2017 19:38
-
-
Save urmil0071/3e6b3babc8f3bb4dcf907baad493d5da to your computer and use it in GitHub Desktop.
0 to 99 Counter Using Arduino and cc Type 7 Segment Display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
char lut[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; | |
int disp[]={B111110,B111101}; | |
byte d; | |
byte x=0; | |
byte x1,x2,xx; | |
void setup() | |
{ | |
DDRB=0xFF; | |
DDRD=0xFF; | |
TCCR1A=0x00; | |
TCCR1B=0x00; | |
TCNT1=0xE2F7; | |
TCCR1B=0x05; | |
} | |
void xupdate() | |
{ | |
TCCR1B=0x00; | |
TCNT1=0xF2F7; | |
x=x+1; | |
// increment 1 to work with the while loop | |
if(x==100) | |
{ | |
x=0; | |
} | |
xx=x; | |
x1=0; | |
x2=0; | |
while(xx != 0) | |
{ | |
xx=xx-1; | |
x1=x1+1; | |
if(x1>9) | |
{ | |
x2=x2+1; | |
x1=0; | |
} | |
} | |
bitSet(TIFR1,2); | |
TCCR1B=0x05; | |
} | |
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); | |
if (bitRead(TIFR1,2)==HIGH) | |
{ | |
xupdate(); | |
} | |
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