7-segmentové hodiny

Problémy s návrhem, konstrukcí, zapojením, realizací elektronických zařízení

Moderátor: Moderátoři

Odpovědět
Zpráva
Autor
Uživatelský avatar
ojtan
Příspěvky: 7
Registrován: 13 říj 2009, 00:00

7-segmentové hodiny

#1 Příspěvek od ojtan »

Ahoj, potřeboval bych poradit jak upravit toto schéma, tak aby se dali použít segmentovky se společnou anodou (celkem 6ks. hodiny,minuty,vteřiny).

Mám to postavené na nepájivém poli a na anody přivedeno 5V, tak segmenty co mají v danou dobu svítit tak nesvítí, ale svítí všechny ostatní.

Nebo bude nutné upravit i program?
Přílohy
Výstřižek.JPG
(69.79 KiB) Staženo 290 x
Uživatelský avatar
serviceman
Příspěvky: 4093
Registrován: 09 črc 2013, 00:00

#2 Příspěvek od serviceman »

Protože výstup 74HC595 může dát 35mA oběma směry, stačí v programu negovat data.
Nebojte se skloňovat (i cizí slova).
Uživatelský avatar
ojtan
Příspěvky: 7
Registrován: 13 říj 2009, 00:00

#3 Příspěvek od ojtan »

A můžeš prosím poradit jak? Program běží na arduinu.

Kód: Vybrat vše

#include <Time.h> 
#include <Wire.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 13;

int j = 0; int i = 0; int h = 0;
int g = 0; int k = 0; int l = 0;

int hours = 0;
int minutes = 0;
int seconds = 0;

//holders for infromation you're going to pass to shifting function
byte dataONE;
byte dataTWO;
byte dataTRE;
byte dataFOUR;
byte dataFIVE;
byte dataSIX;
byte dataArray[10];
byte dataArrayd[10];  //dot on

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
 
  pinMode(16, OUTPUT);      //RTC on arduino GND
  digitalWrite(16, LOW);    //RTC on arduino GND
  pinMode(17, OUTPUT);      //RTC on arduino VCC
  digitalWrite(17, HIGH);   //RTC on arduino VCC
 
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  Wire.begin();

  //Arduino doesn't seem to have a way to write binary straight into the code
  //so these values are in HEX.  Decimal would have been fine, too.
  dataArray[0] = 0x3F;
  dataArray[1] = 0x06;
  dataArray[2] = 0x5B;
  dataArray[3] = 0x4F;
  dataArray[4] = 0x66;
  dataArray[5] = 0x6D;
  dataArray[6] = 0x7D;
  dataArray[7] = 0x07;
  dataArray[8] = 0x7F;
  dataArray[9] = 0x6F; 
  //with dot on
  dataArrayd[0] = 0xBF;
  dataArrayd[1] = 0x86;
  dataArrayd[2] = 0xDB;
  dataArrayd[3] = 0xcF;
  dataArrayd[4] = 0xE6;
  dataArrayd[5] = 0xED;
  dataArrayd[6] = 0xFD;
  dataArrayd[7] = 0x87;
  dataArrayd[8] = 0xFF;
  dataArrayd[9] = 0xEF;
}

void loop() {
  hours = hour();
  minutes = minute();
  seconds = second();
 
    // digital clock display of the time
  Serial.print(hour());
  Serial.print(':');
  Serial.print(minute());
  Serial.print(':');
  Serial.print(second());
  Serial.println();
 
 
 
 
//  Serial.print(now.hour());           // uncomment to debug
//  Serial.print(':');                  // uncomment to debug
//  Serial.print(now.minute());         // uncomment to debug
//  Serial.print(':');                  // uncomment to debug
//  Serial.println(now.second());       // uncomment to debug
 
  j = seconds % 10;
  i = seconds / 10;
  h = minutes % 10;
  g = minutes / 10;
  k = hours % 10;
  l = hours / 10;
 
    //load the light sequence you want from array
    dataSIX = dataArray[j];
    dataFIVE = dataArray[i];
    dataFOUR = dataArrayd[h];
    dataTRE = dataArray[g];
    dataTWO = dataArrayd[k];
    dataONE = dataArray[l];
   
   digitalWrite(latchPin, 0);
    //move 'em out 
    shiftOut(dataPin, clockPin, dataSIX);
    shiftOut(dataPin, clockPin, dataFIVE);
    shiftOut(dataPin, clockPin, dataFOUR);   
    shiftOut(dataPin, clockPin, dataTRE);
    shiftOut(dataPin, clockPin, dataTWO);   
    shiftOut(dataPin, clockPin, dataONE);
    //return the latch pin high to signal chip that it
    //no longer needs to listen for information
    digitalWrite(latchPin, 1);
    delay(500);

}


// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  // This shifts 8 bits out MSB first,
  //on the rising edge of the clock,
  //clock idles low

  //internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

  //clear everything out just in case to
  //prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  //for each bit in the byte myDataOuti?1
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that %00000001 or "1" will go through such
  //that it will be pin Q0 that lights.
  for (i=7; i>=0; i--)  {
    digitalWrite(myClockPin, 0);

    //if the value passed to myDataOut and a bitmask result
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000
    // and proceeds to set pinState to 1.
    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else {   
      pinState= 0;
    }

    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin 
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
  }

  //stop shifting
  digitalWrite(myClockPin, 0);
}
Uživatelský avatar
WLAB
Příspěvky: 867
Registrován: 13 zář 2005, 00:00
Bydliště: Praha

#4 Příspěvek od WLAB »

Nebo negovat signal data, pokud by nechtel menit program....
de omnibus dubitandum est
Uživatelský avatar
WLAB
Příspěvky: 867
Registrován: 13 zář 2005, 00:00
Bydliště: Praha

#5 Příspěvek od WLAB »

Je to sice prasarna, ale nejjednodussi bude zmenit:


digitalWrite(myDataPin, pinState);

na

Kód: Vybrat vše

digitalWrite(myDataPin, !pinState);


Nejlepsi by bylo bud zinvertovat vsechny ty definice znaku, nebo pak jejich prirazeni...
de omnibus dubitandum est
Uživatelský avatar
ojtan
Příspěvky: 7
Registrován: 13 říj 2009, 00:00

#6 Příspěvek od ojtan »

Díky moc! "Prasárna" funguje tak se s tím musím spokojit.
Sám o programování nic nevím.
Odpovědět

Zpět na „Řešení problémů s různými konstrukcemi“