This code now whats thanks to you bruce
when the main time match the alarm time an interupt is generated on INTA (PIN 3)
my led goes low then back high .
all the time does not match the led is high
Very Best Regards
DEFINE LOADER_USED 1 ' uses a bootloader
Include "Modedefs.Bas"
Define OSC 20
clear
@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
' Setup Hardware for uart
DEFINE HSER_BAUD 115200
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLROERR 1
' LCD DEFINES
'============
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)
'** 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)
' -------------- RTC Address 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)
'Alarm 1 Address definitions
'===========================
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)
'Alarm 2 Address definitions
'===========================
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
cntrl CON %00000011 ' sets the SQW/OUT to 1Hz pulse, logic level low
'set interupt on INTB (From pg 9 of data sheet)
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
'ALARM1 VARIABLES
'===============
A1sec VAR BYTE ' seconds
A1MINs VAR BYTE ' minutes
A1hr VAR BYTE ' hours
A1day VAR BYTE ' day
' Initialise Hardware
' -------------------
ADCON1=7
TRISA =%00100000
TRISB =%11100111
TRISC =%10000001
TRISD =%00000000
Pause 1000
LCDOut I,Clr:Pause 30
LCDOut I,Line1+2," DS1337 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, Alm1sec,[A1sec,A1MINs,A1hr,A1day]
pause 10
' Read Ds1337
' Display Section
' ---------------
LCDOut I,Clr
LCDOut I,Line1,"Time: ",HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec
LCDOut I,Line2,"Alarm: ",HEX2 A1hr, ":", HEX2 A1MINs, ":", HEX2 A1sec
Pause 500 ' Allow Time for user to view
I2CWrite DS_SDA, DS_SCL, RTC, StatusReg,[%00000000]' clear status reg<------
PAUSE 10
GoTo Loop
End
SetTimeAndDate:
'=============
yr=0:date =0:mon =0:day=0:hr=0:mins=0:sec=0
A1sec=0:A1MINs=0:A1hr=0: A1day=0
' The constants below set the RTC to: 16:30:40 on 13-08-2004
'################################################# ############
yr=$04
mon=$08
date=$13
day=$01
hr=$16
sec=$40
mins=$30
'SET ALARM FOR 16:31:50
A1hr=$16
A1MINs=$31
A1sec=$50
A1day=$13
'Set the main Time
I2CWrite DS_SDA, DS_SCL, RTC, SecReg,[sec,mins,hr,day,date,mon,yr]
Pause 10
'Set the Alarm 1 Time
I2CWrite DS_SDA, DS_SCL, RTC, ContReg,[$20]
Pause 10
I2CWrite DS_SDA, DS_SCL, RTC, StatusReg,[%00000000]
PAUSE 10
I2CWrite DS_SDA, DS_SCL, RTC,Alm1sec,[A1sec,A1MINs,A1hr,A1day]
Pause 10
I2CWrite DS_SDA, DS_SCL, RTC, ContReg,[5]
Pause 10
Return
Bookmarks