Shop OBEX P1 Docs P2 Docs Learn Events
Object organization - Page 2 — Parallax Forums

Object organization

2»

Comments

  • NewzedNewzed Posts: 2,503
    edited 2006-05-21 12:38
    OK, Andy·- so now I can blink 1 to 8 LEDs with the Demo Board.

    Let's go to something more practical - I want to use a DS1307.· The
    SCA/SDL pins are hardwired to the 24LC256, which has an address of 000.The pins already have pullups so I wouldn't need to add that.· The WRITE address for the RTC is %1101_0000 or 208; the READ address is %1101_0001 or 209.

    I would have to start with a top file named "Top 1307".· At the very beginning of Top 1307 I would write:

    CON
    ··· _Wr = 208
    ··· _Rd = 209
    (Is the indentation space critical or do you just indent something.)

    Now what objects do I need?· To a PBasicer like me, and object is a sub-routine, so I think I would need a "wr_RTC"·, a "rd_RTC" and a "display_RTC".

    The variables - I would think the variables belong in the·three objects since they are the ones that would be using them.· So I would write:

    VAR

    ··· byte day, date, mon, year, hrs, mins, secs

    All·objects would have the same set of variables.· I want to use HEX2 notation so I would need a procedure to enter the 7 RTC parameters, which I think belongs in the wr_RTC object.

    That's about as far as I can go.· What do I do next?

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2006-05-21 13:07
    On secnd thought, I think the CON block goes in each object, not the top file.

    Sid
  • SSteveSSteve Posts: 808
    edited 2006-05-21 14:29
    Newzed said...
    To a PBasicer like me, an object is a sub-routine
    That's the concept you need to break. An object isn't a sub-routine. It's an independent "program" containing any number of subroutines. You'd have a single "RTC" object that handles all DS1307 functionality. Some of its methods write to the DS1307 and some read from the DS1307.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • edited 2006-05-21 15:29
    Sid,

    I found this page: http://forums.parallax.com/showthread.php?p=585972 by entering the following into Google:

    ···· Propeller i2c site:forums.parallax.com

    It was the fourth page in the list. Note that he has a DS1307 object with the necessary methods for Propeller-DS1307 communication. You can write a top file to call the various methods in the DS1307Obj object, which should make it pretty easy. There are also demo objects for several other I2C devices in his zip file.

    As a side note, it might be more economical to use a really accurate crystal connected to the Propeller. Then, the Propeller can be programmed to do the time tracking.

    Andy

    Post Edited (Andy Lindsay (Parallax)) : 5/21/2006 3:34:34 PM GMT
  • edited 2006-05-21 15:32
    newzed said: On second thought, I think the CON block goes in each object, not the top file.

    CON blocks can be included in both top and object files. Although it's more common to use a single CON block near the beginning of the file, I have seen CON blocks salted throughout programs when the coder wanted to keep CON directives close to the methods that use them. Either way works.
  • NewzedNewzed Posts: 2,503
    edited 2006-05-22 13:06
    Sid,

    I found this page: http://forums.parallax.com/showthread.php?p=585972 by entering the following into Google:

    ···· Propeller i2c site:forums.parallax.com

    I created a sub-directory in My Programs called DS1307.· I copied LCD Object, I2C Object,· DS1307Obj and I2CDemoApp into the sub-directory and renamed I2CDemoApp as "Top File DS1307".

    The program uses Pins 20 and 21 for SCL/SDA.· I will have to change this to Pins 28 and 29 for the Prop Demo board.

    I plan to go thru Top File DS1307 and delete everything that does not pertain to the DS1307 or one of its objects.

    OK so far?

    Sid
  • edited 2006-05-22 17:06
    Sid,

    You can comment out entire blocks of code by enclosing them in braces { }. This will make it easier to correct a mistake if you delete too much. As with PBASIC, if you want to comment a single line, an apostrophe still works too.

    The only things I see that need to be trimmed are in the i2cDemoApp.spin, which will be your top file.

    I think that the propeller demo board gives you breadboard access to P0 to P7. So, I would change the i2cSCL, i2cSDA, and LCD_Pin CON directives accordingly, maybe 0, 1, and 2.

    You are correct about putting your top file and all the objects it accesses in the same folder.· When you press F8 to compile, you'll notice some blue objects along with the usual yellow objects.· Those are library files (objects) that are in the Propeller.exe folder.· The Propeller editor always looks for objects in the same folder as your top file.· If it doesn't find them there, it looks for library objects in the same folder as Propeller.exe.· There are some important library objects in with Propeller.exe.· It would be a good idea to study them and their methods so that you know what you'll have at your disposal.

    Andy

    Post Edited (Andy Lindsay (Parallax)) : 5/22/2006 5:29:32 PM GMT
  • NewzedNewzed Posts: 2,503
    edited 2006-05-22 17:20
    Andy, couldn't I use Pins 28 and 29 on the Demo Board since they already have pullups and are the I2C bus for the 24LC256?

    I compiled Top File DS1307 and that was OK.· When I was going thru the different files, I noted the LCDObject had two sub-objects, Simple_Numbers and Simple_Serial.· These two files were not in my collection, and when I compiled LCDObject, in Object View they were identified by a square blue icon.· I went ahead and copied the two files into my DS1307 directory, and whemn I recompiled LCDObject, they were identified by square yellow icon, just like all the other files.· Why did LCDObject compile when I did not have these two files in the directory?

    By the way, I'm working on piggybacks for the Propeller, similar to my Stamp piggybacks.· So far I have one for the VGA Object and one for the DS1307.

    Thanks

    Sid
  • edited 2006-05-22 17:51
    Sid,

    I don't think it's worth it on the demo board. There is no socket access to the Propeller's EEPROM lines, it's all SMT, and the pullup resistor setup is different from a typical I2C bus. More info here: http://forums.parallax.com/forums/default.aspx?f=25&p=2&m=118363

    Andy

    Post Edited (Andy Lindsay (Parallax)) : 5/22/2006 5:59:35 PM GMT
  • NewzedNewzed Posts: 2,503
    edited 2006-05-22 18:15
    True, but with the piggyback between the socket and the Propeller, I would have access to Pins 28 and 29 on the piggyback; however, I took another look at the schematic for the Demo Board and I see no external pullup on P29.· It must be pulled up internally, so I will change the SDA/SCL lines to Pins 0 and 1 and pull them up externally.· Thanks for the advice.

    Sid
Sign In or Register to comment.