'20x-2 picaxe High c.2 High c.0 SYMBOL control = b0 ; Used here for control bits DONT use for else SYMBOL mask = bit0 ; Mask word for the shiftout proceedure SYMBOL index = b1 ; Bit counter for shifting data to SOMO 14D SYMBOL track = w1 ; Pointer to the required track file SYMBOL dta = w2 ; Data to send is a word(16-bit) value SYMBOL MSB = $8000 ; Mask for the Most Significant Bit = bit 16 SYMBOL sda = c.0 ; Serial data output is on pin3 SYMBOL scl = c.2 ; Serial clock output is on pin2 SYMBOL busy = pinC.6 ; Busy line back from SOMO 14D Init: high scl ; Set clock to high idle state wait 5 ; Allow everything to start before sending commands 'goto Main loop1: 'b8 = 11 b10 = 0 IRIN b.6, b8 'b8 = 11 if b8 = 0 then t1b 'button1=0 if b8 = 1 then t1 '2 if b8 = 2 then t1 if b8 = 3 then t1 if b8 = 4 then t1 if b8 = 5 then t1 if b8 = 6 then t1 if b8 = 7 then t1 if b8 = 8 then t1 if b8 = 9 then t1a 'debug b8 goto loop1 loop2: t1b: b8 = 1 b10 = 1 goto t1 t1a: b8 = 0 t1: 'b12 = 55 pause 500 'b13 = 77 irin [2000,loop1],b.6,b9 if b9 = 0 then t2 'button1=0 if b9 = 1 then t2 '2 if b9 = 2 then t2 if b9 = 3 then t2 if b9 = 4 then t2 if b9 = 5 then t2 if b9 = 6 then t2 if b9 = 7 then t2 if b9 = 8 then t2 if b9 = 9 then t3a goto loop2 t2: if b8 = 0 then t3 if b8 = b10 then t4 b8 = b8 + 1 t4: b8 = b8 * 10 t3: b10 = b8 + b9 + 1 dta = b8 + b9 + 1 b12 = dta goto t5 t3a: b8 = b8 + 1 b8 = b8 * 10 b10 = b8 dta = b8 + b9 + 1 b12 = dta goto t5 t5: 'debug gosub send1 pause 1000 goto loop1 send1: gosub send2 GOSUB Hold return 'send data ; Send2: LOW scl ; Pull clock-line low for a start PAUSE 2 ; Start-bit time >= 2msec to indicate a start of command FOR index = 1 TO 16 ; loop for each of 16 bits of filename/number mask = dta AND MSB / MSB ; mask out the most sign. bit to find if next bit is 1 or 0 LOW sda IF mask = 0 THEN SkipMSB ; check if current data bit is "0" and skip if it is a zero HIGH sda ; set data line highonly if the data bit is a "1" SkipMSB: IF index = 16 THEN Skip16th ; Skip here as 16th bit is clocked out at the end PULSOUT scl,20 ; Create 200usec clock pulse for the current data bit dta = dta * 2 ; shift data one bit to left read to check for the next bit to shift out Skip16th: NEXT index ; Go back for the next bit till all 16 bits of data presented to SOMO module HIGH scl ; Pull clock-line high which also clocks out the 16th data bit PAUSE 2 ; End-bit minimum time >= 2msec for STOP indication RETURN 'hold till file finishes Hold: PAUSE 30 ; Need to wait briefly as it seemingly takes ~5-7msec for the busy line to go high = busy IF busy = 1 THEN Hold PAUSE 30 ; Need to wait briefly as it seemingly takes ~5-7msec after busy released before SOMO ready for new instruction RETURN