Help With DS1337 Squarewave Output


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Location
    brighton
    Posts
    149

    Default Help With DS1337 Squarewave Output

    Hello All

    Just need a bit of help here .
    I am trying to use the DS1337 as an alarm with INTA (pin 3 of Ds1337) connected to RB0 Interupt pin of my Pic
    so that anytime the alarm time is reached it pulls RB0. This part is working ok.
    i want to use the other INTB (pin 7 ) to generate a 1 Hz tick .
    so using the datasheet on pages 10 & 11 i set my control register to 00000001
    as pg 10
    http://www.maxim-ic.com/datasheet/index.mvp/id/3128
    but i still don't get the 1hz tick on pin 7 here is my code below i must be doing something really stupid
    Code:
    '************************************************* ***************
    '* 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 9600
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_CLROERR 1
    ' Clock Defines 
    ' ---------------- 
    DS_SCL VAR PORTC.0 ' I2C clock pin 
    DS_SDA VAR PORTC.1 ' 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 %00000001 ' sets the SQW/OUT to 1Hz pulse, logic level low 
    'set interupt on INTA (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 
     VCC_EN      VAR PORTB.6
     LCD_EN      VAR PORTB.3
     HIGH VCC_EN   
    Pause 1000 
    hserout [" DS1337 TEST " ,10,13]
    flag=0
    GoSub SetTimeAndDate 
    ' Main Program Loop 
    ' ----------------- 
    Loopx: 
      
       
    
    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]
    hserout["Alarm Time : ",HEX2 A1hr, ":", HEX2 A1MINs, ":", HEX2 A1sec ,"      "]
    hserout["Present Time: ",HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec ,10,13]
    
    if flag.0=1 then gosub Take_Reading
     pause 1000
    GoTo Loopx
    End 
    
    ' Read Ds1337 
    ' Display Section 
    ' --------------- 
    Take_Reading:
    hserout ["ALARM TRIGGERED",10,13 ]
    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:50 on 13-08-2004 
    '#################################################
    yr=$04 
    mon=$08 
    date=$13 
    day=$01
    hr=$16
    mins=$30 
    sec=$50 
    
    '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
    Regards
    Isaac

  2. #2
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default Re: Help With DS1337 Squarewave Output

    Found the problem
    told you i was stupid

    I2CWrite DS_SDA, DS_SCL, RTC, ContReg,[$20]
    should be
    I2CWrite DS_SDA, DS_SCL, RTC, ContReg,[%00000001]

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