Data from DS1307 (BCD) saved to ext memory and read back to display


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Data from DS1307 (BCD) saved to ext memory and read back to display

    That is correct. The 24LC64 data is 8 bits wide per individual location. CH1_PWM.lowbyte,CH1_PWM.highbyte is the correct way to sequentially load data into the eeprom if the variable is a word.
    Dave Purola,
    N8NTA
    EN82fn

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Thumbs up Defining eeprom address made it work

    It works!

    I declared the EEPROM address as WORD, replaced the $00 in the I2CWRITE and I2CREAD commands and now the result is okay.

    Thanks a lot for the help

    Code:
    '-------------------------------------------------------------------------------
    ' PIC 16F690 Fuses (MPASM)
    @ __Config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF 
    
    '-------------------------------------------------------------------------------
    ' Registers   76543210
    OPTION_REG = %10000000 'PORT A&B Pull-Ups disabled (look WPUA & WPUB) INTEDG rising edge on A2
    'OSCCON     = %01100000 'Internal RC set to 4Mhz - not to be used with XTal
    ANSEL      = %00000000 'Analog inputs Channels 0 to 7
    ANSELH     = %00000000 'Analog inputs Channels 8 to 11
    ADCON0     = %00000000 'A/D Module is OFF
    CM1CON0    = %00000000 'Comparator1 Module is OFF
    CM2CON0    = %00000000 'Comparator2 Module is OFF
    INTCON     = %00010000 'INTerrupts CONtrol
    TRISA      = %00000100 'Set Input/Output (0 to 5)
    PORTA      = %00000000 'Ports High/Low (0 to 5)
    TRISB      = %00010000 'Set Input/Output (4 to 7)
    PORTB      = %00000000 'Ports High/Low (4 to 7)
    TRISC      = %00000000 'Set Input/Output (0 to 7)
    PORTC      = %00000000 'Ports High/Low (0 to 7)
    
    '-------------------------------------------------------------------------------
    ' Defines
    DEFINE OSC 4
    
    '-------------------------------------------------------------------------------
    ' Variables
    SQW     VAR PORTA.2 ' RTC 1Hz output
    D_Out   VAR PORTB.7 ' serial data out
    SCL     VAR PORTC.0 ' RTC clock
    SDA     VAR PORTC.1 ' RTC data 
    
    RTC_Sec VAR BYTE    ' Seconds (00-59)
    RTC_Min VAR BYTE    ' Minutes (00-59)
    RTC_Hou VAR BYTE    ' Hours (00-23)
    
    Eep_Adr VAR WORD
    Eep_Adr = $00
    
    D_Bps   CON 16468   ' 9600 Driven Inverted None
    
    '-------------------------------------------------------------------------------
    ' Initialize
    PAUSE 1000                      ' power-up serial-LCD
    SEROUT2 D_Out,D_Bps,[27,"C",0]  ' set serial-LCD cursor OFF
    SEROUT2 D_Out,D_Bps,[27,"L",0]  ' set serial-LCD backlight OFF
    
    '-------------------------------------------------------------------------------
    ' Program
    ON INTERRUPT GOTO Read_DS1307
    
    MAIN:
        GOTO MAIN:
    END    
    
    '-------------------------------------------------------------------------------
    ' Interrutp Service Routine
    DISABLE
    Read_DS1307:
        I2CREAD SDA,SCL,$D1,$00,[RTC_Sec,RTC_Min,RTC_Hou]
    
        SEROUT2 D_Out,D_Bps,["HEX: ",HEX2 RTC_Hou,":",HEX2 RTC_Min,":",HEX2 RTC_Sec,13,10]
    
        ' Convert Hex coded to decimal - can be usefull for external memory data storage (logging)
        RTC_Sec = (RTC_Sec & $F)+((RTC_Sec >> 4)*10)
        RTC_Min = (RTC_Min & $F)+((RTC_Min >> 4)*10)
        RTC_Hou = (RTC_Hou & $F)+((RTC_Hou >> 4)*10)
    
        ' Write to external memory
        I2CWRITE SDA,SCL,$A0,Eep_Adr,[RTC_Sec,RTC_Min,RTC_Hou]
        PAUSE 10
        
        'Read from external memory
        I2CREAD SDA,SCL,$A0,Eep_Adr,[RTC_Sec,RTC_Min,RTC_Hou]
    
        SEROUT2 D_Out,D_Bps,["DEC: ",DEC2 RTC_Hou,":",DEC2 RTC_Min,":",DEC2 RTC_Sec,"   "]
    
        INTCON.1 = 0  'clear INTF interrupt flag
        RESUME 
    ENABLE
    Thank you Dave for explaining the WORD sized eeprom data.

    Before I started this thread, I didn't know about "packed BDC". I think it can be interesting to reduce data size especially when, like in my current project, time data has to be stored in external memory.
    Roger

Similar Threads

  1. Replies: 2
    Last Post: - 3rd January 2013, 16:57
  2. DS1307 - How to store Decimal Value & how to convert back to BCD?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd January 2011, 23:44
  3. loading data to EXt. eeprom
    By MINHLE in forum General
    Replies: 0
    Last Post: - 28th December 2009, 17:56
  4. Write Onewire data toa I2C memory / read ASCI
    By Eugeniu in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 16th November 2008, 19:19
  5. cannot read/write to 16F690 data memory after CPD_ON
    By awdsas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd November 2006, 11:46

Members who have read this thread : 0

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