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.

real time clock interfacing with 8051?

Status
Not open for further replies.

kiranmayik

Newbie level 4
Newbie level 4
Joined
Jan 14, 2007
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,373
rtc interfacing with 8051

hi,
i'm doing a project to display the temperature using lm35,adc0804 on an lcd.
now i also want to display the time on the second line of lcd using ds12887(or any other rtc),i would like to know how to interface it since it is considered as external memory. rest of my code is in C.
thank u.
 

interfacing rtc with microcontroller

The DS12887 is also a very good candidate, especially that you don't need external battery and 32kHz crystal - everything is build-in ..

Here are some tips:

**broken link removed**

If you decide to use it and will need more help - come back and ask ..

Regards,
IanP
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
interface 8051 and rtc

dedicate one onboard timer (in 8051) for the clock, that should do, whats the crystal frequency u're using?
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
interfacing of 8051 with real time clock

kiranmayik wrote:
how to interface it since it is considered as external memory.
Use pointer to address xram mapped DS12887, as this example:

Code:
#include <reg51.h>

xram char *ds12887;

void main (void){
char c;
     ds12887 = &0x8000; // assume DS12887 locate on XRAM 0x8000
     *ds12887 = 0;      // 0x8000 <- 0
     c = ++ds12887;     // 0x8001 -> c
}

Another method is:
Code:
     XBYTE[0x1234] = 0x55;
will produce:
Code:
     mov dptr,#0x1234 
     mov a,#0x55 
     movx @dptr,a
and will move 0x55 into absolute location 0x1234 in xdata.



mondunno wrote:
dedicate one onboard timer (in 8051) for the clock, that should do
8051 onboard timer isn't RTC (real time clock), kiranmayik discusses about RTC.
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
8051 rtc interface

thanx everyone i'm studying about these.
will come back for doubts.

Added after 12 minutes:

where do i connect EA to.
until now i connected it to Vcc.
but if i have to interface it to RTC (external memory) do i have to connect it to ground.
 

ds12887 interface with 8051

EA is external program memory enable pin, that pin is not for external data memory (ie ds12887).
So remain connect EA to Vcc.
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
at89c51 ds1307 interface

Just remember that if you connect /WR and /RD directly to the DS12887 its address area will start at 0000h .. so, for example, to read seconds the DPTR register has to be loaded with 0000h ..

Regards,
IanP
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
rtc interfacing with 89c51

hi,

lemme elaborate on using one (on board) timer for rtc. if u're using 12MHz crystal. the system clock is 1MHz (in at89cxx series) = 1 micro second. use one of the clock in autoreload mode. that is 8 bit auto reload value can be stored in th0 (or 1). place -6 in it. [ this is the simplest way to realize rtc using timer]
each interrupt generated is 250 micro seconds.
increment a counter in the ISR. see to that u use 2 incremented registers to make up a second (4000 such interrupts)

but this is a tedious and mips wasting process. but really accurate



i already have a clock running in this way, using 89c51



advantages of autoreload mode:
u dont miss any clock pulse. since its autoreloaded, and edge triggered. every pulse is counted.

the crystal we get in general is highly accurate ( the chances of error[by environment changes] is 6 ppm to the max.)

so its around 0-6 seconds error in a year(thats precise)



so why do want a clock/calendar module just for clock(time) display?



******************************************************

EA-bar signal is used to tell the 89c51, from where the 0000h address starts from.

if EA-bar signal is shorted with VCC, then the 0000h of program memory starts from internal memory and goes upto FFFFh into external memory. (is a must if u have ur code in the internal flash rom)

if EA-bar signal is shorted with ground. the 0000h of program memory starts in the external memory (so the code in the internal flash rom is not executed).

conclusion: Connect EA-bar pin to VCC if u're using internal flash
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
pcf 8583 interfacing 8051

i have another doubt
im connecting the rtc(external mem) to Port 0, so do i still need to connect the pull up resistores(10k) or i need not?
plz help
 

using 8051 microcontroller as real time clock

If you use these statements to control I/O thru Port 0
Code:
     MOV P0,#$55
     MOV A,P0
you need to connect the pull up resistors(10k)

If you use these statements to read/write data thru Port 0
Code:
     MOVX A,@DPTR
     MOVX @DPTR,A
     MOVX A,@R0
     MOVX @R0,A
     MOVX A,@R1
     MOVX @R1,A
forget the pull up resistors(10k)

as you'll use
Code:
     XBYTE[0x1234] = 0x55;
