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

ds18b20 and ds1302 rtc problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

ds18b20 and ds1302 rtc problem
PostPosted: Sun May 11, 2008 11:45 am     Reply with quote

Hi;
i am using ds18b20 temperature sensor and ds1302 rtc but have some problems...
firstly,minute part is increasing after 90 seconds and sometimes minute is decreasing...so rtc is awful Rolling Eyes

secondly,ds18b20 temperature sensor shows 180-200 celcius degree. when i heat it with my hand degree is increasing...


ds18b20.c code

Code:


int onewire_read()
{
int count, data;
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 ); //Sensördem okuma işlemi içinl 1-wire sıfıra çekilir.
output_float(ONE_WIRE_PIN); //1-wire bir yapılır,
delay_us( 8 ); // Sensörün kendine gelmesi beklenir,
shift_right(&data,1,input(ONE_WIRE_PIN)); // sonuc bilgisi alınır.
delay_us( 120 ); //Okuma işlemi zamanı doldurulur.
}
return( data );
}

float ds1820_read()
{
int8 busy=0, temp1, temp2;
signed int16 temp3;
float result;
onewire_reset();
onewire_write(0xCC);
onewire_write(0x44);
while (busy == 0)
busy = onewire_read();
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE);
temp1 = onewire_read();
temp2 = onewire_read();
temp3 = make16(temp2, temp1);
result = (float) temp3 / 2.0;
delay_ms(200);
return(result);
}


main code

Code:



#include <16F877A.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)
#define RTC_SCLK PIN_c4
#define RTC_IO   PIN_c5
#define RTC_RST  PIN_c3
#include <ds1302.c>
#include <ds18b20.c>
#include <lcd.c>
#use rs232 (baud=600, rcv=PIN_C7)

float temp;
int saniye,dakika,saat,gun,ay,yil,haftanin_gunu;

 temp = ds1820_read();

 rtc_get_time(saat,dakika,saniye);
 rtc_get_date(gun,ay,yil,haftanin_gunu);

 lcd_gotoxy(1,1);
 printf(lcd_putc,"%02d/%02d/20%02d      ",gun,ay,yil);
 delay_ms(1000);
 lcd_gotoxy(1,1);
 printf(lcd_putc,"%02d:%02d:%02d  %3.1f%cC",saat,dakika,saniye,temp,223);
 delay_ms(1000);
}
}


PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 11:50 am     Reply with quote

Work on only one problem at a time. First work on the RTC problem.
Remove all code for the ds18b20. Also remove all connections to it
on the PIC. When you get the RTC to work perfectly, then add the
code and connections for the ds18b20 and work on it.
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Sun May 11, 2008 12:23 pm     Reply with quote

@ PCM programmer
I've already tried only rtc code and it doesnt work, the problem is same with only rtc code and rtc with ds18b20. And I dont know how to correct them.

If u can help me I'll be satisfied...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 12:31 pm     Reply with quote

Quote:
I've already tried only rtc code and it doesnt work

Then work on it until it does work. Don't add more code and more
hardware devices until you get the first one working.
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Sun May 11, 2008 1:00 pm     Reply with quote

ok then my fist problem is how I correct ds1302 problem, I dont understand where is wrong?Smile
Code:


#include <16F877A.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)
#define RTC_SCLK PIN_c4
#define RTC_IO   PIN_c5
#define RTC_RST  PIN_c3
#include <ds1302.c>
#include <lcd.c>

int saniye,dakika,saat,gun,ay,yil,haftanin_gunu;

void main()
{
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_1(T1_DISABLED);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_CCP1(CCP_OFF);
   setup_CCP2(CCP_OFF);

   lcd_init();

   rtc_init();

   rtc_set_datetime(9,6,8,2,11,31);

  while(1)
{
   rtc_get_time(saat,dakika,saniye);
   rtc_get_date(gun,ay,yil,haftanin_gunu);

  lcd_gotoxy(1,1);
  printf(lcd_putc,"%02d/%02d/20%02d      ",gun,ay,yil);
  delay_ms(1000);
  lcd_gotoxy(1,1);
  printf(lcd_putc,"%02d:%02d:%02d ",saat,dakika,saniye);

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 1:12 pm     Reply with quote

1. Post a list of all connections to the DS1302 chip. Post the part
number, manufacturer, and value of all external components that are
connected to the DS1302.

This webpage has photos of a DS1302 circuit. They have a 32.768 KHz
watch crystal and a "Super cap" connected to the DS1302. Do you have
those components also ?
http://ghmicro.com/index.php/projects/14-clocks/11-pic-16f877-a-ds1302-simple-clock


2. What pins on the PIC are used for the LCD ? Post a list.
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Sun May 11, 2008 1:47 pm     Reply with quote

the connections on DS1302:

X1-X2 32.768kHz
RST pin c3
I/O pin c5
SCLK pin c4

but the difference between my circuit and the circuit at the link is the capacity on Vcc2. i wired 3 volts here as shown in the datasheet. do i have to use capasity?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 2:18 pm     Reply with quote

Do you have Vdd and ground connected to the DS1302 ?

What is the Vdd voltage on the DS1302 and on the PIC ?
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Sun May 11, 2008 2:20 pm     Reply with quote

of course I connected Vdd 5v gnd 0V, PIC's Vdd is 5v, too.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 2:27 pm     Reply with quote

I looked in my parts box and I have a ds1302. I am going to hook it up
and finish this thing.

Post your compiler version. It's given at the top of the .LST file.
The .LST file is in your project directory.
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Sun May 11, 2008 2:31 pm     Reply with quote

This is the compiler version,
CCS PCM C Compiler, Version 3.182, 16465
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 3:17 pm     Reply with quote

I was able to make it work. It required one change, as shown in the
code below. After that change is made, then it displays this on the lcd:
Quote:

09/06/2008
11:31:00

The seconds increment from 00 to 01, 02, 03, etc.

In the code below the lcd_gotoxy() statement must have coordinates
of (1, 2) as shown in bold below. If you change it to (1, 2) it should work.
Quote:

while(1)
{
rtc_get_time(saat,dakika,saniye);
rtc_get_date(gun,ay,yil,haftanin_gunu);

lcd_gotoxy(1,1);
printf(lcd_putc,"%02d/%02d/20%02d ",gun,ay,yil);
delay_ms(1000);
lcd_gotoxy(1, 2); // *** Change this line
printf(lcd_putc,"%02d:%02d:%02d ",saat,dakika,saniye);
}
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Sun May 11, 2008 3:31 pm     Reply with quote

thanks alot, but I must use 2nd line for another application, cant I write date and clock on first line...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 3:33 pm     Reply with quote

But what happens if you test the code as shown in my post ?

Does it start working ?
bittersweet



Joined: 23 Apr 2008
Posts: 22

View user's profile Send private message

PostPosted: Sun May 11, 2008 3:39 pm     Reply with quote

yes I tried and it is working:) thanks alot but is there any way to write them on the same line
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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