8 bit data through a 4-bit port.
kutalinelucas
Posts: 80
Hey guys, I was wondering if my logic is sound for sending a byte through OUTD on a basic stamp 2.
If I try to send an 8-bit value to 4 output data lines from the stamp, will the lower nibble or the upper nibble be sent?
Basically I have a 2-way 4 bit bus between a bs2 and a PIC18F. Reading data into the stamp is fine,
as is the handshaking between processors. I know 2 nibbles are sent from the bs2 using LEDs, but I'm not sure if this method first sends the upper nib of a byte, then the lower nibble...
So far, I:
1. Mask the lower nibble of the byte (eg 1011 0010 becomes 1011 0000
2. Shift the upper nibble 4 places to the right
3. Present on port
4. Swap nibbles of original byte (eg 1011 0010 becomes 0010 1011)
5. Mask lower nibbles (0010 0000)
6. Shift 4 places right
7. Present on port.
Here's what i'm thinking...
The problem is I can't really debug because it would take allot of re-wiring, and I can't really slow the sequence down because of the PIC timings.
If somebody could let me know if it should logically work than that would be brilliant.
if I can clarify in any way please let me know
Cheers
If I try to send an 8-bit value to 4 output data lines from the stamp, will the lower nibble or the upper nibble be sent?
Basically I have a 2-way 4 bit bus between a bs2 and a PIC18F. Reading data into the stamp is fine,
as is the handshaking between processors. I know 2 nibbles are sent from the bs2 using LEDs, but I'm not sure if this method first sends the upper nib of a byte, then the lower nibble...
So far, I:
1. Mask the lower nibble of the byte (eg 1011 0010 becomes 1011 0000
2. Shift the upper nibble 4 places to the right
3. Present on port
4. Swap nibbles of original byte (eg 1011 0010 becomes 0010 1011)
5. Mask lower nibbles (0010 0000)
6. Shift 4 places right
7. Present on port.
Here's what i'm thinking...
Temp_idx = (stalled_value & $0f0) 'mask bottom 4 bits Stalled_upper_nibble = (Temp_idx >> 4) 'move down for 4 bit bus OUTD = Stalled_upper_nibble 'present upper nibble on data_line OUT0 = 1 PAUSE(100) '[^^3^^ -> STAMP ENABLE HIGH FOR PIC TO READ PORTS] OUT0 = 0 '.................^^upper nib on port, then enable^^......................' Temp_idx = (Stalled_value << 4) | (Stalled_value >> 4) 'swap nibbles Temp_lower_nibble = Temp_idx & $0f0 '& to get rid of bottom bits Stalled_lower_nibble = Temp_lower_nibble >> 4 'shift left for 4 bit data transfer OUTD = Stalled_lower_nibble 'send lower nibble
The problem is I can't really debug because it would take allot of re-wiring, and I can't really slow the sequence down because of the PIC timings.
If somebody could let me know if it should logically work than that would be brilliant.
if I can clarify in any way please let me know
Cheers
Comments
You've got the right idea. You don't need to do any masking because the extra bits are going to be discarded. The process is simpler than you think: You could even make things simpler by using PULSOUT. Make sure to initialize OUT0 to 1 Note that in all cases, the time between the pulses that signal to the PIC is pretty short, maybe 300us compared to the 100ms for the signal pulse itself. Depending on how the PIC code handles this, you may want to put a short delay after the OUT0 = 0 or the PULSOUT.