it mean no pull up resistors needed.
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
8051 as rtc

PCF8583 is another good choice.It is easy to use and you can get more than 240 bytes extra SRAM for CPU.
Look at the C code:
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
interface ds1307 with at89c51

If you use these statements to control I/O thru Port 0
Code:
     MOV P0,#$55
     MOV A,P0

you need to connect the pull up resistors(10k)

Some mistake, it should be:
If you use this statements to control Output thru Port 0
Code:
     MOV P0,#$55
you need to connect the pull up resistors(10k)
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
clock interfacing with 8051

i have implemented the rtc
but each time the power is on the time is being set to the initial time,probably i have to write a separate program for setting the time and then write another program for the rest of the code.
 

real time clock pulse using microcontroller 8051

Use one of the 12887 RAM location as a state byte and set a flag which will indicate wheather current time&date is valid ..
On power-on read this flag and if it is correct display current day and time, if it is not, re-initialise the RTC with the default values ..

Regards,
IanP
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
0x1234 rtc

each time the power is on the time is being set to the initial time
Make sure the chip remain powered when your microcontroller voltage supply is off.
 

    kiranmayik

    Points: 2
    Helpful Answer Positive Rating
0x1234 clock

hi

I have also made a clcok project with mu 80c2051 and PCF 8385, but the problem is that the clock chip time does not remain constant, like some time it works so fast and some time it becomes slow. I dont know why it heppenes, i have used 32khz cristal with a vc (trimmer). can any one helps?

regards
 

working of rtc using microcontrollers

hi

have u connected seperate power supply to the rtc chip?

thatz the reason. i think

checkout the datasheet. u'll see some good designs for power down states.

regards
mon
 

8051 real time clock

#include <reg51.h>
#include <absacc.h>
unsigned char hr,min,sec;
void bcdconv(unsigned char mybyte);
void serial(unsigned char x);
sbit RS = P2^2;
sbit DS= P3^7;
sbit RW1= P3^6;
void print(unsigned char *ch);
sbit RW = P2^3;
sbit E = P2^4;
void put (unsigned char ch,bit rs);
void clear(void);
void delay(unsigned int);
void display();
void initlcd(void);
void print(unsigned char *ch);
void main(void)
{
delay(200);
initlcd();
XBYTE[10]=0x20;
XBYTE[11]=0x83;
XBYTE[0]= 0x55;
XBYTE[2]=0x58;
XBYTE[4]=0x36;
XBYTE[7]=0x19;
XBYTE[8]=0x10;
XBYTE[9]=0x04;
XBYTE[11]=0x03;

TMOD=0X20;
TH1=0XFD;
SCON=0x50;
TR1=1;
//display();
while(1)
{
serial("RTC");
hr=XBYTE[4];
bcdconv(hr);
serial(':');
min=XBYTE[2];
bcdconv(min);
serial(':');
sec=XBYTE[0];
bcdconv(sec);
serial(0x0D);
serial(0x0A);
display();
} }
//display();

void bcdconv(unsigned char mybyte)
{
unsigned char x,y;
x=mybyte&0XF0;
x=x|0x30;
y=mybyte&0XF0;
y=y>>4;
y=y|0x30;
serial(y);
serial(x);
}
void serial(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}
void put (unsigned char ch,bit rs)
{
E=1;
RW=0;
P0=ch;
RS=rs;
delay(1);
E=0;
delay(1);
RW=1;
return;
}
void clear(void)
{
put(0x01,0);
delay(100);
return;
}

void delay(unsigned int t)
{
unsigned int k,l;
for(l=0;l<t;l++)
for(k=0;k<975;k++);
return;
}
void initlcd(void)
{
delay(250);
put(0x38,0);
delay(250);
put(0x0C,0);
delay(250);
put(0x0E,0);
delay(250);
put(0x10,0);
delay(250);
put(0x01,0);
delay(250);
put(0x06,0);
//delay(250);
//put(0x0C,0);
print("RTC");
clear();
delay(100);
return;
}
void display()
{
print("hour");
put(hr,1);
put(SBUF,1);
delay(100);
//clear();
put(0xC0,0);
print("min");
put(min,1);
delay(100);
//clear();
put(0x94,0);
print("sec");
put(sec,1);
delay(100);
//clear();
}
void print(unsigned char *ch)
{
while(*ch)
{
put(*ch,1);
//put(0x10,0);
ch++;
}
return;
}

SIR PLEASE TELL ME THE PROBLEM
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top