I have an EasyPIC5 development board and one of the Microelectonica RTC2 add on modules which has been breadboarded and needed to be tested as part of an ongoing project. The following example simply shows todays date (14/2/10) and starts running from 19:00 hrs.
Although this example was simply used to test the comms between PIC and Module, it should be a simple matter to add a few tweaks to allow the date and time to be set.
Code:'**************************************************************** '* Name : RTCtest877A.BAS * '* Author : Malcolm Crabbe * '* Notice : Copyright (c) 2010 M.Crabbe * '* : All Rights Reserved * '* Date : 14/02/2010 * '* Version : 1.0 * '* Notes : Test of breadboarded RTC2 Module to prove * '* : hardware * '* Target : 16F877A '**************************************************************** @ __config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF DEFINE OSC 20 CLEAR ;----[LCD definitions]------------------------------------------------------ DEFINE LCD_DREG PORTB ' LCD Data port DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4) DEFINE LCD_EREG PORTB ' LCD Enable port DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD) DEFINE LCD_RSREG PORTB ' LCD Register Select port DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD) DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits) DEFINE LCD_LINES 2 ' number of lines on LCD DEFINE LCD_COMMANDUS 2000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us SDA var PORTC.1 ' RTC data SCL var PORTC.0 ' RTC clock TRISC= %11111111 DB0 var byte[8] CMCON = %00000111 ' Comparators = off gosub write_1307 read_1307: ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control I2CREAD SDA,SCL,$D1,$00,[STR DB0\8] ' Read 8 bytes from DS1307 lcdout $fe,1,"Time=",hex2 DB0[2],":",hex2 DB0[1],":",hex2 DB0[0] 'bit 0=sec, bit 1=min, bit 2=hrs lcdout $fe,$c0,"Date=",hex2 DB0[4],":",hex2 DB0[5],":",hex2 db0[6] 'bit 4=day, bit 5=month, bit 6=year goto read_1307 end Write_1307: ' Set time & date to 19:00:00 14th Feb 201 I2CWRITE SDA,SCL,$D0,$00,[$00,$00,$19,$7,$14,$2,$10,$90] ' Write to DS1307 pause 10 RETURN




Bookmarks