Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] HOW TO DISPLAY 7 SEGMENT FROM RTC DS 1307 using arduino mega

Status
Not open for further replies.

odenkgo

Newbie level 2
Joined
Nov 20, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
14
I used latch, decoder and multipexer.....how can i display the 7 segment from rtc..

this is my coding...can help me where should i add coding to display the time from rtc to 7 segment display..

Code:
[CODE]#include "Wire.h"
#define DS1307_ADDRESS 0x68


void setup(){
  Wire.begin();
  Serial.begin(9600);
}

void loop(){
  printDate();
  delay(1000);
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

  //print the date
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

}[/CODE
]

7-seg_latest.pngView attachment whole_schematic_schem.png
 
Last edited:

If I understand your question, so you have to put 7 segment routine into main routine loop() or into printdate() routine. If you drive the display dynamically, you will erase delay(1000) function from loop() function, because 7seg will be blinking.
 
Code:
#include <Wire.h>

#define DS1307_ADDRESS 0x68
int min1=0,x,y,hr1,a,b;

int inputs1[4] = {22,23,24,25};// A,B,C,D inputs
int inputs2[4] = {26,27,28,29};

byte BCD[10][4] ={{0,0,0,0},{1,0,0,0},{0,1,0,0},{1,1,0,0},{0,0,1,0},               
{1,0,1,0},{0,1,1,0},{1,1,1,0},{0,0,0,1},{1,0,0,1}};            // BCD input array for ic 4511
// 
byte controlPins[2][4] = {{0,0,0,0},{1,0,0,0}}; //BCD input to latch
int selectlatch[4] = {40,41,42,43};        // ABCD input multiplexer           
                      
void setup()
{
  for(int v=0;v<2;v++) {
  pinMode (selectlatch[v],OUTPUT); 
 delay(2000);}// set  outputs
  for(int z = 0; z < 4; z++){
pinMode(inputs1[z], OUTPUT); //set outputs
pinMode(inputs2[z],OUTPUT);
}
Wire.begin();
Serial.begin(9600);

}
void loop()
{
  
   printDate();
    delay (1000);
 
   
for(int c = 0; c < 4; c++){
    digitalWrite(selectlatch[c],controlPins[1][c]);
    digitalWrite(inputs1[c], BCD[y][c]); 
    digitalWrite(inputs2[c], BCD[x][c]);
    delay (1000);}
    
for(int c = 0; c < 4; c++){
    digitalWrite(selectlatch[c],controlPins[2][c]);
    digitalWrite(inputs1[c], BCD[b][c]); 
    digitalWrite(inputs2[c], BCD[a][c]);
    delay (1000);}
  
 
  
}
byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}
void printDate(){
  
 

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

  //print the date EG   3/1/11 23:59:59
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
   min1=minute;               // min1 contains minutes
   hr1=hour;
   y=min1/10;                       // First digit of minute
   x=min1-(y*10);                   // Second digit of minute
   b=hr1/10;                        // First digit of hour
   a=hr1-(b *10);                   // Second digit of hour
  return;
}

i use multiplexer to choose which latch i want to use...based on my coding i choose latch 1 to display time in minute on 2 piece of 7 segment.. and i choose latch 2 to display time in hours on 2 piece of 7 segment...but the problem is when i test on the hardware, it only choose latch 2 to display time in hours and minute...can u figure out what is the problem of my coding.,,
p/s:sorry for my bad english
 

In the schematic you supply 7 segment display with 9V, right? And BCD driver is supplied with 5V. If you put logical zero (0V) on BCD driver output, 7seg display lights. But if you put logical one on BCD driver output (5V) so between the anode and the cathode on 7seg display will be 4V, and maybe 7seg display will light too. Or BCD driver has an open collector outputs? I coulnd read it.

Are the L1 and L2 latches? So on W1 you give BCD code for the first number of hours and you make some puls on L1. Then you give BCD code for the first number of minutes and you make some puls on L2, right? The same thing about 2nd number of hours and minutes.

Your HW is complicated and also SW is complicated. You better to use four shift registers in a chain and then you will send 4 bytes for each segment like this:
gcbasic_tutorial2_part2_1.JPG


and about the software... :) I dont know much about Arduino programming and I prefer TI MSP430 or AVR so i dont know what exactly digitalWrite, pinMode is doing - I thing that pinMode is something like DDRx and digitalWrite is PORTx in AVR, but these arrays what you are putting there are strage for me.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top