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.

C code for interfacing DS1302 with PIC16F877

Status
Not open for further replies.

imp

Newbie level 5
Newbie level 5
Joined
Jun 7, 2004
Messages
10
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
172
ds1302 code

Hi all,

I need C code for interfacing DS1302 RTC with PIC16F877

THANKS

IMP
 

C-Man

Advanced Member level 4
Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,059
Helped
90
Reputation
180
Reaction score
17
Trophy points
1,318
Activity points
10,189
ds1302 c code

You should get some info by checking this:
**broken link removed**
**broken link removed**


best regards
 

Elavionic

Member level 5
Member level 5
Joined
Apr 6, 2002
Messages
87
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Portugal
Activity points
1,011
ds1302 pic

You must tell what compiler are you using.
PCW from ccs already has a library for DS1302.
 

imp

Newbie level 5
Newbie level 5
Joined
Jun 7, 2004
Messages
10
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
172
ds1302 source code

Hi Elavionic & all,

I am using HITECH C-Compiler.

-IMP
 

Elavionic

Member level 5
Member level 5
Joined
Apr 6, 2002
Messages
87
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Portugal
Activity points
1,011
ccs ds1302

Go to hxxp://www.htsoft.com/forum/all/search.php?Cat= and search for DS1302 at HITECH forum, maybe you'll find some info. If you like i'll put here the driver from CCS, maybe you can port the code for picc.
 

sinatra

Full Member level 4
Full Member level 4
Joined
Mar 29, 2002
Messages
213
Helped
18
Reputation
36
Reaction score
7
Trophy points
1,298
Location
Neverland
Activity points
2,842
pic16f877 ds1302

Hello Imp.
You can find a complete C example in PICC from ccs.
The file is EX_RTCLK.C and it is in the directory:
C:\Program Files\PICC\Examples
S.
 

Manish Sharma

Newbie level 6
Newbie level 6
Joined
Jun 22, 2004
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
137
ds1302.c

hi there ,
for programming of PIC in C u should go for the book

1.) PIC C -An Introduction to programming the PIC in C ( by Nigel Garner & Mark sigsmund)
****
2.) PIC Microcontroller Project Book **
3.) Programming & Customizing the OOPic Micro*
4.)C for PICmicros (Hobbyist) *****

for data sheet of PIC16F877 go for
**broken link removed**

hope you got ur way :eek:
 

imp

Newbie level 5
Newbie level 5
Joined
Jun 7, 2004
Messages
10
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
172
ds1302 pic16f877

Hi all,

DS-1302 is successfully interfaced,and here is the code.

void display_write(void)
{
unsigned char yr1, mn1, date1, dy1, hr1, min1, sec1,line1[16];

reset_3w();
wbyte_3w(0xBF); /* clock burst */
sec1 = rbyte_3w();
min1 = rbyte_3w();
hr1 = rbyte_3w();
dy1 = rbyte_3w();
date1 = rbyte_3w();
mn1 = rbyte_3w();
yr1 = rbyte_3w();
reset_3w();

line1[0]=((date1/10) % 10)+0x30;
line1[1]=((date1) % 10)+0x30;
line1[2]=0x2F; //symbol "/"
line1[3]=((mn1/10) % 10)+0x30;
line1[4]=((mn1) % 10)+0x30;
line1[5]=0x2F;
line1[6]=((yr1/10) % 10)+0x30;
line1[7]=((yr1) % 10)+0x30;
line1[8]=((hr1/10) % 10)+0x30;
line1[9]=((hr1) % 10)+0x30;
line1[10]=0x3A; //symbol ":"
line1[11]=((min1/10) % 10)+0x30;
line1[12]=((min1) % 10)+0x30;
line1[13]=0x3A;
line1[14]=((sec1/10) % 10)+0x30;
line1[15]=((sec1) % 10)+0x30;

lcd_goto(0x00);
lcd_puts(line1);
}

