Hi Henrik

That is exactly what I have got .... Really don't know what I am missing ??

Help very welcome .... I don't do software so go easy on me !

Andy



Here is whole code :-

DEFINE OSC 8
DEFINE HSER_TXSTA 24H
DEFINE HSER_RCSTA 90H
DEFINE HSER_BAUD 9615
DEFINE HSER_CLROERR 1

'76543210
TRISA=%00000010 'Make RA1 input
TRISB=%00000001 'Make RB0 input
PORTA=%00000000 'Port A all low
PORTB=%00000000 'Port B all low

CMCON=7

' Alias pins

i var byte 'Dummy
SDA Var PORTB.3 'SDA Line
SCL Var PORTB.4 'SCL Line
Led var PORTB.6 'White Light
BT var PORTA.0 'BlueTooth Enable
ir var PORTB.0 'Remote Input
time var word 'Real time on
realtrig var word 'Real IR Trigger
char var byte 'Serial in Char
state var PORTA.1 'State Pin High

' Allocate variables
RTCYear Var Byte
RTCMonth Var Byte
RTCDate Var Byte
RTCDay Var Byte
RTCHour Var Byte
RTCMin Var Byte
RTCSec Var Byte
RTCCtrl Var Byte

'Set initial time
RTCYear = $20
RTCMonth = $09
RTCDate = $26
RTCDay = $07
RTCHour = $16
RTCMin = $57
RTCSec = 1
RTCCtrl = 0
'Gosub settime ' Set the time
Goto start ' Skip over subroutines

' Subroutine to write time to RTC

'settime: I2CWrite SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
' Return

'Subroutine to read time from RTC

gettime: I2CRead SDA, SCL, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
Return

'Main program loop

start: high BT 'Turn BlueTooth on

mainloop: Gosub gettime ' Read the time from the RTC

pause 100 ' Stabilise

IF (RTCHour=$19) and (RTCMin=$00) Then
gosub Led_On ' Led on for a bit
endif

pause 100 ' Stabilise

IF (RTCMin=$00 and RTCsec=$01) or (RTCMin=$15 and RTCsec=$01) or (RTCMin=$30 and RTCsec=$01) or (RTCMin=$45 and RTCsec=$01)Then
gosub RST_BT
endif

pause 100 ' Stabilise

if (ir=0) then 'if button press
High PORTB.5
High PORTB.7
Pause 10000
Low PORTB.5
Low PORTB.7
'gosub Seconds 'then on 88 Seconds
endif

pause 100 ' Stabilise

if (state=1) then 'if state high
gosub connected 'then gosub connected
endif

Pause 100 ' Stabilise
Goto mainloop ' Do it forever and ever and ever

'Light control routines

Led_On: for time = 1 to 120 'On for 2 Hours
high led
pause 65000
next time
low led
return

Seconds: pause 500 'Pause for 1/2 seconds
high led
pause 60000 '60 Seconds
High led
pause 28000 ' 28 Seconds (So 60 plus 28 = 88Seconds
low led
Pause 500 'delay 1/2 seconds
return


connected:
hserin 5000, timeout,[char]
if char = "A" then
gosub Led_On ' Led on for a bit
endif
goto connected

RST_BT: low bt 'Turn BlueTooth off
pause 1000 'For 1 second
high bt 'Reset
return

Timeout: hserout ["Back to loop..."]
goto mainloop

End