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

ds1307 help please

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



Joined: 18 Aug 2007
Posts: 2

View user's profile Send private message

ds1307 help please
PostPosted: Sat Aug 25, 2007 3:33 pm     Reply with quote

hi all
i have disturbing problem with rtc clock uses ds1037 ,its work just for one time then make load and stop working .please help me
here is my code:
Code:


#include <18f4620.h>
#include <stdlib.h>
#FUSES NOWDT, XT
#use delay(clock=4000000)
#include<ds1307.c>
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
#include <INPUT.C>

int8 data, fb,value ,cmd;
long int eeprom_address,i,j;


int8 dow, hr, min, hr_eeprom, min_eeprom,sec,min_ring;
int Add1, Add2,duration;
int k, counter,address,prev_min;


int1 flag_ring,on_flag,int_flag;

#int_rda
void serial_isr()  {
cmd=gethex();

      if (cmd==0xc1)
   {
   i=0;

   }
     else
     if (cmd==0xc2)
   {
   i=100;

   }else

      if (cmd==0xc3)
   {
   i=200;

   }
     else
     if (cmd==0xc4)
   {
   i=300;

   }
     else
     if (cmd==0xc5)
   {
   i=400;

   }
      else
      if (cmd==0xc6)
   {
   i=500;

   }
     else
     if (cmd==0xc7)
   {
   i=600;

   }

      else
      if (cmd==0x77)//on
   {
   on_flag=1;
    goto end;
   }
      else
      if (cmd==0x88)//off
   {
   on_flag=0;
     goto end;
   }

         else
      if (cmd==0x99)//set clock
   {

   dow=gethex();
   hr=gethex();
   min=gethex();
   write_ds1307(3,dow);
   write_ds1307(2,hr);
   write_ds1307(1,min);
     goto end;
   }


   j=i;
   address=i;

   while(i<(j+72)) {
   value =gethex();

   if(((i%2)==0))
   address++;

   write_eeprom(address , value);

   i++;}
   end:
   int_flag=1;
}



void main()
{

   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);

   init_ds1307();          // initial DS1307

   write_ds1307(0,0x59); //sec
   write_ds1307(1,0x00); //min
   write_ds1307(2,0x01); //hr
   write_ds1307(3,0x01); //day
   write_ds1307(4,0x01); //date
   write_ds1307(5,0x01); //mnth
   write_ds1307(6,0x01); //year

   output_low(PIN_D0);
   i=0;
   while (TRUE)   /
                 
{

      on_flag=1;
      if (on_flag==1)
      {



      START:



            dow = read_ds1307(3);   //Determine the daya of the week
            Add1=(dow-1)*100+1;      //Start address equation due to dow
            Add2=dow*100;
            hr_eeprom = read_eeprom(Add1);

               hr = read_ds1307(2);    //Read the current hour
               min = read_ds1307(1);   //Read the current minute
               if(min!=prev_min)
               ring_flag=0;
               for (counter=Add1;counter<Add2;counter+=2)
               {
                  j = counter + 1;
                  hr_eeprom= read_eeprom(counter);
                  min_eeprom = read_eeprom(j);
                  if (hr_eeprom==hr)
                  {
                     if (min_eeprom == min)
                     {
               
                        output_high(PIN_D0);
                        delay_ms(500);
                        output_low(PIN_D0);
                        min_ring = min_eeprom;
                        prev_min=min;
                       
                        goto START;
                     }
                     delay_ms(500);
                  }
               }  //end for
               goto START;
            }  //end else
      }  //on_flag
   }//while true
}  //end main






i use driver on
http://www.sixca.com/micro/pic/ds1307/

problem is in code not in connection i guess
Crying or Very sad
mickent



Joined: 18 Feb 2007
Posts: 22
Location: TN, USA

View user's profile Send private message

PostPosted: Sun Aug 26, 2007 8:38 am     Reply with quote

Try removing the single "/" after "while(TRUE)"
_________________
Mick
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Aug 26, 2007 11:00 am     Reply with quote

Change 'address' to a long int.
You are using variable j both in the interrupt and in main, don't do this as it will result in data corruption.

A few design hints:
- Use of the goto command is considered poor design. Basic andd assembly language use it everywhere but the C-language provides better language elements to get the same result.
- The large if/else construction is easier to understand and maintain when replace by a switch statement.
- Try to avoid using global variables. It is more difficult to check your code with global variables as we have to check your whole program to see if this variable is changed in some other places as well. You wouldn't have made the error of using variable 'j' both in the interrupt and in main when it had been a local variable. Another advantage is that the compiler can create more efficient code by reusing memory space of local variables.
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