Same code in different Pins


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Colombia!
    Sorry for the misspelling, but I'm used to hearing a RED or GOLD after it. So it seemed different.

    And since I've been sitting on this answer for 4 days now, ...Not "THAT slow" is still slower than UPS ground.
    So here goes...

    As a reminder ...
    Quote Originally Posted by Darrel Taylor View Post
    And it's a scary one. Yet oh so cool.
    <hr>
    So here's the SCaRy part ...
    I'm going to ask you to modify a PBP macro file. AAAhhhhh!!!!

    Ohhh, stop screaming, It's easy!

    And, since it's easier to Do, than to explain, I'll start with the "HOW TO". Then comes the explanation.

    <hr>
    In your PBP folder, there is a file named PBPPIC14.MAC

    WARNING! Before making any changes to this file, Make a backup copy first.
    Don't blame me if it gets messed up and you have nothing to replace it with!

    Now that the legal issues are over <hr>
    Open the PBPPIC14.MAC file with NotePad.

    Do a Search for OWPIN?W

    You should see a section that looks like this...
    Code:
    OWPIN?T macro Regin, Bitin
            BIT?R1  Regin, Bitin
        endm
      endmod
    
    OWPIN?W macro Win
            MOVE?WA Win
            L?CALL  PINR1
        endm
    PINR1_USED = 1
      endmod
    
    ;****************************************************************
    ;* OWMODE?X   : Macro - Assign One-wire mode, check for reset   *
    Comment out the OWPIN?W macro with semicolons, and replace it with a new routine.
    It should look like this afterwards...(without the colors, of course)
    Blue is the OLD, Red is the NEW.
    Code:
    OWPIN?T macro Regin, Bitin
            BIT?R1  Regin, Bitin
        endm
      endmod
    
    ;OWPIN?W macro Win
    ;        MOVE?WA Win
    ;        L?CALL  PINR1
    ;    endm
    ;PINR1_USED = 1
    ;  endmod
    
    ;-- changed for addressing any pin with a word variable --
    ;-- highbyte = Offset from PORTA, lowbyte = PIN --
    OWPIN?W macro Win
            MOVE?CB PORTA, RR1
            MOVE?BA Win+1
            CHK?RP  RR1
            addwf   RR1, F
            MOVE?BB Win, R4
            L?CALL CONVBIT
            MOVE?AB RM1
        endm
    CONVBIT_USED = 1
      endmod
    
    ;****************************************************************
    ;* OWMODE?X   : Macro - Assign One-wire mode, check for reset   *
    That's It! .. Well, almost.<hr>
    Now the OWIN/OUT commands will accept a WORD variable that can address ANY pin on the chip.
    The next part is to figure out what that WORD is.

    You want the HighByte to be an Offset from PORTA. (0 is PORTA, 1 is PORTB, 2 is PORTC, etc.)
    The LowByte of the word is the BIT number (0-7).

    I'm sure there's a hundred ways to go about it, but here's one possibility.
    Create an array of WORDs, with each element specifying a different PIN.

    Code:
    OWpins   VAR  WORD[16]                    ; assign pins for OneWire commands.
      OWpins(0)  = $0000  ; PORTA is 0, bit 0 ; Assignments can be in any order
      OWpins(1)  = $0002  ;             bit 2 ; Shown sequentially here for clarity
      OWpins(2)  = $0100  ; PORTB is 1, bit 0
      OWpins(3)  = $0101  ;             bit 1
      OWpins(4)  = $0102  ;             bit 2
      OWpins(5)  = $0103  ;             bit 3
      OWpins(6)  = $0104  ;             bit 4
      OWpins(7)  = $0105  ;             bit 5
      OWpins(8)  = $0106  ;             bit 6
      OWpins(9)  = $0107  ;             bit 7
       ... 
      OWpins(15) = $0307  ; PORTD is 3, bit 7
    Which then allows you to do the original request ...
    Code:
    <font color="#000000"><b>PIN  </b><font color="#008000"><b>VAR BYTE
    
    FOR </b></font><b>PIN </b>= <b>0 </b><font color="#008000"><b>TO </b></font><b>15
        </b><font color="#008000"><b>OWOUT </b></font><b>OWpins</b>(<b>PIN</b>), <b>1</b>, [<font color="#FF0000">&quot;data here&quot;</font>]
    <font color="#008000"><b>NEXT </b></font><b>PIN</b>
    That really is IT.
    <hr>
    The Explanation.

    When compiling.., PBP chooses the correct macro to use depending on what type of variable you pass to the statement.
    If you pass a BYTE variable as the PIN, it assumes it's a "PIN Number" (0-15) and uses the macro OWPIN?B

    If you pass a PORTB.0 type, it hard codes the pin and bit with the OWPIN?T macro.

    These choices are made by the PBP(W).EXE compiler, and we have no way to change that.
    However, the actual macro's that are called, are "Open Source", so we are free to change the way the commands behave, even though the compiler doesn't know about it.

    Now it's probably not a good idea to go around changing the way things work on a general basis, but sometimes it can make a big difference.

    And in the case of OWPIN? there's a macro that really should never be used. It's OWPIN?W
    While it allows you to use a WORD variable for the "PIN Number", it's value is limited to 0-15, so a word variable doesn't make a whole lot of sense.

    Since it's already built in to the compiler, and it'll never be used. If we re-write the macro that goes with it, we can use it to select any pin we want, and still have OWIN/OUT work exactly the same way it did before.

    *** I was going to go further into the macros here, but, in case you already understand, I'll wait. **

    The only problem, is that on the next Upgrade to PBP, any changes will be overwritten.
    So you'll have to remember what you've changed. I usually make a .txt file in the same folder as the project, and make notes on any changes required for that program.
    Or, like Joe S. did, you can just bookmark this thread for future reference.

    <HR>
    Now then, I can see the wheels turning in a couple people's minds. And you're right!

    The same concept can work for any command that uses "PIN Numbers".
    SERIN/OUT, PULSIN/OUT, FREQOUT, DTMF, BUTTON, ... ok, well just about all of them.
    You simply need to change the appropriate macro for the specific command.

    If you have PINs scattered all over the place, it's an easy way to address ANY of them in a sequential (or random) manor.
    But, if your PINs can fit into 2 ports, the PORTL/H approach shown in the previous posts is preferred.
    DT

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    And since I've been sitting on this answer for 4 days now, ...Not "THAT slow" is still slower than UPS ground.
    So here goes...
    Brilliant! Absolutely BRILLIANT!
    You really should fire that off to MeLabs...
    Maybe end up making a SEROUT3/OWOUT2 or something along those lines.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Woohoo!

    Does that mean I can have a Guinness now?





    Watch this one last.

    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Talking JAjajajaja I knew it!!! DARREL can!

    Oh my God this is awesome, i am going to work on it right now!!! will post as soon as i am finished.

    And ...

    BRILLIANT!.... by the way. jeje
    Last edited by Josuetas; - 2nd April 2007 at 23:36.

  5. #5


    Did you find this post helpful? Yes | No

    Default Well it Works GREAT!

    I have already wrote and read from each device with this method.

    Darrel, Why would i go back to the previous version of the Macro? this is a real question, do you think of any reason?

    And since life is a Learning HighWay... can you explain a bit of the asm code and can you lead me to do it on 18F devices?

    Thanks Again



    ________
    DJC

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Josuetas View Post
    I have already wrote and read from each device with this method.

    Darrel, Why would i go back to the previous version of the Macro? this is a real question, do you think of any reason?
    Great! Glad you got it working.

    There's really no reason at all to go back.
    As mentioned before, since the "PIN Numbers" are limited to 0-15, there should never be a reason to have the OWPIN?W macro the way it was before.
    Even if you must use a word variable for some reason or another, you can just use the .LowByte modifier and PBP will use the OWPIN?B macro instead.

    Quote Originally Posted by Josuetas View Post
    And since life is a Learning HighWay... can you explain a bit of the asm code and can you lead me to do it on 18F devices?
    OK, well I should have done the 18F version at the same time I did the 16F. The differences in the chips, makes things different for these routines too. It would be too confusing the way it was, so I've changed the way my last example works so that they will work the same for both 16F and 18F's.

    Up in Post #26, I've modified the macro to use an Offset from PORTA, instead of just the Address of PORTx.
    This way, the actual usage of the WORD variables will be the same for both chips.

    And here's the macro for the 18F's. This one goes in the PBPPIC18.MAC file.
    Code:
    ;-- changed for addressing any pin with a word variable --
    ;-- highbyte = Offset from PORTA, lowbyte = PIN --
    OWPIN?W macro Win
            MOVE?CB  high(PORTA), RS1
            MOVE?CB  low(PORTA), RR1
            MOVE?BA  Win+1
            CHK?RP   RR1
            addwf    RR1, F
            MOVE?BB  Win, R4
            L?CALL   CONVBIT
            MOVE?AB  RM1
        endm
    CONVBIT_USED = 1
      endmod
    The usage will be the same as in Post #26 for the 16F's. (please go back and review it again)

    I'm still trying to figure out how I can explain the macro's.
    <br>
    DT

  7. #7


    Did you find this post helpful? Yes | No

    Default It also works... of course..

    My head is telling me somehow: "You donīt really wanna know"
    Man it seems thought..

    I will hold my breath and just go with my happy new versions of the OWPIN? macro.

    Gracias otra vez

Similar Threads

  1. My code for TV remote and MIBAM for RGB control
    By idtat in forum Code Examples
    Replies: 4
    Last Post: - 12th January 2013, 20:52
  2. Nokia COLOR LCD PicBasicPro 2.50a example code
    By skimask in forum Code Examples
    Replies: 49
    Last Post: - 28th September 2011, 01:43
  3. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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