DriverInside
Joined: 10 Feb 2006 Posts: 6
|
Real-time clock |
Posted: Tue Feb 28, 2006 9:24 am |
|
|
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 |
|