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 CCS Technical Support

Real-time clock

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
DriverInside



Joined: 10 Feb 2006
Posts: 6

View user's profile Send private message Send e-mail

Real-time clock
PostPosted: Tue Feb 28, 2006 9:24 am     Reply with quote

Hello i'll like to use the TIMER1 as a real time clock with my pic18F4455... I founded this code in the 18F datasheet.

I'll like to know how the use assembler code in a C program and how can a read/change the present time.

thank you

JP

//==============================================
// Real time clock
//==============================================

RTCinit
MOVLW 80h ; Preload TMR1 register pair
MOVWF TMR1H ; for 1 second overflow
CLRF TMR1L
MOVLW b’00001111’ ; Configure for external clock,
MOVWF T1OSC ; Asynchronous operation, external oscillator
CLRF secs ; Initialize timekeeping registers
CLRF mins ;
MOVLW d’12’
MOVWF hours
BSF PIE1, TMR1IE ; Enable Timer1 interrupt
RETURN
RTCisr
BSF TMR1H, 7 ; Preload for 1 sec overflow
BCF PIR1, TMR1IF ; Clear interrupt flag
INCF secs, F ; Increment seconds
MOVLW d’59’ ; 60 seconds elapsed?
CPFSGT secs
RETURN ; No, done

CLRF secs ; Clear seconds
INCF mins, ; Increment minutes
MOVLW d’59’ ; 60 minutes elapsed?
CPFSGT mins
RETURN ; No, done

CLRF mins ; clear minutes
INCF hours, F ; Increment hours
MOVLW d’23’ ; 24 hours elapsed?
CPFSGT hours
RETURN ; No, done

MOVLW d’01’ ; Reset hours to 1
MOVWF hours
RETURN ; Done
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 28, 2006 6:19 pm     Reply with quote

You can use assembler in your program using the #ASM and #ENDASM directives, check the manual for examples.

Much easier is to use the search function of this forum (see top of the page) and use one of the C implementations, for example http://www.ccsinfo.com/forum/viewtopic.php?p=59789#59789
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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