Go Down

Topic: Manual increment of SEC register of DS-1307 RTC (Read 2269 times) previous topic - next topic

Anindya14

I have an assignment to submit on 27th December. The problem is ,

I have to manually increment the SEC register of a DS-1307 RTC IC. Assume that present condition is 19(bcd). I want to increment it by 1 to get 20. And write it back to the SEC register. How to do it? 

Please Help me :)

AWOL

It isn't possible to manipulate a register manually; you'll have to write code to do it,  or use a debugger.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Anindya14

It isn't possible to manipulate a register manually; you'll have to write code to do it,  or use a debugger.
I know and i am asking for the code

CrossRoads

That just needs some simple Wire.h commands to read the register, increment the value, and write the register.

Google DS1307 Arduino and you will find tons of links, such as
https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

GolamMostafa

#4
Dec 25, 2017, 09:44 am Last Edit: Dec 25, 2017, 10:05 am by GolamMostafa
As suggested by @CrossRoads, you can use standard TWI Bus Commands (Wire.beginTransmission(deviceAddress);, Wire.write(arg);, Wire.endTransmission();, Wire.requestFrom(deviceAddress, n);, Wire.read();) of the Wire.h Library to read/write the BCD formatted content of the SEC Register of DS1307 RTC. Add 01 (another BCD number) with the content of SEC Register and write it back into SEC Register. (Be sure you are writing BCD formatted value of 20 into SEC Register.) Few hints for you:

