Arduino - AT24C32 / DS1307 Real Time Clock 7 SEGment Display

Toon hier Uw afgeronde projecten aan anderen.
Berichten: 9
Geregistreerd: 12 Mei 2016, 01:43

Arduino - AT24C32 / DS1307 Real Time Clock 7 SEGment Display

Berichtdoor arduinosensorsNL » 22 Okt 2016, 06:02

Een code voor de 4 digit 7 segment display met een RTC (Real time clock) Module AT24C32/DS1307

Bekijk hier de video: https://www.youtube.com/watch?v=Jp_ch0WM2es

Schema:
Afbeelding

Degene die ik gebruikt heb is anders dan het schema, maar dit maakt niet uit voor de module, beneden kan je zien welke ik heb gebruikt.
Afbeelding

Onderdelenlijst:
Arduino uno
AT24C32 / DS1307 real time clock ( I used the one on the picture above. There is also room for a temperature sensor like the LM35 on it)
4 Digit 7 Segment Display
4x 1 k Resistors. (Optional)
Jumper wires set MM/FM/MF


Code:
Code: Alles selecteren
/*
Author: Danny van den Brande, arduinosensors.nl. BlueCore Tech.
This code is written for the AT24C32/DS1307 RTC Module and
4 digit Seven Segment displays.
Be sure to check if you have a common anode or cathode display.(change @ line 26)
 */
#include "Wire.h"
#include "SevSeg.h" //https://github.com/sparkfun/SevSeg/tree/master/src
 
#define DS1307_ADDRESS 0x68
 
//Create an instance
SevSeg display7seg;
 
int valor = 0;
 
byte zero = 0x00;
unsigned long timer;
void setup()
{
  Wire.begin();
  //Comment this line after you have set the date @ void TimeSelection() below
//   TimeSelection(); Uncomment this line when your setting the time. Set time @ (line 66)
 
  //Change to COMMON_ANODE if you have a Common anode display.
  int displayType = COMMON_CATHODE;
     
  int digit1 = 10;
  int digit2 = 11;
  int digit3 = 12;
  int digit4 = 13;
 
  int segA = 2; 
  int segB = 3;
  int segC = 4;
  int segD = 5;
  int segE = 6;
  int segF = 7;
  int segG = 8;
  int segDP= 9;
   
  int numberOfDigits = 4;
 
  //Initialize display
  display7seg.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP);
   
  //Set brightness
  display7seg.SetBrightness(50);
  timer = millis();
}
 
void loop()
{
  char tempString[10]; //Used for sprintf
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  int seconds = ConvertToDecimal(Wire.read());
  int minutes = ConvertToDecimal(Wire.read());
  int hours = ConvertToDecimal(Wire.read() & 0b111111);
  sprintf(tempString, "%02d%02d", hours, minutes);
  display7seg.DisplayString(tempString, 3);
}
 
void TimeSelection()   //Select date and time here below!!(line 69,70,71)
//after setting time also comment time TimeSelection() @ void setup
{
  byte seconds = 10; //Valores de 0 a 59
  byte minutes = 38; //Valores de 0 a 59
  byte hours = 3; //Valores de 0 a 23
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero); //Stop no CI para que o mesmo possa receber os dados
 
  //As linhas abaixo escrevem no CI os valores de
  //data e hora que foram colocados nas variaveis acima
  Wire.write(ConvertToPCD(seconds));
  Wire.write(ConvertToPCD(minutes));
  Wire.write(ConvertToPCD(hours));
  Wire.write(zero);
  Wire.endTransmission();
}
 
byte ConvertToPCD(byte val)
{
  //Convert Decimal to binary
  return ( (val/10*16) + (val%10) );
}
 
byte ConvertToDecimal(byte val) 
{
  //Convert binary to decimal
  return ( (val/16*10) + (val%16) );
}


Bekijk de instructable hier: http://www.instructables.com/id/Arduino-AT24C32-DS1307-Real-Time-Clock-7-SEGment-D/
Sensors voor arduino! http://arduinosensors.nl

Advertisement

Terug naar Afgeronde projecten

Wie is er online?

Gebruikers in dit forum: Google [Bot] en 1 gast