Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int clock = 7; //SCK
- const int latch = 5; //RCK
- const int data = 6; //DIO
- byte value[] ={//DGFEDCBA
- B11000000, // 0
- B11111001, // 1
- B10100100, // 2
- B10110000, // 3
- B10011001, // 4
- B10010010, // 5
- B10000010, // 6
- B11111000, // 7
- B10000000, // 8
- B10010000, // 9
- B10001000, // A
- B10000011, // b
- B11000110, // C
- B10100001, // d
- B10000110, // E
- B10001110, // F
- B11111111
- };// display nothing
- byte digit[] ={ B10000000, // left segment
- B01000000,
- B00100000,
- B00010000,
- B00001000,
- B00000100,
- B00000010,
- B00000001
- }; // right segment
- byte ii = 0;
- byte temp_low[] = {0, 0, 0, 0, 0, 0, 0, 0 };
- byte temp_high[] = {0, 0, 0, 0, 0, 0, 0, 0 };
- byte vvalue_low = value[0];
- byte vvalue_high = value[0];
- void setup() {
- pinMode(clock, OUTPUT);
- pinMode(latch, OUTPUT);
- pinMode(data, OUTPUT);
- cli();//stop interrupts
- //set timer0 interrupt at 980Hz
- TCCR0A = 0;// set entire TCCR0A register to 0
- TCCR0B = 0;// same for TCCR0B
- TCNT0 = 0;//initialize counter value to 0
- OCR0A = 255;//(must be <256) --> 16000000 / (prescaler*255) = 980 Hz
- TCCR0A |= (1 << WGM01);
- TCCR0B |= (1 << CS01) | (1 << CS00); //prescaler = 64
- TIMSK0 |= (1 << OCIE0A);
- sei();//allow interrupts
- }
- ISR(TIMER0_COMPA_vect){
- ii++;
- if (ii==8) ii=0;
- vvalue_low = temp_low[ii];
- vvalue_high = temp_high[ii];
- /*
- digitalWrite(latch,LOW);
- shiftOut(data,clock,MSBFIRST,B11111111); // select all segments
- shiftOut(data,clock,MSBFIRST,B11111111); // display nothing
- shiftOut(data,clock,MSBFIRST,B11111111); // select all segments
- shiftOut(data,clock,MSBFIRST,B11111111); // display nothing
- digitalWrite(latch,HIGH);
- */
- digitalWrite(latch,LOW);
- shiftOut(data,clock,MSBFIRST,value[vvalue_low]);
- shiftOut(data,clock,MSBFIRST,digit[ii]);
- //digitalWrite(latch,HIGH);
- //digitalWrite(latch,LOW);
- shiftOut(data,clock,MSBFIRST,value[vvalue_high]);
- shiftOut(data,clock,MSBFIRST,digit[ii]);
- digitalWrite(latch,HIGH);
- }
- long i, j; // i - counts up, j counts down
- void loop() {
- for (i=1;i<=99999999;i++) {
- j = 100000000-i;
- temp_high[7] = (j / 0x1) % 0x10;
- temp_high[6] = (j / 0x10) % 0x10;
- temp_high[5] = (j / 0x100) % 0x10;
- temp_high[4] = (j / 0x1000) % 0x10;
- temp_high[3] = (j / 0x10000) % 0x10;
- temp_high[2] = (j / 0x100000) % 0x10;
- temp_high[1] = (j / 0x1000000) % 0x10;
- temp_high[0] = (j / 0x10000000) % 0x10;
- temp_low[7] = (i /1) % 10;
- temp_low[6] = (i / 10) % 10;
- temp_low[5] = (i / 100) % 10;
- temp_low[4] = (i / 1000) % 10;
- temp_low[3] = (i / 10000) % 10;
- temp_low[2] = (i / 100000) % 10;
- temp_low[1] = (i / 1000000) % 10;
- temp_low[0] = (i / 10000000) % 10;
- delay(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement