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

DS1621 and 18F2550 problem...??

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



Joined: 08 Sep 2006
Posts: 182

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

DS1621 and 18F2550 problem...??
PostPosted: Wed Sep 26, 2007 4:01 am     Reply with quote

Hello,

I have connected (corerctly I beleive) a DS1621 to the 18F2550...
I included the DS1621.c in mine program... but keep reading the same wrong value (0x1E)... When looking whith the scoop I see that there is communication between the DS1621 and the pic but why o why I keep on reading these strange value???
Include the main.. DS1621.c is like the driver file from CCS..
Code:

#include "C:\MentorProjects\Koffie_Zetter\Kofiie_Zetter.h"
#include <string.h>
#include <stdlib.h>
#include <input.c>
#include <ds1621.c>
#include <ds1306.c>

#define  RELAIS              PIN_C1

int16 month_easter, day_easter, coffee = 1;

BYTE get_number() {
  char first,second;

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

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

  if(second=='\r')
    return(first);
  else
    return((first*10)+(second-'0'));
}

void set_clock(){
   BYTE day, mth, year, dow, hour, min;

   printf("\r\nPress ENTER after 1 digit answers.");
   printf("\r\nYear 20: ");
   year=get_number();
   printf("\r\nMonth: ");
   mth=get_number();
   printf("\r\nDay: ");
   day=get_number();
   printf("\r\nWeekday 1-7: ");
   dow=get_number();
   printf("\r\nHour: ");
   hour=get_number();
   printf("\r\nMin: ");
   min=get_number();

   rtc_set_datetime(day,mth,year,dow,hour,min);
   printf("\r\n\n");
}

easter(year, month, day){

   int16 year_easter, c, n, k, i, j, l;
   year_easter = year + 2000;
   c = year / 100;
   n = year - 19 * ( year / 19 );
   k = ( c - 17 ) / 25;
   i = c - c / 4 - ( c - k ) / 3 + 19 * n + 15;
   i = i - 30 * ( i / 30 );
   i = i - ( i / 28 ) * ( 1 - ( i / 28 ) * ( 29 / ( i + 1 ) ) * ( ( 21 - n ) / 11 ) );
   j = year + year / 4 + i + 2 - c + c / 4;
   j = j - 7 * ( j / 7 );
   l = i - j;
   month_easter = 3 + ( l + 40 ) / 44;
   day_easter = l + 28 - 31 * ( month_easter / 4 );

      if((month == month_easter) & (day == day_easter) || (month == month_easter) & (day == (day_easter+1)))
      {
      // Dan is het nu paashazen eerste of tweede en mag ie wel uit......
      coffee = 0;
      }
   coffee = 1;
}

newyearsday(month, day){

   if((month == 1) & (day == 1))
   {
   // Happy NEWYEAR!!!!!!!!!!!!!!!
   coffee = 0;
   }
   coffee = 1;
}

queensday(month, day){

   if((month == 4) & (day == 30))
   {
   // Happy Birthday!!!!!!!!!!!!!!!
   coffee = 0;
   }
   coffee = 1;
}

christmas(month, day){

   if((month == 12) & (day == 25) || (month == 12) & (day == 26))
   {
   // Jipeeee :-( !!!!!!!!!!!!!!!
   coffee = 0;
   }
   coffee = 1;
}

void whitmundy(month, day){

   int16 month_whitmundy, day_whitmundy;

   day_whitmundy = day_easter + 20;
   if(day_whitmundy > 31)
   {
   day_whitmundy = day_whitmundy - 31;
   month_whitmundy = month_whitmundy + 2;
   }
   month_whitmundy = month_whitmundy + 1;

      if((month == month_whitmundy) & (day_whitmundy == day))
      {
      // Pinksteren wat fijn maar weer
      coffee = 0;
      }
   coffee = 1;
}

void ascension_day(month, day){

   int16 month_ascension_day, day_ascension_day;

   day_ascension_day = day_easter + 39;
   if(day_ascension_day > 31)
   {
   day_ascension_day = day_ascension_day - 31;
   month_ascension_day = month_ascension_day + 2;
   }
   month_ascension_day = month_ascension_day + 1;

      if((month == month_ascension_day) & (day_ascension_day == day))
      {
      // hemelvaart.. ook zooo leuk
      coffee = 0;
      }
   coffee = 1;
}

void main() {

   char cmd;
   BYTE day, month, year, dow, hour, min, sec, day_old, hour_old, dow_old;
   signed long temp;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   set_tris_c(0X80);

   rtc_init();
   init_temp();
/*
   printf("\r\nPress S to change, D to display: ");

   do {
      cmd=getc()&0xdf;
   } while ((cmd!='D')&&(cmd!='S'));

   if(cmd=='S')
   set_clock();
   printf("\r\n");
  */
   output_low(RELAIS);
     
   while (1) {
      rtc_get_date( day, month, year, dow);
      rtc_get_time( hour, min, sec );
    //  printf("%02u/%02u/%02u %02u %02u:%02u:%02u\r                   ",day,month,year,dow,hour,min,sec);//dow = Day Of Week
      delay_ms(1000);
   init_temp();
      temp = read_full_temp();
      temp = (temp/100);
      temp = ((temp -32)/1.8);
      printf("%4LX\r", temp);
temp = 0;
   

     if(coffee)
      {
      output_high(RELAIS);
      }

      if(day != day_old)               // Vakantie oid pasen,pinksteren etc.
      {
         easter(year, month, day);
         newyearsday(month, day);
         queensday(month, day);
         christmas(month, day);
         whitmundy(month, day);
         ascension_day(month, day);

         if(coffee)
         {
         output_high(RELAIS);
         }else
         {
         output_low(RELAIS);
         }

      }

      if(hour != hour_old)             // Voor 07:00 en na 19:00
      {
         if((hour > 6) & (hour < 19))
         {
         output_high(RELAIS);
         }else
         {
         output_low(RELAIS);
         }
      }

      if(dow != dow_old)               // Weekend!!!!!
      {
         if((dow == 6) || (dow == 7))
         {
         output_low(RELAIS);
         }else
         {
         output_high(RELAIS);
         }
      }

      dow_old = dow;
      day_old = day;
      hour_old = hour;
   }
}
Jody



Joined: 08 Sep 2006
Posts: 182

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

Solved ... almost
PostPosted: Wed Sep 26, 2007 7:14 am     Reply with quote

Oke at this moment I get sometimes the correct value and some time 0x1E... wich is not what I should get....

I removed 'only' the Farhenheid to Celcius conversion....

Why o why is it so instable???
Jody



Joined: 08 Sep 2006
Posts: 182

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

Solved ... almost
PostPosted: Wed Sep 26, 2007 7:43 am     Reply with quote

Oke at this moment I get sometimes the correct value and some time 0x1E... wich is not what I should get....

I removed 'only' the Farhenheid to Celcius conversion....

Why o why is it so instable???
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