Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ds1307 pic16f88 improper counting

Status
Not open for further replies.

starterfor10

Newbie level 4
Joined
Apr 7, 2011
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,317
Hello,

I am fairly new to programming and attempting to make a clock using an rtc ds1307 with the pic16f88 for school. ( coding in c using hitech compiler)

I have got the i2c protocol working and can read from the ds1307 but the seconds register not only counts in irregular increments but also goes above 60.

the irregular increments are as follows:
1 - 9 fine
16 - 25 fine
32-41 fine
48 - 57 fine
64 - 72 fine
80-89 fine


Any suggestions would be greatly appreciated - thanks
 

the time and date are in BCD format - check that you are decoding them correctly
e.g. I use this for an MCP79410 RTC
Code:
// convert a BCD value to decimal, e.g. 0x41 to 41
unsigned char BCDtoDec(unsigned char hex)
{
         return (hex >> 4) *10 + (hex & 0x0f);
}
 

Thanks very much horace for the prompt reply - got it working!
 

Hello,

Ive been writing the rtc values to an lcd display using sprintf functions but my PIC is slowly getting filled up and still need additional functionaility.

Ive found the function IOTA which i believe can do the same as sprintf but cant find any code to implement - any suggestions / pointers would be greatly appreciated!
 

sprint() is as large and complex as printf() - you need a simple function that will take an int and return a string or similar
e.g. this is from an PIC16 program for a Microchip PICDEM Mechatrponics board
Code:
// prints a decimal integer value to screen - assume 16 bit ints
void printUint(unsigned int x, int field, int (*p_char)(int))
{
   unsigned int divisor=10000;
   int lead=1;                // removes leadins 0's
   if(x == 0)   
      { (*p_char)('0'); return; }        // if x=0 print 0
   // loop printing digits
   while (divisor > 0)
      {
       int ch=x/divisor;                // get digit
       if(!(lead && ch==0))         // print it if not leading 0
          { 
           lead=0; 
           (*p_char)(ch+'0'); 
          }
       else 
           if(field) (*p_char)(' ');
       x=x%divisor;             // get remainder of number
       divisor=divisor/10;        // set next divisor value
      }
}
the third parameter is the address of the function to print, e.g. in this case putchar()
Code:
printUint(adc=ADCread(), 0, putchar);
 

you use the hex value then check if not com output properly then put decimal value because i think so this is the reason for this type of your output.
 

Hi guys,

Thanks very much for the responses - my project is almost complete...

one thing I wanted to know what about printing to LCD display:

at the moment I am currently using:

sprintf (botmessage," %d:%d:%d", hour, min, sec) // and itoa for something else

but when a number for minutes for example is below 10 the display looks like

7:1 instead of 7:01

I have done away of separating the tens and units out as shown
(botmessage," %d%d:%d%d:%d%d", hour1, hour2, min1, min2, sec1, sec2)

to achieve 7:01 =====> but was wondering if there was a simpler way of achieving this??

Thanks for your help
 

try
Code:
sprintf (botmessage," %02d:%02d:%02d", hour, min, sec)
the conversion specification %02d prints in a field width of 2 with the 0 printing leading zeros
 

Horace you've been a great help!:p (sorry to ask such basic questions)

Thanks again
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top