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

Problem with ds1302

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



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

Problem with ds1302
PostPosted: Wed Jul 06, 2005 1:31 pm     Reply with quote

hallo i have problem with ds1302 give to me always 1:1:1

my code is this:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <DS1302.C>



BYTE day=1,mth=2,year=3,dow=4,hour=5,min=6,sec=7;
//bcd def
const unsigned int conv[16] = {
0,10,20,30,40,50,60,70,80,90,90,90,90,90,90,90 };

#define fromBCD(x) ((x & 0xf)+conv[(x>>4)])
unsigned int toBCD(unsigned int val)
{
int ctr;
for (ctr=0;ctr<10;ctr++)
{
if (val == conv[ctr])
return(ctr<<4);
else if (val < conv[ctr]) break;
}
--ctr;
return((val-conv[ctr])+(ctr<<4));
} // end bcd def

byte get_bcd() {
char first,second;

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

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

return((first<<4)|(second-'0'));
}

void set_clock()
{

puts("Year 20: ");
year=get_bcd();
puts("Month: ");
mth=get_bcd();
puts("Day: ");
day=get_bcd();
puts("Weekday 1-7: ");
dow=get_bcd();
puts("Hour: ");
hour=get_bcd();
puts("Min: ");
min=get_bcd();
puts("sec");
sec=get_bcd();

printf("\n\r %2d,%2d,%2d, %2d um %2d:%2d\n",fromBCD(day),fromBCD(mth),fromBCD(year),fromBCD(dow),fromBCD(hour),fromBCD(min));

rtc_set_datetime(day,mth,year,dow,hour,min);

printf("\n\r clock setup");
}

void get_clock()
{
rtc_get_time(hour,min,sec);
printf("\n\r...%2d:%2d:%2d...\n",fromBCD(hour),fromBCD (min),fromBCD(sec));

}


void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
rtc_init();

printf("\n\r...start...\n");

set_clock();

do {

get_clock();
delay_ms(1000);
get_clock();

} while (TRUE);
} //end main


i have tired cange chip too but always 1:1 :1

i have connect so :
#define RTC_SCLK Pin_A2
#define RTC_IO Pin_A3
#define RTC_RST Pin_A4

but nothing works

there is sameone that can help me ?

Thanks..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 06, 2005 1:41 pm     Reply with quote

Have you tried to use the CCS example file, EX_RTCLK.C with
the ds1302 driver file DS1302.C ?

The example file is in this folder: c:\Program Files\Picc\Examples

I suggest that you get it working first with the CCS example file,
and then try your own code.
ferrarilib



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

PostPosted: Wed Jul 06, 2005 3:43 pm     Reply with quote

i dont can try with this example because i dont have keyboard in a pic..
Confused
ferrarilib



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

PostPosted: Wed Jul 06, 2005 4:01 pm     Reply with quote

ok i have tired with manual set day,mth,year,dow,hour,min but output is always 01:01:01
in the date and in the time ..
I think that is a comunicate problem !

my set is :
Pic ds1302

A2------> 7
A3------> 6
A4------> 5
2---> XL 32,768
3--->none
1---->+5v
8---->+3,3 Batt

Confused

but need in A4 a resistor to Vcc ?
ferrarilib



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

PostPosted: Wed Jul 06, 2005 4:18 pm     Reply with quote

Now works fine but with ressistor of 1,5K vcc---> A4

But why need this resistor for works ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 06, 2005 4:20 pm     Reply with quote

Quote:
A2------> 7
A3------> 6
A4------> 5
2---> XL 32,768
3--->none
1---->+5v
8---->+3,3 Batt


The crystal should connect to pins 2 and 3. The crystal has two
wires coming from it. One wire goes to pin 2 and the other wire
goes to pin 3.

Also, you need a pull-up resistor on pin A4 of the PIC.
Pin A4 is an open-drain output pin on most PICs.
You can use a 4.7K resistor. One side should connect to
pin A4, and the other side to +5v.
ferrarilib



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

PostPosted: Wed Jul 06, 2005 4:41 pm     Reply with quote

PCM programmer wrote:
Quote:
A2------> 7
A3------> 6
A4------> 5
2---> XL 32,768
3--->none
1---->+5v
8---->+3,3 Batt


The crystal should connect to pins 2 and 3. The crystal has two
wires coming from it. One wire goes to pin 2 and the other wire
goes to pin 3.

Also, you need a pull-up resistor on pin A4 of the PIC.
Pin A4 is an open-drain output pin on most PICs.
You can use a 4.7K resistor. One side should connect to
pin A4, and the other side to +5v.


PCM Thanks !!
my XL is epson cristal and have only 1 pin output . one is for v+ one ground one out ..
Thanks Razz
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