-- -- file : shiftIn.jal -- author : special [k] -- date : 28-JAN-2004 -- purpose : Shift in data -- pins : Defined below -- -- Copyright (C) 2004 special [k] -- -- This library is free software; you can redistribute it and/or -- modify it under the terms of the GNU Library General Public -- License as published by the Free Software Foundation; either -- version 2 of the License, or (at your option) any later version. -- -- This library is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- Library General Public License for more details. -- -- You should have received a copy of the GNU Library General Public -- License along with this library; if not, write to the -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- Boston, MA 02111-1307, USA. -- -- -------------------------------------------------------------------------------- -- shiftIn(extInClock, theInMode) -- If extInClock = high and theInMode = 0 then shift in theData MSB first; sample bits during clock pulse -- If extInClock = high and theInMode = 1 then shift in theData LSB first; sample bits during clock pulse -- If extInClock = low and theInMode = 0 then shift in theData MSB first; sample bits before clock pulse -- If extInClock = low and theInMode = 1 then shift in theData LSB first; sample bits before clock pulse -- If extInClock = low and theInMode = 2 then shift in theData MSB first; sample bits during clock pulse -- If extInClock = low and theInMode = 3 then shift in theData LSB first; sample bits during clock pulse -- If extInClock = low and theInMode = 4 then shift in theData MSB first; sample bits after clock pulse -- If extInClock = low and theInMode = 5 then shift in theData LSB first; sample bits after clock pulse -- -------------------------------------------------------------------------------- procedure _shiftInDelay is -- delay_100mS(5) end procedure var volatile bit shiftInClk is gp5 var volatile bit shiftInClkDir is gp5_direction var volatile bit shiftInData is gp3 var volatile bit shiftInDataDir is gp3_direction function shiftIn( bit in extInClock, byte in theInMode) return byte is shiftInData = low shiftInDataDir = input var byte theInData = 0 if extInClock then shiftInClk = low shiftInClkDir = input if theInMode == 0 then -- MSB first var bit dataBit at theInData : 0 for 8 loop while ! shiftInClk loop end loop theInData = theInData << 1 dataBit = shiftInData while shiftInClk loop end loop end loop elsif theInMode == 1 then -- LSB first var bit dataBit at theInData : 7 for 8 loop while ! shiftInClk loop end loop theInData = theInData >> 1 dataBit = shiftInData while shiftInClk loop end loop end loop end if else shiftInClk = low shiftInClkDir = output if theInMode == 0 then -- MSB first; sample bits before clock pulse var bit dataBit at theInData : 0 shiftInClk = low for 8 loop theInData = theInData << 1 dataBit = shiftInData _shiftInDelay shiftInClk = high _shiftInDelay shiftInClk = low end loop elsif theInMode == 1 then -- LSB first; sample bits before clock pulse var bit dataBit at theInData : 7 shiftInClk = low for 8 loop theInData = theInData >> 1 dataBit = shiftInData _shiftInDelay shiftInClk = high _shiftInDelay shiftInClk = low end loop elsif theInMode == 2 then -- MSB first; sample bits during clock pulse var bit dataBit at theInData : 0 shiftInClk = low for 8 loop theInData = theInData << 1 _shiftInDelay shiftInClk = high dataBit = shiftInData _shiftInDelay shiftInClk = low end loop elsif theInMode == 3 then -- LSB first; sample bits during clock pulse var bit dataBit at theInData : 7 shiftInClk = low for 8 loop theInData = theInData >> 1 _shiftInDelay shiftInClk = high dataBit = shiftInData _shiftInDelay shiftInClk = low end loop elsif theInMode == 4 then -- MSB first; sample bits after clock pulse var bit dataBit at theInData : 0 shiftInClk = low for 8 loop _shiftInDelay shiftInClk = high _shiftInDelay shiftInClk = low theInData = theInData << 1 dataBit = shiftInData end loop elsif theInMode == 5 then -- LSB first; sample bits after clock pulse var bit dataBit at theInData : 7 shiftInClk = low for 8 loop _shiftInDelay shiftInClk = high _shiftInDelay shiftInClk = low theInData = theInData >> 1 dataBit = shiftInData end loop end if end if return theInData end function -- --------------------------------------------------------------------------------