Alarm Time


Closed Thread
Results 1 to 2 of 2

Thread: Alarm Time

  1. #1
    Santana's Avatar
    Santana Guest

    Thumbs up Alarm Time

    Thanks to Bruce & Toni
    i have managed to get the DS1337 RTC to work perfectly
    i used a PIC18F452 & A DS1337 I Connected an Led to Pin 3 to Gnd .
    The led is on while the alarm time and the main RTC time don't match and of when the time match up.


    '************************************************* ***************
    '* Name : ALARM1.BAS *
    '* Author : [SANTANA] *
    '* Notice : Copyright (c) 2004 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 30/10/2004 *
    '* Version : 1.0 *
    '* Notes :THE PROGRAM USES A TRIGGERS AN ALARM WHEN THE *
    '* :ALARM TIME SET BY THE USER MATCHS THAT OF THE RTC *
    '* :ON PIN 3 OF A DS1337 *
    '* :THE HRS:MINS & SECS MUST MATCH EXACTLY ON BOTH *
    '* :THE MAIN RTC TIME AND THE ALARM TIME
    '************************************************* ***************
    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
    flag var byte

    ' 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.. !!"
    flag=0
    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]
    I2Cread DS_SDA, DS_SCL, RTC, StatusReg,[flag]
    LCDOut I,Clr
    LCDOut I,Line1,"Alarm: ",HEX2 A1hr, ":", HEX2 A1MINs, ":", HEX2 A1sec
    LCDOut I,Line2,"Time: ",HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec

    nap 5
    if flag.0=1 then gosub Take_Reading

    GoTo Loop
    End


    ' Read Ds1337
    ' Display Section
    ' ---------------
    Take_Reading:
    LCDOut I,Clr
    LCDOut I,Line1,"ALARM TRIGGERED"
    Pause 1000 ' Allow Time for user to view
    gosub SetTimeAndDate ' RESET TIMER
    I2CWrite DS_SDA, DS_SCL, RTC, StatusReg,[%00000000]' clear status reg<------
    PAUSE 10
    return



    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
    mins=$30
    sec=$40


    'SET ALARM FOR 16:31:05
    A1hr=$16
    A1MINs=$31
    A1sec=$05
    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


    __________________

  2. #2
    fortuner_qnoy's Avatar
    fortuner_qnoy Guest


    Did you find this post helpful? Yes | No

    Default how if use 7 segment

    may you explain how if use 7 segment for display all data?

Similar Threads

  1. INT2 anomaly in DT_INTS-18??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2010, 21:07
  2. DS1307 and a LED array, need ideas
    By peu in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 30th December 2009, 19:45
  3. Replies: 14
    Last Post: - 26th September 2007, 06:41
  4. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 20:55
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 15:24

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts