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

real time clock

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

real time clock
PostPosted: Sun Dec 15, 2013 10:13 am     Reply with quote

I revised command delay time.
I used 500kHz internal oscillator for clock source.
Also this code shows how to use watch dog timer.
Code:

#include <16f1937.h>
#use delay(clock = 500000)
#fuses NOLVP,WDT

#byte PORTB =0x0d
#byte PORTC = 0x0e //PORTC
#byte TRISB = 0x8d
#byte TRISC = 0x8e
#byte LAtC = 0x10E
#byte OPTION_REG = 0x95
#byte OSCCON = 0x99
#byte INTCON = 0x0b
#byte TMR0 =0x15

#define IS_LEAP(year) (year%4 == 0)

int ticker=0;
int msec_100=0;
int minutes=0;
int hours=0;
int seconds=0;
int days=1;
int month=1;
int year=1;

#INT_TIMER0
void isr_timer0()
{
   #asm
   nop;
   #endasm
   set_rtcc(0xff-250+11);//4msec
   ticker++;
   if(ticker==25)     //100msec
   {
      msec_100++;
      ticker=0;
   }
   if(msec_100==10) //1 sec
   {
      seconds++;
      msec_100=0;
   }
   if(seconds==60) seconds=0;
 }
void main()
{
   OPTION_REG=0x00;
   //OSCCON=0x3a;
   setup_counters(rtcc_internal,rtcc_div_2);
   set_rtcc(0xff-250+11);
   INTCON=0xa0;
   TRISB=0;
   setup_wdt(WDT_2S);
   while(1)
   {
      restart_wdt();
      if(seconds%2) PORTB=1;
      else PORTB=0;
   }
}
   


Last edited by pkipyy on Sat Dec 21, 2013 7:04 pm; edited 3 times in total
Gabriel



Joined: 03 Aug 2009
Posts: 913
Location: Panama

View user's profile Send private message

PostPosted: Sun Dec 15, 2013 8:15 pm     Reply with quote

I would give user ckielstra some credit since your work is a variation or improvement on his.

Other than that, thanks for sharing.

G.
_________________
CCS PCM 4.135 - PIC: 16F886, 88', 876' 877A
CCS PCH 5.012 - PIC: 18F97j60
pkipyy



Joined: 21 Nov 2013
Posts: 25

View user's profile Send private message

I did coding myself!!
PostPosted: Wed Dec 18, 2013 2:43 am     Reply with quote

I copied only part of year,month,day.
It is similar whoever did.
I revised my own code.
Now I deleted part of day,year,month.
What is variation?
Worth of this code is Only knowing man can see.
How correct time!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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