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

how to call a function in main

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



Joined: 07 Feb 2010
Posts: 2

View user's profile Send private message

how to call a function in main
PostPosted: Tue Feb 23, 2010 7:29 am     Reply with quote

Hi everyone. Hope you guys can help me here. I worked with RTC DS1307 and its working fine but when I get to call a function in the void main, my RTC won't tickle anymore.

Here is my sample code:
Code:

void main()
{
   //enable_interrupts(GLOBAL);
   port_b_pullups(TRUE);

   lcd_init();
   kbd_init();

   gca_ds1307_regs[DS1307_SECONDS_REG] = 30; // 30 seconds
   gca_ds1307_regs[DS1307_MINUTES_REG] = 59; // 59 minutes
   gca_ds1307_regs[DS1307_HOURS_REG] = 23; // 11 PM
  //gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG]= 0; // Skip this.
   gca_ds1307_regs[DS1307_DATE_REG] = 22; // 22th
   gca_ds1307_regs[DS1307_MONTH_REG] = 02; // February
   gca_ds1307_regs[DS1307_YEAR_REG] = 10; // 2010

   ds1307_set_date_time();

   while(1)
   {
   delay_ms(1000);
   ds1307_read_date_time();

   // Get these into variables with shorter names, so I can
   // put them into printf more easily.
   sec = gca_ds1307_regs[DS1307_SECONDS_REG];
   min = gca_ds1307_regs[DS1307_MINUTES_REG];
   hrs = gca_ds1307_regs[DS1307_HOURS_REG];
   day = gca_ds1307_regs[DS1307_DAY_OF_WEEK_REG];
   date = gca_ds1307_regs[DS1307_DATE_REG];
   month = gca_ds1307_regs[DS1307_MONTH_REG];
   yr = gca_ds1307_regs[DS1307_YEAR_REG];
   
   printf(lcd_putc, "\n\%02d:\%02d:\%02d", hrs,min,sec);
 
    room_controller();
   }

  //disable_interrupts(GLOBAL);
}


Here is the function i am to call:
Code:

//===========================================//
//           room controller                 //
//===========================================//

void room_controller(void)
   {

   lcd_gotoxy(1,2);
   printf(lcd_putc, "PERSONS:%d    ", persons);

      while(1)
        {

            if(input(SENS_IN)){
               while(input(SENS_IN));
               while(!input(SENS_OUT));
               while(input(SENS_OUT));

                persons++;
                OUTPUT_HIGH(DEVICE);
                lcd_gotoxy(1,2);
                printf(lcd_putc, "PERSONS:%d    ", persons);
                delay_ms(600);
                }
             else if(input(SENS_OUT))
                {
                 while(input(SENS_OUT));
                 while(!input(SENS_IN));
                 while(input(SENS_IN));

                if(persons>0){
                   persons--;
                   lcd_gotoxy(1,2);
                   printf(lcd_putc, "PERSONS:%d   ", persons);
                   delay_ms(600);}
                else if(persons==0){
                  OUTPUT_LOW(DEVICE);
                  lcd_gotoxy(1,2);
                  printf(lcd_putc, "PERSONS:%d    ", persons);
                  delay_ms(600);}
           }
         }
   }

How can I call other function without interrupting my RTC?
thanks in advance!!!
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

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

PostPosted: Tue Feb 23, 2010 8:23 am     Reply with quote

Well, your problem is that the function you are calling has an infinite while loop in it. Control never returns to main. There are a variety of ways of fixing it but since main also has a while loop you might start by just taking the while loop out of the called function and let main call that function repeatedly.
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