Dr. Nabil Rami was kind enough to forward this code that he has successfully used with the PAK-VII and the OOPic. These commands should also be useful for other "ShiftIn/ShiftOut" PAKs (all but the PAK-V and VI). The main parts that concern the PAK are the FReset command (initial reset), shift_out (send a byte), and shift_in_word (read a 16-bit word). Obviously, for some PAKs you'd need to be able to read in a byte as well, but that should be straightforward from this program.
Thanks Dr. Rami!
'Example of using the PAK VII with an OOPIC to read the value of 'of pulses from a servo PWM signal r/c receiver hooked to the PAK VII 'PAK VII data input and output are connected to the OOPIC line 7, the clock is Line 5 in the OOPIC 'Done by Nabil Rami email@example.com 'some of this code was initially done by Tony Brenke Dim wPakReceivedData As New oWord Dim clock_pin as new oDio1 Dim data_pin as new oDio1 Dim LCD as new oLcd Const PakResetCommand = &hFF const Servo0Com = &b01001000 Sub Main () call setup do shift_out(Servo0Com) 'send serco0 command wPakReceivedData=shift_in_word 'receive response LCD.Clear lcd.string = str$(wPakReceivedData) 'display the result oopic.delay = 50 'hold it for half a second loop 'run all the time end sub sub Setup() LCD.IOLineRS = 26 ' Set up the oLCD object LCD.IOLineE = 27 LCD.IOGroup = 3 LCD.Nibble = 1 LCD.Operate = 1 ' Turn on the oLCD Object. LCD.Init ' Initialize the LCD Module. LCD.Clear ' Clear the screen. clock_pin.ioline = 5 'use line 5 for clock clock_pin.direction = cvoutput 'clock line is always used as output data_pin.ioline = 7 'use line 7 for data input and output call Freset 'reset using data and clock sequencing shift_out(PakResetCommand) 'reset using the total reset command oopic.delay = 10 'let it settle end sub sub Freset() 'reset using clock and data sequence clock_pin.value=0 'make sure the clock is at low level data_pin.direction = cvoutput 'data line should be used as an output this time data_pin.value = 0 'make sure the data is at low level clock_pin.value=1 'switch the clock to one data_pin.value = 1 'then while the clock is at one switch data to one clock_pin.value=0 'then switch the clock back to one while data is still at one data_pin.value = 0 oopic.delay = 10 'let it settle end sub sub shift_out(dataout as byte) 'send an 8-bit value one bit at a time. the MSB first dim tmp as new obyte dim count as new obyte tmp = dataout count.value = 8 'we are sending 8 bits clock_pin.value = 0 data_pin.direction = cvoutput 'now the data line is set to be used as output do if count.value > 0 then data_pin.value = tmp.msb 'set the data line to the MSB clock_pin.value = 1 'pulse the clock clock_pin.value = 0 tmp.lshift 'left shift so the next character become the MSB count.dec else exit do 'exit when we have sent all 8 bits end if loop end sub ' receive a 16-bit value one byte at a time with the lowest byte ' first using presampling method with the MSB first function shift_in_word() as word Dim data_in as new oBit dim tmp3 as new oByte dim tmp4 as new oWord dim counter2 as new obyte tmp3.clear tmp4.clear counter2.value=8 'receiving 8 bits first clock_pin.value = 0 data_pin.direction = cvinput 'at this time the data line is used as an input to receive data do if counter2.value > 0 then tmp3.lshift 'we are receiving data from the highest to the lower bit data_in.value= data_pin.value 'read the value of one bit tmp3.value = data_in.value + tmp3.value 'add the new bit to the rest of bit sequence clock_pin.value = 1 'pulse the clock for the next bit clock_pin.value = 0 counter2.dec else exit do 'exit when we done receiving the lower byte end if loop counter2.value=8 'redo the same thing with the second byte do if counter2.value > 0 then tmp4.lshift data_in.value= data_pin.value tmp4.value = data_in.value + tmp4.value clock_pin.value = 1 clock_pin.value = 0 counter2.dec else exit do end if loop counter2.value=8 'left shift the second byte eight times so it position itself in the upper byte of the 16-bit word do if counter2.value > 0 then tmp4.lshift counter2.dec else exit do end if loop shift_in_word = tmp3.value + tmp4.value 'add the lower byte with the upper byte to form the 16-bit value received end function
Site contents © 1997-2018 by AWC, Houston TX (281) 334-4341