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 support@ccsinfo.com

Another DS1307 driver
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
faizkeats



Joined: 01 Aug 2010
Posts: 1

View user's profile Send private message

An error
PostPosted: Sun Aug 01, 2010 12:23 am     Reply with quote

In last two statements where printf is used, it gives me an error:
Expecting a close paren
Can someone help me in this regard? Rest of the code is same as given above by Phil. Thanks.
matheuslps



Joined: 29 Sep 2010
Posts: 73
Location: Brazil

View user's profile Send private message MSN Messenger

PostPosted: Sun Dec 05, 2010 9:26 pm     Reply with quote

I know this is an old topic, but here the code worked like a charm! :D

BUT, can someone tell me what is dow? From:

Code:
ds1307_set_date_time(day,mth,year,dow,hour,min,sec)  Set the date/time


thanks
Phil



Joined: 09 Sep 2003
Posts: 12

View user's profile Send private message

PostPosted: Mon Dec 06, 2010 2:08 am     Reply with quote

Day of week: 1 = Sunday, 2= Monday....7=Saturday
matheuslps



Joined: 29 Sep 2010
Posts: 73
Location: Brazil

View user's profile Send private message MSN Messenger

PostPosted: Mon Dec 06, 2010 6:43 am     Reply with quote

Thanks man!
ajaygautam.ic



Joined: 28 Apr 2011
Posts: 1

View user's profile Send private message

PostPosted: Thu Apr 28, 2011 12:14 am     Reply with quote

Hi ,
I am new for this, please correct me if I am wrong.
This code is not looking a driver code. Means I am not able to get that where is the init_module, cleanup_module, device_open, device_release, device_read, device_ioctl functions in this code ?
Please clarify me.

--Thanx
Ajay Gautam
PCM programmer



Joined: 06 Sep 2003
Posts: 20268

View user's profile Send private message

PostPosted: Thu Apr 28, 2011 11:13 am     Reply with quote

This is not a Linux driver. It's for small PIC micro-controllers, and is
written for the CCS C compiler. These micro-controllers don't have
an operating system.
Koslov



Joined: 02 May 2011
Posts: 2

View user's profile Send private message Send e-mail

PostPosted: Wed May 11, 2011 11:42 am     Reply with quote

Hi,
I've used that driver with a pic18f4550, but for some weird reason the display doesn't show the hours, and the minutes parameter freezes when arrive at 59 minutes, here's my code
Code:
#include "C:\Users\Koslov\Desktop\Electronica\C08 - Elec. Sistemes\rellotge_lcd\programa.h"
#define loader_end 0x7ff
#define loader_size 0x6ff
#build (reset=loader_end+1,interrupt=loader_end+9)
#org 9, loader_end{}
#include <ds1307.c>
#include <string.h>
#include <lcd2011_noread.c>
#include <ds1621M.c>
int min,sec,hrs,dow,month,yr,day,a;
void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   setup_oscillator(False);
   lcd_init();
   init_temp(1);
  ds1307_init();
  ds1307_set_date_time(15,6,5,2,23,58,50);


  while(1)
  {
      ds1307_get_time(hrs,min,sec);
      ds1307_get_date(day,month,yr,dow);
     // hh : mm : ss
     //1234567891234
      lcd_gotoxy(10,1);
      if(sec>9 ){
      printf(lcd_putc,": %u ",sec);}
      else{printf(lcd_putc,": 0%u",sec);}
      lcd_gotoxy(5,1);
      if(min>9){
      printf(lcd_putc,": %u ",min);}
      else{(lcd_putc,": 0%u",min);}
      lcd_gotoxy(2,1);
      if(hrs>9){(lcd_putc,"%u ",hrs);}
      else{(lcd_putc,"0%u ",hrs);}
      lcd_gotoxy(1,2);
      printf(lcd_putc,"%u - %u - %u : %u",day month yr dow);
  }

}

can someone tell me how to solve this?
PCM programmer



Joined: 06 Sep 2003
Posts: 20268

View user's profile Send private message

