Advertisement
NittyGritty

HC585-Test

Nov 2nd, 2017
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.19 KB | None | 0 0
  1. const int clock = 7; //SCK
  2. const int latch = 5; //RCK
  3. const int data = 6;  //DIO
  4.  
  5. byte value[] ={//DGFEDCBA
  6.                 B11000000, // 0
  7.                 B11111001, // 1
  8.                 B10100100, // 2
  9.                 B10110000, // 3
  10.                 B10011001, // 4
  11.                 B10010010, // 5
  12.                 B10000010, // 6
  13.                 B11111000, // 7
  14.                 B10000000, // 8
  15.                 B10010000, // 9
  16.                 B10001000, // A
  17.                 B10000011, // b
  18.                 B11000110, // C
  19.                 B10100001, // d
  20.                 B10000110, // E
  21.                 B10001110, // F
  22.                
  23.                 B11111111
  24.                
  25.                 };// display nothing
  26.  
  27. byte digit[] ={ B10000000, // left segment
  28.                 B01000000,
  29.                 B00100000,
  30.                 B00010000,
  31.                 B00001000,
  32.                 B00000100,
  33.                 B00000010,
  34.                 B00000001
  35.                 }; // right segment
  36.  
  37. byte ii = 0;
  38.  
  39. byte temp_low[]  = {0, 0, 0, 0, 0, 0, 0, 0 };
  40. byte temp_high[] = {0, 0, 0, 0, 0, 0, 0, 0 };
  41.  
  42. byte vvalue_low  = value[0];
  43. byte vvalue_high = value[0];
  44.  
  45. void setup() {
  46.   pinMode(clock, OUTPUT);
  47.   pinMode(latch, OUTPUT);
  48.   pinMode(data, OUTPUT);
  49.  
  50.   cli();//stop interrupts
  51.   //set timer0 interrupt at 980Hz
  52.   TCCR0A = 0;// set entire TCCR0A register to 0
  53.   TCCR0B = 0;// same for TCCR0B
  54.   TCNT0  = 0;//initialize counter value to 0
  55.   OCR0A = 255;//(must be <256) --> 16000000 / (prescaler*255) = 980 Hz
  56.   TCCR0A |= (1 << WGM01);
  57.   TCCR0B |= (1 << CS01) | (1 << CS00);   //prescaler = 64
  58.   TIMSK0 |= (1 << OCIE0A);  
  59.   sei();//allow interrupts
  60.  
  61. }
  62.  
  63.  
  64. ISR(TIMER0_COMPA_vect){  
  65.  
  66.   ii++;
  67.   if (ii==8) ii=0;
  68.  
  69.   vvalue_low  = temp_low[ii];
  70.   vvalue_high = temp_high[ii];
  71.  
  72. /*
  73.   digitalWrite(latch,LOW);
  74.   shiftOut(data,clock,MSBFIRST,B11111111); // select all segments
  75.   shiftOut(data,clock,MSBFIRST,B11111111); // display nothing
  76.  
  77.   shiftOut(data,clock,MSBFIRST,B11111111); // select all segments
  78.   shiftOut(data,clock,MSBFIRST,B11111111); // display nothing
  79.   digitalWrite(latch,HIGH);
  80.  
  81. */
  82.  
  83.   digitalWrite(latch,LOW);
  84.   shiftOut(data,clock,MSBFIRST,value[vvalue_low]);
  85.   shiftOut(data,clock,MSBFIRST,digit[ii]);
  86.   //digitalWrite(latch,HIGH);  
  87.  
  88.   //digitalWrite(latch,LOW);
  89.   shiftOut(data,clock,MSBFIRST,value[vvalue_high]);
  90.   shiftOut(data,clock,MSBFIRST,digit[ii]);
  91.   digitalWrite(latch,HIGH);  
  92.  
  93. }
  94.  
  95.  
  96. long i, j;  // i - counts up, j counts down
  97.  
  98. void loop() {
  99.  
  100.   for (i=1;i<=99999999;i++) {
  101.     j = 100000000-i;
  102.    temp_high[7] = (j / 0x1) % 0x10;
  103.    temp_high[6] = (j / 0x10) % 0x10;
  104.    temp_high[5] = (j / 0x100) % 0x10;
  105.    temp_high[4] = (j / 0x1000) % 0x10;
  106.    temp_high[3] = (j / 0x10000) % 0x10;
  107.    temp_high[2] = (j / 0x100000) % 0x10;
  108.    temp_high[1] = (j / 0x1000000) % 0x10;
  109.    temp_high[0] = (j / 0x10000000) % 0x10;
  110.    
  111.    temp_low[7] = (i /1) % 10;
  112.    temp_low[6] = (i / 10) % 10;
  113.    temp_low[5] = (i / 100) % 10;
  114.    temp_low[4] = (i / 1000) % 10;
  115.    temp_low[3] = (i / 10000) % 10;
  116.    temp_low[2] = (i / 100000) % 10;
  117.    temp_low[1] = (i / 1000000) % 10;
  118.    temp_low[0] = (i / 10000000) % 10;
  119.    
  120.    delay(100);
  121.   }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement