PR 12 REAL TIME CLOCK ..

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

PR 12 REAL TIME CLOCK ..

Postby ONG WEI GIAP » Mon Nov 21, 2011 8:59 pm

i have compile the PIC16F876A, the source code i used is from the website itself.. everythings is well function, but it is in 24hrs mode.. it only display time and date. how can i change it to 12hrs with AM/PM indicator and display date and day?
ONG WEI GIAP
Freshie
 
Posts: 5
Joined: Wed Nov 02, 2011 3:46 pm

Re: PR 12 REAL TIME CLOCK ..

Postby robosang » Mon Nov 21, 2011 11:21 pm

You are learning or we are learning ? You are simply copying the code and use it without studying it.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: PR 12 REAL TIME CLOCK ..

Postby ABSF » Tue Nov 22, 2011 12:23 pm

robosang WROTE:You are learning or we are learning ? You are simply copying the code and use it without studying it.


I totally agreed with robosang. By giving you the answer, you would have learned nothing.

ONG WEI GIAP WROTE:i have compile the PIC16F876A, the source code i used is from the website itself.. everythings is well function, but it is in 24hrs mode.. it only display time and date. how can i change it to 12hrs with AM/PM indicator and display date and day?


I am a beginner in C just like you. But after I gone thru the C program of PR#12, I found something that could be modified to suite your need.

CODE: SELECT_ALL_CODE
// SET HOUR ===========================================================
   
   while(sw0==1)                  //infinity loop if switch0 is not pressed
   {
      if(sw1==1)                  //if switch 1 is not pressed
      {
            lcd_goto(0);         //maintain current hour value on LCD and make it blinking
            send_dec(clkhrs,2);   
            delay(10000);
            lcd_goto(1);
            send_char(' ');
            lcd_goto(0);
            send_char(' ');
            delay(10000);
      }   
      if(sw1==0)                        //if switch 1 is pressed
      {   
         while(sw1==0)continue;            //wait switch1 to depress

         if(clkhrs<=22)clkhrs++;
         else clkhrs=0;
      }
   }

   lcd_goto(0);                        //overwrite changed hour value on LCD
   send_dec(clkhrs,2);   
   while(sw0==0)continue;                  //wait switch 0 to be depressed


If I want to display in 12 hour mode then I would change "if(clkhrs<=11)clkhrs++;" and it should do the trick. But the day and date has to be adjusted accordingly.

But to be able to display AM and PM, I would define one more variable "AM_PM" as string characters. Expand the subroutine above to check clkhrs. If clkhrs is between 0-11 then AM_PM="AM", if clkhrs is 12-23 then AM_PM="PM". Of course, the LCD display part has to be adjusted also.

Can some experts here check whether I am correct?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PR 12 REAL TIME CLOCK ..

Postby ABSF » Tue Nov 22, 2011 12:36 pm

Just found out that you can also change the 12/24 hours mode in rtc.c here

CODE: SELECT_ALL_CODE
void i2c_rtc_set_hours(unsigned char uc_value)
{
   // The current value of the DS1307 RTC register.
   unsigned char uc_current_register_value;
   
   
   
   // Make sure the value is < 24 hours.
   if (uc_value < 24) {
      
      // Change the value into BCD.
      uc_value = ((uc_value / 10) << 4) + (uc_value % 10);
      
      // Read back the current value of register "Hours".
      uc_current_register_value = uc_i2c_read(RTC_ADDRESS, 0x02);
      
      [b]// We only interested in the 12-hour/24-hour mode bit, mask out the others.
      uc_current_register_value &= 0x40;
      [/b]
      // Write to the I2C RTC.
      uc_i2c_write(RTC_ADDRESS, 0x02, uc_current_register_value | uc_value);
   }   
}   


Please read the datasheet of the clock chip to see how to use it.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PR 12 REAL TIME CLOCK ..

Postby ONG WEI GIAP » Tue Nov 22, 2011 4:09 pm

<<ABSF>> .. your guilding is really higly appreciated. thank lots. i was find out that i dint define the method after my edition of source code.
<<robosong>> i find out that every comments on forum u did is kind acting p.r.o but without giving any guilding. is that the way how u use forum? single things can show how a person and attitude u having. please make sure every situation before u give any comments.
ONG WEI GIAP
Freshie
 
Posts: 5
Joined: Wed Nov 02, 2011 3:46 pm

Re: PR 12 REAL TIME CLOCK ..

Postby IsaacChuah90 » Wed Nov 30, 2011 5:17 am

hey WEI GIAP, I have something to ask you. The schematic of PR12 is showing that there is a 10k resistor connected at RB3 from LCD to PIC, is that necessary? I'm using PIC16F877A instead of using PIC16F876A,
IsaacChuah90
Apprentice
 
Posts: 52
Joined: Mon Jun 06, 2011 7:35 pm

Re: PR 12 REAL TIME CLOCK ..

Postby TeoYX » Wed Feb 29, 2012 7:31 am

Hi everyone,


I have some problem when displaying the real time clock. My LCD did show 00:00:00 and day/month/year. However, everytime i want to change the value, it always start from 00 for hour, minute, second, day, month, and year. Moreover, with connecting to back up battery, once i power ON and OFF the PIC, the changed value disappear and back to all 00.

All my components are well soldered on the PCB board already.

Does anyone meet this problem before? Any suggestion on the cause and solution?

P.S.: i am using the same program code.
TeoYX
Apprentice
 
Posts: 47
Joined: Fri Aug 12, 2011 10:47 pm

Re: PR 12 REAL TIME CLOCK ..

Postby TeoYX » Fri Mar 02, 2012 10:34 pm

Does the source code of PR12 from Cytron website work properly with PIC16f877A? Anyone success with the code?

Please help because i really cannot solve the problem.

Here is the screenshot of the schematic diagram:

Real Time IC Connection.jpg


Thanks a lot if someone can give some suggestions!!!
TeoYX
Apprentice
 
Posts: 47
Joined: Fri Aug 12, 2011 10:47 pm

Re: PR 12 REAL TIME CLOCK ..

Postby sich » Mon Mar 05, 2012 11:37 am

Successfully compiled the code? What about your full schematic?
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: PR 12 REAL TIME CLOCK ..

Postby TeoYX » Tue Mar 13, 2012 12:44 am

Yes i compile the code without error. I found the root cause already. That is because i used R_W instead of RW in i2c.c. Thanks guys for your reply.
TeoYX
Apprentice
 
Posts: 47
Joined: Fri Aug 12, 2011 10:47 pm

Next

Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 15 guests