Posted: 12:22am 06 Mar 2016 |
Copy link to clipboard |
 Print this post |
|
Hi Konya,
Further to my last post, the following 5.0 code should clock out a byte serially, lsb first, although I haven't actually run the code. The receiver should monitor the clock pin and on a 0 to 1 transition, sample the data pin.
' Sample code to clock a byte out serially, lsb first.
'
' a bit of setup code for this example - normally your program would have
' done this before calling the sub routine
'
' define dat and clock pins as digital outputs
setpin datapin,DOUT ' any digital out pins for clock and data
setpin clkpin,DOUT
pin(clkpin)=0 ' clock pin to 0 to start
' example byte to output
sobyte% = &H10100101
' sub routine to clock out byte
sub shift_byte_out (sobyte%,datapin,clkpin,x)
local sobyte%,dpin,cpin,sobit%
dpin = datapin
cpin = clkpin
for x = 1 to 8
sobit% = &H00000001 AND sobyte% ' mask and select lsb
sobyte% = sobyte% >> 1. ' shift byte 1 bit place right
if setbit% = 0 then
pin(datapin) = 0
else
pin(datapin) = 1
endif
pause 1. ' wait for data pin to stabilize - a guess?
pin(cpin) = 1 ' pulse the clock pin
pause = 1 ' 1mS clock width
pin(cpin) = 0
pause 1 ' set this to determine clock speed
next x. ' loop through 8 bits
end sub
The shift in routine will be similar, maybe interrupt on a low to high clock then sample data line in an 8 bit loop.
Hope this helps,
Doug.
[EDIT} Fixed a couple of errors in code. D.
Edited by panky 2016-03-07 ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |