This is a multi-part message in MIME format. ------=_NextPart_000_0006_01C145E0.1D5E6180 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Hi Danie, I attach some code I have written for the Dallas DS1302 chip, a small and cheap RTC. Enjoy! -------------------------------------------- Hans Nielsen NIELSEN Elektronik nielsen.elek@wanadoo.fr ------------------------------------------- > -----Ursprungligt meddelande----- > Fren: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]Fvr Danie Prinsloo > Skickat: den 25 september 2001 11:51 > Till: PICLIST@MITVMA.MIT.EDU > Dmne: [PIC]How to make use of realtime clock > > > HI > Is there anyone who has any suggestions on how to use > a realtime clock. I need to use it for datalogging. > I am a student and need to do a project on > datalogging. > What I am planning to do is to use a keypad to enter > an individual's code to get access to a workshop. > When he gains access through a gate the clock has to > start as to record the hours he is inside. When he > goes out with his own code from the other side of the > gate, the clock must stop. This data must be > available for someone to access from another keypad > and LCD. > I have to use the 16F84A. > Can someone help me with the 'time' problem. > Regards Danie > > __________________________________________________ > Do You Yahoo!? > Get email alerts & NEW webcam video instant messaging with Yahoo! > Messenger. http://im.yahoo.com > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > ------=_NextPart_000_0006_01C145E0.1D5E6180 Content-Type: application/octet-stream; name="rtc1302.asm" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="rtc1302.asm" ;************************************************************************** ; RTC1302.ASM ; Real time clock routines ; v 1.0 010502 ; Uses a Dallas DS1302 RTC ; NIELSEN Elektronik ; nielsen.elek@wanadoo.fr ;************************************************************************** ; Variables used in the unit cblock RTCvar Temp0 sdata scount endc ; Port pin definitions #define csRTC PORTB,0 ; Out, RTC chip select #define ioRTC PORTB,5 ; In/Out, RTC data I/O #define ckRTC PORTB,4 ; Out, RTC data clock ; Sets i/o pin to input for data read from RTC RTCin macro banksel TRISB ; select bank 1 bsf TRISB,5 ; set RB5 (ioRTC) to input banksel PORTB ; select bank 0 endm ; Sets i/o pin to output for data write to RTC RTCout macro banksel TRISB ; select bank 1 bcf TRISB,5 ; set RB5 (ioRTC) to output banksel PORTB ; select bank 0 endm ;-------------------------------------------------------------------------- ; The time registers in DS1302 RTC ; The time is: ; Reg Pos Data ; 1 1 second ; 2 2 minute ; 3 3 hour ; 4 4 date ; 5 5 month ; 6 6 day ; 7 7 year ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ; RTC clock burst mode write, data fetched from RAM ; Provided data: ; sdata Start RAM location of data to put into RTC ; scount Number of bytes to write (up to 8) ;-------------------------------------------------------------------------- WriteToRTC bsf csRTC ; Set RST for RTC movlw b'10111110' ; load RTC burst write command call RTCwrite ; RTC shift routine ; send data: movf sdata,w ; pointer to first RAM data loc. movwf FSR ; put in File Select Register movf scount,w ; data bytes count movwf Temp0 ; local counter SendRTCByte movf INDF,w ; load data using Indirect Addressing call RTCwrite ; RTC shift routine incf FSR,f ; step to next data pos decfsz Temp0,f ; decrement data counter goto SendRTCByte ; if not zero, send next byte bcf csRTC ; Clear RST for RTC return ;-------------------------------------------------------------------------- ; RTC clock burst mode read, data put in RAM ; Provided data: ; sdata Start RAM location to place received data ; scount Number of bytes to read (up to 8) ;-------------------------------------------------------------------------- ReadFromRTC bsf csRTC ; Set RST for RTC movlw b'10111111' ; load RTC burst read command call RTCwrite ; RTC shift routine ; read RTC data to RAM RTCin ; Set i/o pin RB5 to input for data read from RTC bcf INTCON,RBIE ; clear PORTB int mask movfw sdata ; pointer to first RAM data loc. movwf FSR ; put in File Select Register movfw scount ; data byte count movwf Temp0 ; local counter ReadRTCByte call RTCread ; RTC shift routine movwf INDF ; save data using Indirect Addressing incf FSR,f ; step to next data pos decfsz Temp0,f ; decrement data counter goto ReadRTCByte ; if not zero, read next byte bcf csRTC ; Clear RST for RTC RTCout ; Set i/o pin RB5 to output for data write to SPI and RTC return ;-------------------------------------------------------------------------- ; RTC data read, shifts 8 bits into inbyte and w ; Data is valid after a falling clock edge. ;-------------------------------------------------------------------------- RTCread clrwdt ; clear watchdog timer movlw 8 ; load loop counter movwf count ; stash it RTCrdloop bcf sck ; clock low, data is now valid clrc ; preclear carry btfsc ioRTC ; if i/o line low then skip setc ; else set carry rrf inbyte,f ; rotate C in place, LSB bit first bsf sck ; clock high, i/o 3-stated decfsz count,f ; do loop counter goto RTCrdloop ; loop until 8 movf inbyte,w ; put read result in w return ; all done ;-------------------------------------------------------------------------- ; RTC data write, shifts w into RTC ;-------------------------------------------------------------------------- RTCwrite clrwdt ; clear watchdog timer movwf outbyte ; put data in shift out variable movlw 8 ; load loop counter movwf count ; stash it RTCwtloop rrf outbyte,f ; get bit to send, LSB first bcf sck ; clock low bcf ioRTC ; preclear i/o line skpnc ; if carry low then skip bsf ioRTC ; else set i/o line bsf sck ; clock high, data is now clocked in decfsz count,f ; do loop counter goto RTCwtloop ; loop until 8 bsf sck ; clock high, i/o 3-stated return ; all done ;-------------------------------------------------------------------------- ; End of include file ;-------------------------------------------------------------------------- ------=_NextPart_000_0006_01C145E0.1D5E6180-- -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics