CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RTC DS1302 an PIC 18F452

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
CCSgues
Guest







RTC DS1302 an PIC 18F452
PostPosted: Sun May 16, 2004 7:08 am     Reply with quote

Has anyone experiences with maxim's DS1302 and DS32kHz.


I've connected the DS32Khz clock output directly with DS1302's X1 and X2 clock input and I'm using CCS' driverfile DS1302.c, but I got strange outputs for hour, min and sec.

Is there any bug in the soure?


Code:
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#include <DS1302.C>                             //Uhrentreiber

byte day,mth,year,dow,hour,min,sec;

const unsigned int conv[16] = {0,10,20,30,40,50,60,70,80,90,90,90,90,90,90,90 };

#define fromBCD(x) ((x & 0xf)+conv[(x>>4)])
   unsigned int toBCD(unsigned int val)
{
   int ctr;
   for (ctr=0;ctr<10;ctr++)
   {
      if (val == conv[ctr])
      return(ctr<<4);
      else if (val < conv[ctr]) break;
   }
   --ctr;
   return((val-conv[ctr])+(ctr<<4));
}                                                                                      //Definiton RTC_BCD_Code ende



////////////////////////////////////////////////////////////////////////////////
//                             RTD DS1302 Maxim                               //
////////////////////////////////////////////////////////////////////////////////
//                                 DS1302.C                                   //
//                       Driver for Real Time Clock                           //
//                                                                            //
//    rtc_init()                                   Call after power up        //
//                                                                            //
//    rtc_set_datetime(day,mth,year,dow,hour,min)  Set the date/time          //
//                                                                            //
//    rtc_get_date(day,mth,year,dow)               Get the date               //
//                                                                            //
//    rtc_get_time(hr,min,sec)                     Get the time               //
//                                                                            //
//    rtc_write_nvr(address,data)                  Write to NVR               //
//                                                                            //
//    data = rtc_read_nvr(address)                 Read from NVR              //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

byte get_bcd() {
  char first,second;

  do {
    first=getc();
  } while ((first<'0') || (first>'9'));
  putc(first);
  first-='0';

  do {
    second=getc();
  } while ((second<'0') || (second>'9'));
  putc(second);

  return((first<<4)|(second-'0'));
}

void set_clock()
{
   puts("Year 20: ");
   year=get_bcd();
   puts("Month: ");
   mth=get_bcd();
   puts("Day: ");
   day=get_bcd();
   puts("Weekday 1-7: ");
   dow=get_bcd();
   puts("Hour: ");
   hour=get_bcd();
   puts("Min: ");
   min=get_bcd();
   puts("sec");
   sec=get_bcd();

   rtc_set_datetime(day,mth,year,dow,hour,min);

   printf("\n\r Eingestelltes Datum: %2d,%2d,%2d, um %2d:%2d:%2d Uhr\n",fromBCD(day),fromBCD(mth),fromBCD(year),fromBCD(hour),fromBCD(min),fromBCD(sec));

}

void get_clock()
{
rtc_get_time(hour,min,sec);
printf("\n\r...%2d:%2d:%2d...\n",fromBCD(hour),fromBCD(min),fromBCD(sec));
delay_ms(1000);
}



void main()
{
rtc_init();

   set_clock();

 printf("\n\r...Begin Main...\n");

  do {
      get_clock();

     } while (TRUE);  //end true

}
Somkiat



Joined: 30 Mar 2004
Posts: 8

View user's profile Send private message Visit poster's website

PostPosted: Sun May 16, 2004 7:42 am     Reply with quote

Hi
about this question try to look this site :
http://www.geocities.com/contax_electronics/ctpic84_examples/ds1302_84.html
CCSgues
Guest







PostPosted: Sun May 16, 2004 9:56 am     Reply with quote

Is it right to connect the DS32khz's 32.768kHz output directly to DS1302's Pin 2 and 3 or do I have to connect Pin 2 to 32.768kHz output and Pin 3 to gnd?
I don't know how to connect the DS32kHz
http://pdfserv.maxim-ic.com/en/ds/DS32kHz.pdf

thx Fabian
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

DS32KHZ to DS1302
PostPosted: Sun May 16, 2004 5:42 pm     Reply with quote

The DS1302 data sheet tells you how it should be connected with the 32KHZ output to pin X1 and leave X2 floating.

The DS32KHZ sheet also shows you how to connect it for low curent consumption. PLEASE read the data sheets before asking.....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group