Usage of lookup with outputs

IZ2EWV

New Member
Hello,
I want to set 4 outputs of a 08M2 according to 4 sequences of 16 bits.
Considering one sequence/output and assuming that b0 is used as pointer (from 0 to 8), I should use the subroutine:
Code:
loop:  lookup b0,(%0,%1,%0,%1,%1,%1,%0,%1,%0,%0,%0,%0,%0,%0,%0,%0),bit8
1st: is this instruction formally correct?
2nd question: how is it possible to set the output pin C.0 of the 08M2 according to the value of bit8?
3rd: after adding in the code the other 3 lookup instructions (which use the variables bit9, bit10 and bit12) how is possible to transfer the 4 bits to the 4 outputs C.0, C.1, C.2 and C.4 of the 08M2 in the same time, by using the "pins" instruction? I guess like this:
Code:
       pins = b1
Last: in the case that the port is larger (e.g. other PICAXE chip), how is it possible to keep theremaining pins configured as inputs? If I use the "pins" instruction, they should become outputs, if I don't misunderstand the instruction.
Thank you in advance,
Alberto
 
Last edited:

hippy

Technical Support
Staff member
Your code is correct and you can put that out on C.0 using -
Code:
Do
  For b0 = 0 To 15
    LookUp b0,(%0,%1,%0,%1,%1,%1,%0,%1,%0,%0,%0,%0,%0,%0,%0,%0),bit8
    pinC.0 = bit8
  Next
Loop
That won't affect any other C.x pins.

You could update all four pins with something like, my made up bit patterns -
Code:
Output C.4, C.2, C.1, C.0
Do
  For b0 = 0 To 15
    LookUp b0,(%0,%1,%0,%1,%1,%1,%0,%1,%0,%0,%0,%0,%0,%0,%0,%0),bit8
    LookUp b0,(%1,%1,%1,%1,%0,%0,%0,%0,%1,%1,%1,%1,%0,%0,%0,%1),bit9
    LookUp b0,(%1,%1,%0,%0,%0,%1,%1,%0,%0,%1,%1,%0,%0,%1,%1,%0),bit10
    LookUp b0,(%0,%1,%0,%1,%0,%1,%0,%1,%0,%1,%0,%1,%0,%1,%0,%1),bit12
    pinC.0 = bit8
    pinC.1 = bit9
    pinC.2 = bit10
    pinC.4 = bit12
  Next
Loop
Note we used 'bit12' not 'bit11' for C.4. While we are not updating 'pinC.3=bit11', it keeps a consistent bit to pin mapping for the bits of 'b1'.

One thing to note is that pins set as inputs won't be affected by "pins=" writes, so you can replace the four 'pinC.x=' above with a single 'pinsC=b1'.

In fact, you could have a single LOOKUP which copies values into 'pinsC' directly -
Code:
  For bo = 0 To 15
    LookUp b0, ( %10111, ... ), pinsC
  Next         ;   |
               ;   Would be C.3 but not used
 

IZ2EWV

New Member
Thank you very much!
One further confirmation, please: where you wrote "One thing to note is that pins set as inputs won't be affected by "pins=" writes, so you can replace the four 'pinC.x=' above with a single 'pinsC=b1'." you are saying that, if I write for a 14M2 the following
Code:
main:	let dirsC = %00010111
Pins C.3, C.5, C.6 and C.7 will remain inputs despite in the following code I write
Code:
                pinsC = %11111111
? In other words, "dirs" should have priority over "pins"? And should it be the same on other commands like "input", "output", "reverse", (what else)?
Thank you in advance, again.
Alberto
 

hippy

Technical Support
Staff member
That is one way of describing it; the "dirs" / "dir" bits have priority over the "pins" / "pin" bits.

The INPUT, OUTPUT and REVERSE commands will set "dir" but not "pin".

The HIGH, LOW and TOGGLE commands will set "dir" to be an output and then set "pin".

Most other commands which affect an I/O pin will also set "dirs" / "dir" bits as appropriate; COUNT and PULSIN will set "dir" as input, "PLSOUT" will set the "dir" as output.
 

IZ2EWV

New Member
That is one way of describing it; the "dirs" / "dir" bits have priority over the "pins" / "pin" bits.

The INPUT, OUTPUT and REVERSE commands will set "dir" but not "pin".

The HIGH, LOW and TOGGLE commands will set "dir" to be an output and then set "pin".

Most other commands which affect an I/O pin will also set "dirs" / "dir" bits as appropriate; COUNT and PULSIN will set "dir" as input, "PLSOUT" will set the "dir" as output.
Thank you again!

Alberto
 
Top