Well that version of the project didn't work so well in the field...

I'm now working on a second version which uses a RTC. Basically I already have half the code written for one of my other projects so most of this will be a cut and paste. But something is really puzzling me and would welcome your advice.

I'm using a 16F690 (20 pin DIP) because it has both a basic UART and IC2 interface, and I happened to have a sample in my project box. I could be cleaver (yeah right) and use the full capabilities of the DS1307 and program the times for each month so it takes care of BST and GMT etc, but for now I thought the easiest way would be to use a serial utility to set the time and trigger value as required. Using PicMultiCalc to get the coms values I am able to connect and receive data, however the time is shown as 00:00 in the following code. Now like I mentioned , I've cut and pasted the section and same variables in a previous project so there should be no reason for it not to work. To prove the DS1307 is working on the breadboard (it hasn't been removed since I took a break from the previous project) I removed the 16F690 and replaced it with the 18F4580 and connected the jumper to the EasyPIC5 board - clock was displaying the time set by the code. Noted the correct clk and dta pins, powered down the EP5 board and mapped the connections to the pins used by the 16F690. Replaced the 16F690 and tested again - the serial monitor in Microcode Studio connected and displayed "Time : 00:00"

I've looked at the data sheet, but not sure if I am missing anything (probably some register needs setting but I'll be dammed if I can see it) so hopefully someone here might be able to assist.

Here's the code

Code:
'****************************************************************
'*  Name    : Chicken Coop Door Control                         *
'*  Author  : Malcolm Crabbe                                    *
'*  Date    : 30th January 2014                                 *
'*  Version : 1.0                                               *
'*  Notes   : Uses PBP 2.60c                                    *
'*          : 16F690, int osc 4MHz                              *
'*          : Program uses RTC  to turn                         *
'*          : on an electric motor and open a sliding door.     *
'*          : Door travel controlled by limit switches          *
'****************************************************************


ASM
 __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF  
endasm

ANSEL=%00000000
ADCON1=7
ADCON0 = %00000000                      'AD converter module disabled
ADCON1 = %00001111 

TRISA=%00000011                         'set PORTA as all output 
TRISC=%00000001                         'set PORTC as all output apart from RC0
TRISB=%00000011

DEFINE HSER_RCSTA 90h                   'Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h                   'Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25                    '9600 Baud @ 0.16%
DEFINE HSER_CLROERR 1                   'Clear overflow automatically

day             var byte 
RTCMin          var byte		        'RTC Minutes
RTCHour         var byte	            'RTC Hours
RTCsec          var byte                'RTC Seconds

TimeH           var byte                'variable to store Hours
TimeM           var byte                'variable to store Minutes
SS              VAR Byte                'variable to store Seconds

CounterA        var byte	            'General purpose Variable
CounterB        var byte	            'General purpose Variable

Counter1        var word                'used to store the current time as a digit.  Counts minutes from 0000 at midnight (to be added later)

Relay           var PortA.5             'used to activate relay and thus reverse direction
Motor           var PortA.4             'used to drive the motor
SW1             VAR PortA.0             'Door open limit switch
SW2             VAR PortA.1             'Door closed limit switch
Tx              var PortB.7             'used for sending time value in testing
Rx              Var PortB.5             'used for receiving time value in testing

SetMN           var byte		        'Used to set time Minutes
SetHR           var byte	            'Used to set time Hours
SetSS           var byte                'Used to set time Seconds 

RCIF            VAR PIR1.5              'USART receive flag
GIE             VAR INTCON.7
RCIF=1

SCLpin          var PORTB.6             'RTC pin - clk
SDApin          var PORTB.4             'RTC pin - data

setHR = 08                              'initial time to 8am 
setMN = 00

'convert initial time to BDC and write it to the DS1307
CounterA=SetMN
Gosub ConvertBCD
RTCMin=CounterB

CounterA=SetHR
Gosub ConvertBCD
RTCHour=CounterB

I2Cwrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour] 


test:

I2CREAD SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]  ; read DS1307 chip

timeH=(RTCHour>>4)                        'convert the BCD format of the hours register and store in variable timeH
timeH=(timeH &$03)*10
timeH=timeH+(RTCHour&$0F)

timeM=(RTCMin>>4)                         'convert the BCD format of the mins register and store in variable timeM
timeM=(timeM &$07)*10
timeM=timeM+(RTCMin&$0F)    

ss=(RTCSec>>4)                            'convert the BCD format of the sec register and store in variable ss
ss=(ss &$07)*10
ss=ss+(RTCSec&$0F)                     

Counter1 = (TimeH *60)+ TimeM             'take hours and multiply it by 60 then add odd minutes to get the total minutes into counter1

Hserout["Time: ",#TimeH DIG 1,#TimeH DIG 0,":",#TimeM DIG 1,#TimeM DIG 0,10]
pause 1000


goto test



'*******************************************************************************
' convert BDC format to decimal
 ConvertBCD:
	CounterB=CounterA DIG 1                        ' CounterA is the entry variable
	CounterB=CounterB<<4                           ' CounterB holds the converted BCD result on exit
	CounterB=CounterB+CounterA DIG 0
	Return
'*******************************************************************************