PostPosted: Wed May 11, 2011 1:39 pm     Reply with quote

Your printing code is too complicated. Test it with the example code
for main() in the first post in this thread.

If it doesn't work, then make a post in the main CCS forum.
It's better to have a long thread about problems in the main forum.
Koslov



Joined: 02 May 2011
Posts: 2

View user's profile Send private message Send e-mail

PostPosted: Mon May 16, 2011 7:57 am     Reply with quote

Thank you PCM programmer, compiling the example program made me see the trouble was in my program, and its a noob one, I forgot to put printf function at the hours parameter Embarassed
mutthunaveen



Joined: 08 Apr 2009
Posts: 100
Location: Chennai, India

View user's profile Send private message

same hang problem...now solved
PostPosted: Sun Nov 27, 2011 11:51 pm     Reply with quote

Hello
yesterday, when i first programmed DS1307 i got the same problem.. hanging and not refreshing auto resetting etc... i analyzed my code and did the following things

1. use proper pullup resistors for I2C communication (i used 10K) hardware not in software...
2. Use WDT for 500 - 800 ms as your PIC18F supports.
3. for first compilation set date and time and for next compilation comment set date and time function, and then load that again. (when WDT reset is done then there will be no resetting of time).

hope it will help Cool
small_chick



Joined: 17 Jul 2012
Posts: 53

View user's profile Send private message

must set clock every run
PostPosted: Fri Jul 20, 2012 10:39 am     Reply with quote

hadeelqasaimeh wrote:
Quote:

Its work fine with this driver but this mean i must set clock every run!!!!!!! How to avoid this?

I haven't understood what you mean, hadeelqasaimeh ! Would you mind explaining more clearly ? Thanks!
small_chick



Joined: 17 Jul 2012
Posts: 53

View user's profile Send private message

PostPosted: Sat Jul 21, 2012 7:20 pm     Reply with quote

Phil, I'd like to ask you this:

1/- if I assign variables such as: date,year,hr,sec... in "char" or "int8" type => is it okay ?

2/- I've contracted 2 subroutines: bin2bcd & bcd2bin, as follow:

Code:

//subroutine converting BCD to Binary.   
char bcd2bin(char bcd_value)
{
return((bcd_value >> 4) * 10 + (bcd_value & 0x0F));
}

//---------------------------------------
//subroutine converting Binary to BCD.
char bin2bcd(char binary_value)
{
return( (swap(binary_value/10)) & (binary_value % 10));
}

if it has any problems, please let me know !
kaem1189



Joined: 27 Dec 2011
Posts: 12

View user's profile Send private message

PostPosted: Sat Jun 01, 2013 8:20 pm     Reply with quote

I know that this is already a decade old thread. I am wondering why there is a ds1307_init() code. I think it makes no sense (unless there is function that stops the oscillator). init command fetch the value from seconds register and set oscillator enable bit and disable the squarewave output as well.. but ds1307_setdatetime also do those routine(except fetching seconds value of course)
freesat



Joined: 08 Feb 2011
Posts: 32

View user's profile Send private message

ds1307 problems with interrupts
PostPosted: Mon Sep 16, 2013 6:09 pm     Reply with quote

I have used this code, it really works, but is not perfect. I have found errors when any timer(x) interrupt is enabled, this causes data written or read with errors, looks like interrupt is freezing code, then continues and data lost some bits.

Can anyone confirm that?

I'm not posting sample code because is not my code problem.
PCM programmer



Joined: 06 Sep 2003
Posts: 20268

View user's profile Send private message

PostPosted: Tue Sep 17, 2013 1:59 pm     Reply with quote

Look at this driver code for the pcf8583. This driver assumes you are
using interrupts in another part of your main program:
http://www.ccsinfo.com/forum/viewtopic.php?t=27988
The routines that call CCS i2c library functions (i2c_start, i2c_write, etc).
are protected from interrupts by being enclosed with disable/enable lines
for Global interrupts.

I suggest that you edit the ds1307 driver routines and protect them in
the same way. See if that fixes the problem.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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