1.  Check that DS1307 is present and set the address of SEC Register.
2. Read the content of SEC Register. (You have said that it is 19=00011001.)
3.  Add 01 with 19; the MCU will produce 1A (0001 1010) and not 0010 0000 (20 BCD).
4.  Adjust the incorrect BCD of Step-3 into correct BCD and write it into SEC Register. (If you don't know how to do it, you may take the following alternative steps.)

3.  Convert the BCD content of SEC Register into natural binary (normal decimal) just by adding the positional weights of the BCD digits.
4.  Add 0x01 with the value of Step-3.
5.  Convert the value of Step-4 into BCD value using % (modulus) and / (division) operators.
6.  Write the value of Step-5 into SEC Register.

Good luck! We wish to see your full codes in your next post of this thread.

Anindya14

As suggested by @CrossRoads, you can use standard TWI Bus Commands (Wire.beginTransmission(deviceAddress);, Wire.write(arg);, Wire.endTransmission();, Wire.requestFrom(deviceAddress, n);, Wire.read();) of the Wire.h Library to read/write the BCD formatted content of the SEC Register of DS1307 RTC. Add 01 (another BCD number) with the content of SEC Register and write it back into SEC Register. (Be sure you are writing BCD formatted value of 20 into SEC Register.) Few hints for you:

1.  Check that DS1307 is present and set the address of SEC Register.
2. Read the content of SEC Register. (You have said that it is 19=00011001.)
3.  Add 01 with 19; the MCU will produce 1A (0001 1010) and not 0010 0000 (20 BCD).
4.  Adjust the incorrect BCD of Step-3 into correct BCD and write it into SEC Register. (If you don't know how to do it, you may take the following alternative steps.)

3.  Convert the BCD content of SEC Register into natural binary (normal decimal) just by adding the positional weights of the BCD digits.
4.  Add 0x01 with the value of Step-3.
5.  Convert the value of Step-4 into BCD value using % (modulus) and / (division) operators.
6.  Write the value of Step-5 into SEC Register.

Good luck! We wish to see your full codes in your next post of this thread.
Is the code alright? I very much appreciate your help! Thank you so much!

AWOL

Quote
Is the code alright?
Does it do reliably and repeatedly what you want it to do?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Anindya14

Does it do reliably and repeatedly what you want it to do?
It does. But i want to know if the code is efficient or not and any suggestions for better efficiency.

AWOL

It does. But i want to know if the code is efficient or not and any suggestions for better efficiency.
I don't know; I can't see your code.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

GolamMostafa

#9
Dec 26, 2017, 05:58 am Last Edit: Dec 26, 2017, 06:18 am by GolamMostafa
@Anindya14

Quote
I don't know; I can't see your code.
In respect of the above quote of @AWOL and also mine, please post your program in this window using code tags (</>) in order to allow us seeing your codes online rather than downloading and opening.

Anindya14

@Anindya14

In respect of the above quote of @AWOL and also mine, please post your program in this window using code tags (</>) in order to allow us seeing your codes online rather than downloading and opening.
Here it is:

#include <Wire.h>

void setup()
{
   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.endTransmission();

   byte bcdSec=Wire.read(); //reading the SEC register of DS-1307. Assume the value is 19(bcd)(00011001)
   byte binSec=(((bcdSec>>4)*10)+(bcdSec & 0b00001111)); // Converting the bcd value to binary value
   binSec++; //incrementing the binary value by 1
   byte bcddigit_zero=(binSec%10);
   byte bcddigit_one =(binSec/10);
   bcdSec= (bcddigit_zero + bcddigit_one);

   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.write(bcdSec);
   Wire.endTransmission();
   
}

void loop()
{

}

GolamMostafa

#11
Dec 26, 2017, 05:25 pm Last Edit: Dec 26, 2017, 05:32 pm by GolamMostafa
You could make your codes good looking by using code tags(</>) from Tool bar.

Code: [Select]
#include <Wire.h>

void setup()
{
   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.endTransmission();

   byte bcdSec=Wire.read(); //reading the SEC register of DS-1307. Assume the value is 19(bcd)(00011001)
   byte binSec=(((bcdSec>>4)*10)+(bcdSec & 0b00001111)); // Converting the bcd value to binary value
   binSec++; //incrementing the binary value by 1
   byte bcddigit_zero=(binSec%10);
   byte bcddigit_one =(binSec/10);
   bcdSec= (bcddigit_zero + bcddigit_one);

   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.write(bcdSec);
   Wire.endTransmission();
  
}

void loop()
{

}


You have claimed that your codes are working! How is it possible when your program is missing 'the complete coding' of Step-2 of Post#4?

Anindya14

You could make your codes good looking by using code tags(</>) from Tool bar.

Code: [Select]
#include <Wire.h>

void setup()
{
   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.endTransmission();

   byte bcdSec=Wire.read(); //reading the SEC register of DS-1307. Assume the value is 19(bcd)(00011001)
   byte binSec=(((bcdSec>>4)*10)+(bcdSec & 0b00001111)); // Converting the bcd value to binary value
   binSec++; //incrementing the binary value by 1
   byte bcddigit_zero=(binSec%10);
   byte bcddigit_one =(binSec/10);
   bcdSec= (bcddigit_zero + bcddigit_one);

   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.write(bcdSec);
   Wire.endTransmission();
  
}

void loop()
{

}


You have claimed that your codes are working! How is it possible when your program is missing 'the complete coding' of Step-2 of Post#4?
Code: [Select]

#include <Wire.h>

void setup()
{
   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.endTransmission();
   
   Wire.requestFrom(0b1101000,1);
   byte bcdSec=Wire.read(); //reading the SEC register of DS-1307. Assume the value is 19(bcd)(00011001)
   byte binSec=(((bcdSec>>4)*10)+(bcdSec & 0b00001111)); // Converting the bcd value to binary value
   binSec++; //incrementing the binary value by 1
   byte bcddigit_zero=(binSec%10);
   byte bcddigit_one =(binSec/10);
   bcdSec= (bcddigit_zero + bcddigit_one);

   Wire.beginTransmission(0b1101000); //device address is 1101000
   Wire.write(0x00);
   Wire.write(bcdSec);
   Wire.endTransmission();
   
}

void loop()
{

}


is it alright now?

GolamMostafa

Please test the program using UNO/Serial Monitor/LCD Monitor/7seg Monitor.

Go Up