Do i have to read the status register using 12C command
or just read the value of the register ?
i tried to see if bit 1 is set .
i did it as below but its i just get the value of the register as
%00001111 and it dosen't change when the time gets to the
alarm time.
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)
'Alarm 1
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)
'Alarm2
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
'set interupt on INTB
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
STAD VAR BYTE
'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]
pause 10
' Read Ds1337
' Display Section
' ---------------
LCDOut I,Clr
LCDOut I,Line1,"Time: ",HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec
LCDOut I,Line2,"STATUS ",BIN8 StatusReg
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:40 on 13-08-2004
yr=$04
mon=$08
date=$13
hr=$16
sec=$40
mins=$30
'SET ALARM FOR 16:31:00
A_hr=$16
A_mins=$31
'Set the Time
I2CWrite DS_SDA, DS_SCL, RTC, SecReg,[sec,mins,hr,day,date,mon,yr,cntrl]
Pause 10
'Set the Alarm 1 Time
I2CWrite DS_SDA, DS_SCL, RTC, Alm2min,[A_mins,A_hr,cntrl]
Pause 10
I2CWrite DS_SDA, DS_SCL, RTC, StatusReg,[$00,cntrl]
PAUSE 10
Return
Toni
Bookmarks