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
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
 

ds1302 c code

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


best regards
 
ds1302 pic

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

ds1302 source code

Hi Elavionic & all,

I am using HITECH C-Compiler.

-IMP
 

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.
 

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.
 

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:
 

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
 
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.
 

pic ds1302

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

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:
 

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.
 

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
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

Back
Top