PDA

View Full Version : How to send 7 cases and read 7 cases



Nauketec
08-22-2008, 05:19 AM
Howdy,

I have a project that uses 2 BS2P40 micros.

I need to send 0 to 7 cases out from one micro to be read by the other.
Unfortunately,ˇ The pins chosen are off by a bit (no pun).ˇ

The first micro uses ports (not pins) P1, P2, P3 to send data out, (there is nothing on PO, it was a mistake).

Theˇsecond micro uses ports (not pins) P0, P1, P2 to read data in. (P3 is used as an output)

I think what I need to use is the INA and OUTA commands but not sure how to filter out the unsed ports.

I would really appreciate any help but please use comments for I am a newbie.

Thanks

Daniel

Zoot
08-22-2008, 05:33 AM
So you are setting the number you want as the 3 pins and just reading them all in one shot?

DIRA
INA
OUTA

Are your friends here. Each of the above represents some aspect of pins 0-3 (let's presume for discussion that you have the correct IO bank on the BS2p set.




' for reading on P1, P2, P3 -- the first micro
myVal VAR Nib ' the number 0-7 coming in on the above pins

DIRA = DIRA & %0001 ' this makes p1-p3 inputs and leaves p0 untouched
' dira bits are set if that pin is an output, cleared (0) if input

DO
myVal = INA >> 1 ' grab the state of 4 inputs pins (0-3) at once shift all the bits one place right -- %0110 would become %0011
' that pesky bit0 (pin0) just drops off the face of the earth
DEBUG DEC1 myVal, CR
LOOP

' for reading on P0, P1, P2 -- the second micro
myVal VAR Nib ' the number 0-7 coming in on the above pins

DIRA = DIRA & %1000 ' this makes p0-p2 inputs and leaves p3 untouched
' dira bits are set if that pin is an output, cleared (0) if input

DO
myVal = INA & %0111 ' positions of pin input bits are OK, but we don't want pin3, so mask it off
' that pesky bit0 (pin0) just drops off the face of the earth
DEBUG DEC1 myVal, CR
LOOP





BTW -- If you need to comm. between to BS2p40s, personally I would use two pins on each and a high-baud SERIN/SEROUT with flow control (then you are much more flexible).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php (http://1uffakind.com/robots/povBitMapBuilder.php)
1uffakind.com/robots/resistorLadder.php (http://1uffakind.com/robots/resistorLadder.php)

Post Edited (Zoot) : 8/21/2008 10:56:54 PM GMT

Chris Savage
08-22-2008, 05:36 AM
Daniel,

You can use INA and OUTA to affect those lines. When reading INA the trick to ignoring the value of one of the bits depends on how you want to handle things. If your case since they literally are off by one bit you can simply shift the nibble left/right as necessary to properly align it with the next stage. On the end stage to ignore the bit you don’t want you simply mask it using bitwise AND. So you could do:

Result = INA & %1110  this will mask bit 0 from the variable.
Result = INA & %0111  this will mask bit 3 from the variable

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

Nauketec
08-22-2008, 06:15 AM
Hey Zoot - thanks for the help

The first micro was to send out through ports P1 P2 P3 should I just change the INA comand for OUTA?
and change the DIRA to %1110 ?

I am waiting to see if I become your post # 1000

thanks

Danel

Nauketec
08-22-2008, 06:19 AM
Chris

if this variable named Result masks the bits - is that result in bin also or DEC and do I need to leave out numbers - example:

would the results be 0000 = DEC 0
the next would be 0001 = can not be used
the next usable be 0010 = DEC 2

is that the correct truth table?

Result = INA & %1110  this will mask bit 0 from the variable.
Result = INA & %0111  this will mask bit 3 from the variable


thanks Daniel

Zoot
08-22-2008, 09:39 AM
If you just mask the bits, that would be the case. Shifting the bits into myval (for the micro on p1-p3) set the 3 bits you want "flush right" so you can read them "normally" i.e. 0-7.

You would modify both DIRA and OUTA to "send" info -- DIRA will let you switch those pins to outputs, OUTA will let you set those now outpin pins to 1s (high) or 0s (low).

Certainly make sure to connect the pins of the two Stamps together through a resistor (so if both pins on either end are *accidentally* made outputs and one is high and one is low you don't get a short. Or you could pull up all 3 lines with a 10k resistor, and just drive them low, i.e.



PinState VAR DIRA
PinState = %1000 ' all three inputs, pulled high, so other micro will see this as %0111
OUTA = %0000 ' but remember this is not "seen" on the pins if they are inputs, only outputs
' now if you change pinstate, you are actually switching between OUTPUT LOW and INPUT.
' in input the line is allowed to be pulled HIGH by the external resistor
' the idea here is that if BOTH micros drive the line low, there is no short circuit
' if one or the other drives high while the other is low, the resistor sucks away the high load
PinState = %1101 ' puts 010 on the lines
PinState = %1000 ' puts 111 on the lines
' since it's the opposite of 1 = high, you can also NOT the value to make it easier to read
PinState = ~%0111 ' puts 111 on the lines


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php (http://1uffakind.com/robots/povBitMapBuilder.php)
1uffakind.com/robots/resistorLadder.php (http://1uffakind.com/robots/resistorLadder.php)

Post Edited (Zoot) : 8/23/2008 8:29:32 AM GMT

Nauketec
08-22-2008, 01:55 PM
Hey Zoot and Jeff et al

Here is the code I am working with if you choose to look at it or have a go at changing it for me to test.

Thanks for all the help

Daniel

Chris Savage
08-22-2008, 10:04 PM
Masking the bits does just that. There is no change to the format of the value. Values are always stored in binary in memory. It is how we choose to view them that you refer to as the format, but in this case I have just taken the port and masked the bits. The value is the same whether you choose to represent it in decimal, hex or binary.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

Unsoundcode
08-23-2008, 07:17 AM
Hi Daniel, somewhere at the beginning of your "Main" program you should have P0 to P3 set to outputs (DIRA=%1111) because P0 is not used we don't really care. make a nibble variable that you can manipulate before you place it on the OUTA register. Once the variable is assigned a value shift the bits left 1 place so that they line up with P1 to P3.

eg:

LED_out VAR Nib

LED_out=5ˇ 'LED_out value now looks like this binary value %0101.......(P0=1,P1=0,P2=1 and P3=0)

LED_out=LED_out << 1ˇˇ ''LED_out value now looks like this binary value %1010.......(P0=0,P1=1,P2=0 and P3=1)

OUTA=LED_out 'Your output pins (P1 to P3) now contain the value 5

Those 3 outputs will be read by the the other processor on P0 to P2

eg:

CheckMode:

LED_in VAR Nib

LED_in =INA & 7ˇ 'We don't need P3 so we use the mask

ON LED_in GOSUB mode7,mode6,mode5,mode4,mode3,mode2,mode1,mode0 'if LED_in=5 gosub mode2 etc

mode1 mode2 etc are sub routines so at the end of each routine replace GOTO main with RETURN

Jeff T.

Nauketec
08-25-2008, 01:12 AM
Heyˇ Jeff



So much touble about these three pins I am electing to move the traces.ˇ I hate putting in wires toa board but I left provisions with extra holes at each IO pin just in case.ˇ So I am moving them now.

If you could help me with the new code that would be great so I can put this issue to restˇ I need to send out P0 P1 and P2 on one chip and make a debug so I can see the data and recieve data on the second micro om P0 P1 P2. and make a debug window to see it.ˇ You are using Gosub my program is uses goto comands on one side I need pieces that go into the sections that state something like outa =ˇ0, 1,2,3 4,.... 7 and on the othersideˇ reads 0 - 7 and sends it to a goto mode1,mode2,mode3 ... mode7

Thanks again.