ShiftIn, ShiftOut Replacement code
Archiver
Posts: 46,084
For Tracy Allen:
I tried your code, but unfortunately it won't compile:
The code below works fine with a short cable between the SHT1X and the BS2:
'sends "ioByte"
'returns "ackBit"
SHT_Write_Byte:
SHIFTOUT ShtData, Clock, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
SHIFTIN ShtData, Clock, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
RETURN
'returns "ioByte"
'sends "ackBit"
SHT_Read_Byte:
SHIFTIN ShtData, Clock, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
INPUT ShtData ' release data line
RETURN
where "ShtData" is set as a constant, or "ShtData CON 1"; "Clock" is set as a constant, or "Clock CON 0"; "ioByte" is set as a variable byte, or "ioByte VAR Byte"; "ackBit" is set as a variable bit, or "ackBit VAR Bit"
The below code which I put in to replace SHIFTOUT and SHIFTIN (The original SHIFTOUT, SHIFTIN code lines have been commented out) was supposed to work with a remoted SHT1X on a 50 foot piece of telephone line (4 wire), but always gives an error when I attempt to compile it. The error is on the line
"ShtData2=ioByte.BIT0(ToDelay)"
where the ShtData2 term is highlighted and the error note says "expected a Label, Variable, or Instruction". I tried to follow your previous advice on this, but........?? Would you, could you, please help me?
'sends "ioByte"
'returns "ackBit"
SHT_Write_Byte2:
'SHIFTOUT ShtData2, Clock2, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
FOR ToDelay = 7 TO 0 '7 to 0 is MSBFIRST
ShtData2=ioByte.BIT0(ToDelay)
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
'SHIFTIN ShtData2, Clock2, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
FOR ToDelay = 0 TO 1 '0 to 1 is LSBPRE, 1 Bit Only
ackBit.BIT0(ToDelay)=ShtData2 'ackBit valid pre clock pulse
PULSEOUT Clock2,10 '10 milisecond clock pulse
RETURN
'returns "ioByte"
'sends "ackBit"
SHT_Read_Byte2:
'SHIFTIN ShtData2, Clock2, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
FOR ToDelay = 7 TO 0 '7 to 0 is MSBPRE
ioByte.BIT0(ToDelay)=ShtData2 'ShtData2 valid pre clock pulse
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
'SHIFTOUT ShtData2, Clock2, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
FOR ToDelay = 0 TO 1 '0 to 1 is LSBFIRST, 1 Bit Only
ackBit.BIT0(ToDelay)=ShtData2 'ackBit valid clock pulse
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
INPUT ShtData2 ' release data line
RETURN
Many thanks for your previous advice and any help you can offer further.
Kindest regards, Chuck Irwin
[noparse][[/noparse]Non-text portions of this message have been removed]
I tried your code, but unfortunately it won't compile:
The code below works fine with a short cable between the SHT1X and the BS2:
'sends "ioByte"
'returns "ackBit"
SHT_Write_Byte:
SHIFTOUT ShtData, Clock, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
SHIFTIN ShtData, Clock, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
RETURN
'returns "ioByte"
'sends "ackBit"
SHT_Read_Byte:
SHIFTIN ShtData, Clock, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
INPUT ShtData ' release data line
RETURN
where "ShtData" is set as a constant, or "ShtData CON 1"; "Clock" is set as a constant, or "Clock CON 0"; "ioByte" is set as a variable byte, or "ioByte VAR Byte"; "ackBit" is set as a variable bit, or "ackBit VAR Bit"
The below code which I put in to replace SHIFTOUT and SHIFTIN (The original SHIFTOUT, SHIFTIN code lines have been commented out) was supposed to work with a remoted SHT1X on a 50 foot piece of telephone line (4 wire), but always gives an error when I attempt to compile it. The error is on the line
"ShtData2=ioByte.BIT0(ToDelay)"
where the ShtData2 term is highlighted and the error note says "expected a Label, Variable, or Instruction". I tried to follow your previous advice on this, but........?? Would you, could you, please help me?
'sends "ioByte"
'returns "ackBit"
SHT_Write_Byte2:
'SHIFTOUT ShtData2, Clock2, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
FOR ToDelay = 7 TO 0 '7 to 0 is MSBFIRST
ShtData2=ioByte.BIT0(ToDelay)
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
'SHIFTIN ShtData2, Clock2, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
FOR ToDelay = 0 TO 1 '0 to 1 is LSBPRE, 1 Bit Only
ackBit.BIT0(ToDelay)=ShtData2 'ackBit valid pre clock pulse
PULSEOUT Clock2,10 '10 milisecond clock pulse
RETURN
'returns "ioByte"
'sends "ackBit"
SHT_Read_Byte2:
'SHIFTIN ShtData2, Clock2, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
FOR ToDelay = 7 TO 0 '7 to 0 is MSBPRE
ioByte.BIT0(ToDelay)=ShtData2 'ShtData2 valid pre clock pulse
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
'SHIFTOUT ShtData2, Clock2, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
FOR ToDelay = 0 TO 1 '0 to 1 is LSBFIRST, 1 Bit Only
ackBit.BIT0(ToDelay)=ShtData2 'ackBit valid clock pulse
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
INPUT ShtData2 ' release data line
RETURN
Many thanks for your previous advice and any help you can offer further.
Kindest regards, Chuck Irwin
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
>where the ShtData2 term is highlighted and the error note says
>"expected a Label, Variable, or Instruction".
That sounds like you might not have defined ShtData2 correctly. The
best way to define it under PBASIC 2.5 is by using the new "PIN"
declaration, as follows. Also, I think you will need to use the
OUTPUT and INPUT commands to set the pin direction.
ShtData2 PIN 1
Clock2 PIN 0
ToDelay VAR Nib
ioByte VAR Byte
SHT_Write_Byte2:
OUTPUT ShtData2 ' the pin needs to be an output
FOR ToDelay = 7 TO 0 '7 to 0 is MSBFIRST
ShtData2=ioByte.BIT0(ToDelay) ' sets the output register
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
SHT_Read_Byte2:
INPUT ShtData2 ' the pin needs to be an inout
FOR ToDelay = 7 TO 0 '7 to 0 is MSBPRE
ioByte.BIT0(ToDelay)=ShtData2 'ShtData2 valid pre clock pulse
PULSEOUT Clock2,10 '10 milisecond clock pulse
NEXT
I hope that helps?
-- Tracy
>For Tracy Allen:
>I tried your code, but unfortunately it won't compile:
>The code below works fine with a short cable between the SHT1X and the BS2:
>
>'sends "ioByte"
>'returns "ackBit"
>
>SHT_Write_Byte:
> SHIFTOUT ShtData, Clock, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
> SHIFTIN ShtData, Clock, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
> RETURN
>
>'returns "ioByte"
>'sends "ackBit"
>
>SHT_Read_Byte:
> SHIFTIN ShtData, Clock, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
> SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
> INPUT ShtData
>' release data line
> RETURN
>
>where "ShtData" is set as a constant, or "ShtData CON 1"; "Clock"
>is set as a constant, or "Clock CON 0"; "ioByte" is set as a
>variable byte, or "ioByte VAR Byte"; "ackBit" is set as a variable
>bit, or "ackBit VAR Bit"
>
>The below code which I put in to replace SHIFTOUT and SHIFTIN (The
>original SHIFTOUT, SHIFTIN code lines have been commented out) was
>supposed to work with a remoted SHT1X on a 50 foot piece of
>telephone line (4 wire), but always gives an error when I attempt to
>compile it. The error is on the line
>"ShtData2=ioByte.BIT0(ToDelay)"
>where the ShtData2 term is highlighted and the error note says
>"expected a Label, Variable, or Instruction". I tried to follow
>your previous advice on this, but........?? Would you, could you,
>please help me?
>
>'sends "ioByte"
>'returns "ackBit"
>
>SHT_Write_Byte2:
> 'SHIFTOUT ShtData2, Clock2, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
> FOR ToDelay = 7 TO 0
>'7 to 0 is MSBFIRST
> ShtData2=ioByte.BIT0(ToDelay)
> PULSEOUT Clock2,10 '10 milisecond clock pulse
> NEXT
> 'SHIFTIN ShtData2, Clock2, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
> FOR ToDelay = 0 TO 1 '0 to 1 is
>LSBPRE, 1 Bit Only
> ackBit.BIT0(ToDelay)=ShtData2 'ackBit valid pre
>clock pulse
> PULSEOUT Clock2,10 '10 milisecond clock pulse
> RETURN
>
>'returns "ioByte"
>'sends "ackBit"
>
>SHT_Read_Byte2:
> 'SHIFTIN ShtData2, Clock2, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
> FOR ToDelay = 7 TO 0 '7 to 0 is MSBPRE
> ioByte.BIT0(ToDelay)=ShtData2 'ShtData2 valid pre
>clock pulse
> PULSEOUT Clock2,10 '10 milisecond clock pulse
> NEXT
> 'SHIFTOUT ShtData2, Clock2, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
> FOR ToDelay = 0 TO 1 '0 to 1 is
>LSBFIRST, 1 Bit Only
> ackBit.BIT0(ToDelay)=ShtData2 'ackBit valid clock pulse
> PULSEOUT Clock2,10 '10 milisecond clock pulse
> NEXT
> INPUT ShtData2 ' release data line
> RETURN
>
>Many thanks for your previous advice and any help you can offer further.
>Kindest regards, Chuck Irwin
>