| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| pkipyy 
 
 
 Joined: 21 Nov 2013
 Posts: 25
 
 
 
			    
 
 | 
			
				| real time clock |  
				|  Posted: Sun Dec 15, 2013 10:13 am |   |  
				| 
 |  
				| 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: 1074
 Location: Panama
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sun Dec 15, 2013 8:15 pm |   |  
				| 
 |  
				| 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 5.078 & CCS PCH 5.093
 |  | 
	
		|  | 
	
		| pkipyy 
 
 
 Joined: 21 Nov 2013
 Posts: 25
 
 
 
			    
 
 | 
			
				| I did coding myself!! |  
				|  Posted: Wed Dec 18, 2013 2:43 am |   |  
				| 
 |  
				| 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!
 |  | 
	
		|  | 
	
		|  |