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.

8051 with RTC DS12887 problem

Status
Not open for further replies.

MRgenius

Junior Member level 3
Joined
May 14, 2015
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
174
I'm facing a problem in driving the RTC Ds12887 with AT89C51ED2
anyone here ready for help
 

Elaborate the problem. And give any associated information. Someone here might have an answer
 

Last edited:

The interface is activated by setting EXTRAM = 1

could you explain more
Do you mean that ...
these pins definition are built in
AD0-AD7 --> P0.0-P0.7
AS --> ALE
R/W --> p3.6
DS --> p3.7

besides the compiler tells
Code:
main.c(75): error C202: 'EXTRAM': undefined identifier
 

P3.6 and P3.7 are acting as Intel mode /RD and /WR memory signals, the DS12887 mode as to be set respectively.

EXTRAM is a register bit, have to review your processor specific *.h files if and how it's defined, in case of doubt define the register bit yourself.
 

the RTC counts seconds and minutes upto 90 not 60 ???

i'm interfaced AT89C51ED2 with ds12887
and i used the following code
the problem is that ...the count of minutes and seconds is up to 90
anyone could tell me why this happens:
 

Probably unrelated if code-based problem. My 24-hr digital clock using CD4026 and seven-segment displays... the common cathode resistors when too low a value caused either the AND gates or the 4026s to count seconds and minutes up to 100 (no idea why??), using higher value resistors solved the problem.
 

Hi,

i didn´t read datasheet... but other RTCs use BCD coding for minutes and seconds (and other values):

30 seconds = 0x30 in BCD, but 0x30 as hex = 48 in decimal
59 seconds = 0x59 in BCD, but 0x59 as hex = 89 in decimal

Maybe this is the problem. The datasheet will tell you.

Klaus
 
Probably unrelated if code-based problem. My 24-hr digital clock using CD4026 and seven-segment displays... the common cathode resistors when too low a value caused either the AND gates or the 4026s to count seconds and minutes up to 100 (no idea why??), using higher value resistors solved the problem.

but the counting in the RTC is fully independent from the display at the seven segment

- - - Updated - - -

Thanks alot everybody it's already solved :clap: :clap::clap:
 

how to avoid incorrect time and calendar reading::
i found three methods at the data sheet ... this is one of them

use the update–ended interrupt. If enabled, an interrupt
occurs after every up date cycle that indicates that
over 999 ms are available to read valid time and date
information.

do i have to use the interrupt pin IRQ to use this method
or i can just scan the IRQF or UF bit to read the RTC
 

Hi,

I assume you may read the date/time at any time.

Klaus
 

look the page 6 left top there is a mentioned error getting to read calendar.
**broken link removed**
 

Hi,

In my eyes it makes not much sense to use solution2 and 3 without true interrupts, but it is possible.
The flags in the registers in either case show the correct status.

For a "polling" solution I'd use solution 1.

Klaus
 

Hi,

In my eyes it makes not much sense to use solution2 and 3 without true interrupts, but it is possible.
The flags in the registers in either case show the correct status.

For a "polling" solution I'd use solution 1.

Klaus

i used solution 1 where i keep polling on IRQF bit after i enabled the UIE bit in the initlization
but unfortunately the shift problem increased
 

Hi,

What "shift problem"?

Describe the problem more detailed.
What do you do, step by step?
What do you expect?
And what do you see instead?

Klaus
 

Hi,

What "shift problem"?

Describe the problem more detailed.
What do you do, step by step?
What do you expect?
And what do you see instead?

Klaus

the problem is as following
1- i interfaced the ds12887 with AT89C51ED2
2- the C code works as following it checks the RTC if it's initialized or not ,if not it initlize it and write a flag in the internal eeprom so that it's not initialized again if the processor is restarted
3- then the while loop just read the time and date and display them in a 7 segment display
4- but i noticed that, the time is shifted about 6 seconds in two days
5- i checked the data sheet again and i tried to use the first method of avoiding accessing the RTC while it's being updated by enabling the UIE bit at initialization and loop on the IRQF bit and read the RTC only when IRQF bit is set
but the shift increased besides i get garbage values from the RTC if it's restarted
 

Hi,

What "shift problem"?

Describe the problem more detailed.
What do you do, step by step?
What do you expect?
And what do you see instead?

Klaus

it gives about 1 minute shift per day not only 6 seconds per two days
 

Hi,

Pleas confirm, that the time error is continous and not jumping.
(I mean if it is 60s per day it should be continously 2.5s per hour)

and write a flag in the internal eeprom
I can´t see an internal EEPROM.

You may READ register A to check if clock is initialized.

Take care when writing to register A.
Best: Never write to this register. Only at the very first time to start the clock.

An incidentally change in DV2:DV0 other than "010" may cause errors in time.

Also datasheet says:
Before writing the internal time, cal-
endar, and alarm registers, the SET bit in Register B
should be written to a logic one to prevent updates from
occurring while access is being attempted.

Also, don´t write to the time / date registers, only when you want to set time. (once in half a year).

Klaus
 

Hi,

Pleas confirm, that the time error is continous and not jumping.
(I mean if it is 60s per day it should be continously 2.5s per hour)


I can´t see an internal EEPROM.

You may READ register A to check if clock is initialized.
Take care when writing to register A.
Best: Never write to this register. Only at the very first time to start the clock.
An incidentally change in DV2:DV0 other than "010" may cause errors in time.

Also datasheet says:
Also, don´t write to the time / date registers, only when you want to set time. (once in half a year).

Klaus

i think the time error is jumping not contentious , i need to check it again to make sure of that
i only write to register A and other time and date regester at initialization
here is the code

Code:
void RTC_init(void){
	XBYTE[10] = 0x20; 	//turn on OSC
	XBYTE[11] = 0x92; 	//BCD ,24h ,no dayLight savings
	/*initilize*/
	XBYTE[0] = 0x00; 	//seconds =00
	XBYTE[2] = INITIAL_MINUTE; 	//Minute = 
	XBYTE[4] = INITIAL_HOUR; 	//HOUR =
	XBYTE[6] = 0x03; 	    //day of the weak thursday
	XBYTE[7] = INITIAL_DAY; 	  //day of the month 12
	XBYTE[8] = 0x11; 	   //month = november
	XBYTE[9] = 0x15; 	  //year = 2015
	
	XBYTE[11] = 0x12; 	//allow update
}
/*****************************************************/
void main()
{
	unsigned char hr =0,min =0 ,sec =0,day=0,month=0,year=0;
	unsigned char initRTC_state ;
	bit disp_f = 0;
	delay(250);			//RTC needs 200ms upon power-up
	AUXR = 0x02;
	initRTC_state =	__api_rd_eeprom_byte(0x400); 
	if( initRTC_state != VERSION_NO){
		RTC_init();    // use it at the first time only
		__api_wr_eeprom_byte(0x400, VERSION_NO);
	}
	while(1)
	{
	        sec = XBYTE[0];
	        min = XBYTE[2];
		hr  = XBYTE[4];
		day  = XBYTE[7];
		month= XBYTE[8];
		year = XBYTE[9];
		if(disp_f == 0){
			display(sec , min , hr);
			if(sec == 0x19)
				disp_f = 1;
		}
		else{
			display(year ,month ,day);
			if(sec == 0x39)
				disp_f = 0;
		}
	}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top