I2c & Variable Size


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Quote Originally Posted by Bill Legge View Post
    I'm using: PIC16F877A @ 20 MHz, an I2C RTC with PBP.

    The story so far:

    1. All works well - set the clock, read it and display the time.
    2. I have a loop counter (VAR BYTE) in my software to do a job not connected with the RTC.
    3. As long as the variable is a BYTE it works properly.
    4. But if I make the loop counter a WORD - it will not increment (Variable = Variable + 1) fails to work. If I by-pass the RTC - it starts working!
    5. The name of the loop counter is unique and not used in the RTC code.
    6. I do need the variable to be word-sized.

    Any ideas anyone?

    Regards Bill Legge
    Hi Bill,
    Without having a firm grasp on your code . . . It works with BYTE variable, but not WORD . . . don't you have to split the word into highbyte and lowbyte to use it?
    ahhh: not : that : i: could: read: it: Looks like skimask said that already!
    Last edited by Archangel; - 15th February 2008 at 22:13.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517

    Smile

    I have not studied your code but....

    >>Time var byte[3] ' Holds months,days,hours,mins read from RTC

    and then

    >>Time[3] = Month

    You are overwriting the LoopCounter LowByte here (see your LST file) - change the [3] to [4] in the VAR define.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136

    Default I2c Variable Length

    Thanks for your replies:

    Skimask:
    1. DEFINE OSC 20 was in caps in my code, I messed it up whilst trying to tidy up the post.
    2. Colon after TimeSet. As above, another 'posting mistake on my part. Code was OK.
    3. Don't use " or '. Point taken - I'll change the comments and try again.
    4. Thanks for the code - I'll give it a go. What is HCM?

    Joe S:
    1. HighByte/LowByte split - agreed I could 'work around' the problem but it seems
    important to me that I find out why a WORD won't increment around an I2C read.

    Paul B:
    1. I think the array size is OK; Time[3] has 4 elements: 0,1,2,3. I'll check with a bit of test code.

    Thanks to you all

    Regards Bill Legge

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517

    Smile

    >>Paul B:
    >>1. I think the array size is OK; Time[3] has 4 elements: 0,1,2,3. I'll check with a bit of test >>code.

    Hi Bill,

    Not OK- see your manual or your lst file
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136

    Default I2c Variable Length

    Paul B,

    Thanks - I agree. Time[3] would give me 3 elements 0,1,2.
    I'll make the changes.

    I've returned to electronics after a gap of 25 years and find my
    main difficulty is with the easier bits that I think I already know
    and don't bother to look them up - hence this sort of mistake.

    Regards

    Bill Legge

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343

    Default

    Not just Time, but Dtime also needs to be dimensioned correctly.

    Time var byte[4] ' Holds months,days,hours,mins read from RTC
    Dtime var byte[4] ' Holds months,days,hours,mins in HEX format

    SteveB

  7. #7
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136

    Default I2c Variable Size

    Thanks, I've changed the arrays to the correct size and -IT WORKS.

    Sorry to bang on about WORD/BYTE/I2C when I just got a variable format wrong.

    regards

    Bill Legge

  8. #8
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Bill Legge View Post
    Skimask:
    4. Thanks for the code - I'll give it a go. What is HCM?
    Regards Bill Legge
    Somebody coined the phrase for me awhile back... the 'High Colonic Master'. I like to use colons in my coding to keep as much of it on the screen at one time, prevent as much vertical scrolling as I can. Most people hate it, but I'm not writing code for most people, I'm writing code for me, and the majority of what I post here (or modify), gets the same treatment 'cause I like it that way...
    that's all, nothing much...

    I totally missed the array variable dimensioning thing...oh well...

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 01:06
  2. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 23:31
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 22:07
  4. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 20:33
  5. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21:36

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