void initialize_DS1302()
{
reset_3w();
wbyte_3w(0x8e); /* control register */
wbyte_3w(0); /* disable write protect */
reset_3w();
wbyte_3w(0x90); /* trickle charger register */
wbyte_3w(0xab); /* enable, 2 diodes, 8K resistor */
reset_3w();
wbyte_3w(0xbe); /* clock burst write (eight registers) */
wbyte_3w(sec);
wbyte_3w(min);
wbyte_3w(hr);
wbyte_3w(dy);
wbyte_3w(date);
wbyte_3w(mn);
wbyte_3w(yr);
wbyte_3w(0); /* must write control register in burst mode */
reset_3w();
}

void reset_3w()
{
RTC_SCLK = 0;
RTC_RS = 0;
RTC_RS = 1;
}

void wbyte_3w(unsigned char W_Byte) //write into DS1302
{
unsigned char i;

TRISB = 0b00000011; //RB3 as o/p
for(i = 0; i < 8; ++i)
{
RTC_IO = 0;
if(W_Byte & 0x01)
{
RTC_IO = 1; /* set port pin high to read data */
}
RTC_SCLK = 0;
RTC_SCLK = 1;
W_Byte >>= 1;
}
}

unsigned char rbyte_3w() //read from DS1302
{
unsigned char i;
unsigned char R_Byte;
unsigned char TmpByte;

TRISB = 0b00001011; //RB3 as i/p

R_Byte = 0x00;
RTC_IO = 1;
for(i=0; i<8; ++i)
{
RTC_SCLK = 1;
RTC_SCLK = 0;
TmpByte = (uchar)RTC_IO;
TmpByte <<= 7;
R_Byte >>= 1;
R_Byte |= TmpByte;
}

TRISB = 0b00000011; //RB3 as o/p
return R_Byte;
}


Thanks to all.

-IMP
 

tushar

Newbie level 1
Newbie level 1
Joined
Dec 15, 2004
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
14
pic ds 1302

Hi IMP,
I am doing a project using DS1302 and 16F877. I am trying to use your code in my project. But it's not working. I need only minutes and hours from DS302. I have modified your code accordingly but it's not working. Is it important to access 1302 in Burst mode, b'cause i am not using it in that way. My timer shows erratic behaviour. If you could help me it would be great.I am attaching my source code file for your convenience.
Regards,
Tushar.
 

nikhileshsawarkar

Newbie level 5
Newbie level 5
Joined
Jul 17, 2006
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,352
pic ds1302

HI Friends,
Im interfacing DS1302 with AT89s8253.
My compiler is SDCC and KEILuv2
Need sample code.
regards,
Nikhilesh
 

arge

Newbie level 1
Newbie level 1
Joined
Sep 23, 2006
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
ds1302 picc

nikhileshsawarkar said:
HI Friends,
Im interfacing DS1302 with AT89s8253.
My compiler is SDCC and KEILuv2
Need sample code.
regards,
Nikhilesh

did you find any sample code nikhi? i need the same thing i use at89c51,keiluv2,ds1302 on proteus isis

please help me:cry:
 

Blue_Key

Newbie level 2
Newbie level 2
Joined
Sep 21, 2008
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,293
pic16f877 c code

Hello,

I do the same job, DS1302 with 16F877, but everything i got the same bug...

I have try different way, but, each time i got this values:

0 - 1 - 0 - 3 - 0 - 1 - 0 - 7 - 0 - 1 instead 0-1-2-3-...-8-9, and this for each digits.

If someone know why??

Here is my code: https://pastebin.com/febf0f69


thanks.
 

malikmuhammadali

Newbie level 5
Newbie level 5
Joined
Dec 16, 2008
Messages
8
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,283
Activity points
1,342
I've made the schematic, but the simul inisis doesn't work. time is 00:00:00, and date 00:00:2000. can u help me pls?
proteus7
ds1307
simulation only show time and date when i2c debugger connected.

 

    V

    Points: 2
    Helpful Answer Positive Rating

MODCHIP

Junior Member level 3
Junior Member level 3
Joined
Feb 13, 2008
Messages
29
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,492
just try to change the 5k resistor of SDA and CLK wiht tow resistor called PULLUP in isis
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top