|
|
View previous topic :: View next topic |
Author |
Message |
EmbdFreak
Joined: 28 Jul 2005 Posts: 23
|
NJU6355 |
Posted: Sat Jan 28, 2006 4:07 am |
|
|
Hi,
The example program for the NJU6355 prints ??:??:?? after setting the date and time. Ive altered the driver to suit my own pins and ve connected the 32khz xtal to drive it. Theres nothing much to see in the program, yet im pasting it here:
*************************
Code: |
/* driver altered to make
#define RTC_DATA PIN_A2
#define RTC_CLK PIN_A3
#define RTC_CE PIN_A4
#define RTC_IO PIN_A5
*/
#include <16F877a.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_C4, rcv=PIN_C5) // Jumpers: 8 to 11, 7 to 12
#include <nju6355.c>
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')) && (second!='\r'));
putc(second);
if(second=='\r')
return(first);
else
return((first<<4)|(second-'0'));
}
void set_clock(){
BYTE day, mth, year, dow, hour, min;
printf("\r\nPress ENTER after 1 digit answers.");
printf("\r\nYear 19: ");
year=get_bcd();
printf("\r\nMonth: ");
mth=get_bcd();
printf("\r\nDay: ");
day=get_bcd();
printf("\r\nWeekday 1-7: ");
dow=get_bcd();
printf("\r\nHour: ");
hour=get_bcd();
printf("\r\nMin: ");
min=get_bcd();
rtc_set_datetime(day,mth,year,dow,hour,min);
printf("\r\n\n");
}
void display_bcd( BYTE n ) {
putc( (n/16)+'0' );
putc( (n%16)+'0' );
}
void display_3_bcd( char separator, BYTE a, BYTE b, BYTE c ) {
display_bcd(a);
putc(separator);
display_bcd(b);
putc(separator);
display_bcd(c);
}
void main() {
char cmd;
BYTE day, mth, year, dow, hour, min, sec;
rtc_init();
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");
while (TRUE) {
rtc_get_date( day, mth, year, dow);
display_3_bcd( '/', day, mth, year );
printf(" ");
rtc_get_time( hour, min, sec );
display_3_bcd( ':', hour, min, sec );
printf("\r");
delay_ms(250);
}
}
|
Plz suggest a possible solution. |
|
|
VanHauser
Joined: 03 Oct 2005 Posts: 88 Location: Ploiesti, Romania
|
|
Posted: Sat Jan 28, 2006 5:28 am |
|
|
I have tested the program you posted with CCS 3.242 and it didn't even compile. You renamed get_number() function from EX_RTC.C example to get_bcd(), which is already defined in NJU6355.C. Rename your function back and update your code with the change. Maybe your compiler is too old and doesn't issue an error. |
|
|
EmbdFreak
Joined: 28 Jul 2005 Posts: 23
|
|
Posted: Sat Jan 28, 2006 6:15 am |
|
|
thanx for the reply. My compiler version is 3.203 which is surely a little older. Ive run the same example as is, without renaming that function as such. The newer version might have it renamed.
Plz suggest solution if possible |
|
|
VanHauser
Joined: 03 Oct 2005 Posts: 88 Location: Ploiesti, Romania
|
|
Posted: Sat Jan 28, 2006 7:04 pm |
|
|
I've already told you a possible solution. You have two functions with the same name. There's only one thing to do. |
|
|
EmbdFreak
Joined: 28 Jul 2005 Posts: 23
|
|
Posted: Tue Jan 31, 2006 12:18 am |
|
|
Actually the problem is slightly different. i tested the setup on breadboard and it gave the correct date,time(used A0-A3). I changed the ports in the driver to A2-A5 and designed a PCB assuming it would work again, but it prints ??:??:?? or 00:00:00. this is besides the fact that im not using the analog port anywhere else. This is why i didnt consider ur input for function renaming ! |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Tue Jan 31, 2006 12:20 am |
|
|
I'm pretty sure that pin A4 is open drain - it can't drive signals high without an external pullup.
Check the 877's data sheet to be certain, but I'm pretty sure about A4 being open drain. I know it is on the 18F252 and 452, and the 452 is pin compatible (pretty much) with the 877. |
|
|
EmbdFreak
Joined: 28 Jul 2005 Posts: 23
|
|
Posted: Tue Jan 31, 2006 12:42 am |
|
|
Thats correct, it infact is an open drain and thanx a lot for the input. Ill alter the code or pcb and will try again ! |
|
|
EmbdFreak
Joined: 28 Jul 2005 Posts: 23
|
|
Posted: Tue Jan 31, 2006 12:57 am |
|
|
Thanks again, its working now. I have simply changed the port ! |
|
|
|
|
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
|