Hello Folks,
i really do need your help on this one as i have being strugling
for the the past few days .
Here is what i am trying to do.
i want to use the DS1337 to display Time and date which i have
managed to do as i upgraded from ds1307 .
The part i struglling with is the alarm part as i haven't used this
before .
i want to set the alarm intb which i connected a led to when the
after 5 minutes
How do i check to know the alarm time is up ?
i have tried everything (i know) with no joy so if anyone has
used this Ds1337 please give me a helping hand


Toni


DEFINE LOADER_USED 1 ' uses a bootloader
Include "Modedefs.Bas"
Define OSC 20
clear

' Setup Hardware for uart
DEFINE HSER_BAUD 115200
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLROERR 1


DEFINE LCD_DREG PORTD ' Use Portd for LCD Data
DEFINE LCD_DBIT 4 ' Use Upper(4) 4 bits of Port
' PORTD-4 thru PORTD-7 connects to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTE ' PORTE for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 0 ' PORTE-0 pin for LCD's RS line
DEFINE LCD_EREG PORTE ' PORTE for Enable (E) bit
DEFINE LCD_EBIT 1 ' PORTE-1 pin for LCD's E line

DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 2000 ' Command Delay (uS)
DEFINE LCD_DATAUS 50 ' Data Delay (uS)


@ device pic16F877, XT_osc, wdt_off, pwrt_on, protect_off
'** DEFINE LCD Control Constants **
I CON 254 ' Control Byte
Clr CON 1 ' Clear the display
Line1 CON 128 ' Point to beginning of line 1
Line2 CON 192 ' Point to beginning of line 2

' Clock Defines
' ----------------
DS_SCL VAR PORTC.3 ' I2C clock pin
DS_SDA VAR PORTC.4 ' I2C data pin
RTC CON %11010000 ' RTC device address (byte addressing)

'Setting the RTC so we can get out 1Hz tick output
'-------------------------------------------------
' -------------- RTC definitions -----------------
SecReg CON $00 ' seconds address (00 - 59) ' MSB of SecReg must be set to a 0 to enable RTC
MinReg CON $01 ' minutes address (00 - 59)
HourReg CON $02 ' hours address (01 - 12) or (00 - 23)
DayReg CON $03 ' day address (1 - 7)
DateReg CON $04 ' date address (01 - 28/29, 30, 31)
MonthReg CON $05 ' month address (01 - 12)
YearReg CON $06 ' year address (00 - 99)
Alm1sec CON $07 ' Alarm 1 seconds address (00 - 59)
Alm1min CON $08 ' Alarm 1 minutes address (00 - 59)
Alm1hr CON $09 ' Alarm 1 hours address (01 - 12) or (00 - 23)
Alm1Day CON $0A ' Alarm 1 day address (1 - 7)
Alm2min CON $0B ' Alarm 2 minutes address (00 - 59)
Alm2hr CON $0C ' Alarm 2 hours address (01 - 12) or (00 - 23)
Alm2Day CON $0D ' Alarm 2 day address (1 - 7)
ContReg CON $0E ' control register
StatusReg CON $0F ' STATUS register
RTCflag CON 0 ' RTC flag (location 0 of internal EEPROM)
RTCset VAR BIT ' bit to check if RTC has been set
cntrl CON %00000110 ' sets the SQW/OUT to 1Hz pulse, logic level low
'Sta CON %00000000
' The variable below holds the values entered:
' entered by the user




sec VAR BYTE ' seconds
MINs VAR BYTE ' minutes
hr VAR BYTE ' hours
day VAR BYTE ' day
date VAR BYTE ' date
mon VAR BYTE ' month
yr VAR BYTE ' year

'ALARM VARIABLES
'===============

A_MINs VAR BYTE ' minutes
A_hr VAR BYTE ' hours

'
' Initialise Hardware
' -------------------
ADCON1=%00000111
TRISA =%00100000
TRISB =%11100111
TRISC =%10000001
TRISD =%00000000


Pause 1000
LCDOut I,Clr:Pause 30
LCDOut I,Line1+2," RTC TEST "
LCDOut I,Line2+2,"..Power On.. !!"

GoSub SetTimeAndDate

' Main Program Loop
' -----------------
Loop:


I2CRead DS_SDA, DS_SCL, RTC, SecReg, [sec,MINs,hr,day,date,mon,yr]
I2CRead DS_SDA, DS_SCL, RTC, Alm2min,[A_mins,A_hr]

' Read Ds1337
' Display Section
' ---------------
LCDOut I,Clr
LCDOut I,Line1,"Time: ",HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec
'LCDOut I,Line2,"Date : ",HEX2 date,"-",HEX2 mon,"-",HEX2 yr
LCDOut I,Line2,"Alarm: ",HEX2 A_hr, ":", HEX2 A_MINs

Pause 500 ' Allow Time for user to view
GoTo Loop

End



SetTimeAndDate:
'=============
yr=0:date =0:mon =0:day=0:hr=0:mins=0:sec=0

' The constants below set the RTC to: 16:30:00 on 13-08-2004
yr=$04
mon=$08
date=$13
hr=$16
sec=$00
mins=$30
'SET ALARM FOR 16:35:00
A_hr=$16
A_mins=$35

I2CWrite DS_SDA, DS_SCL, RTC, SecReg,[sec,mins,hr,day,date,mon,yr,cntrl]

Pause 10
I2CWrite DS_SDA, DS_SCL, RTC, Alm2min,[A_mins,A_hr,cntrl]

Pause 10
Return