rem AsciiKeyboard.bas symbol sclk = 7 ' clock (output pin) symbol serdata = input6 ' data pin symbol counter = b7 ' variable used during loop symbol var_in = b5 ' data variable used durig shiftin symbol bits = 8 ' number of bits symbol MSBValue = 128 ' MSB value symbol DisplayHex = bit0 ' init: high Sclk DisplayHex = 0 main: high 0 high 2 if input7 = 1 then getkeystroke 'Flag is set by the keyboard strobe goto main getkeystroke: low 2 gosub shiftin_LSB_Pre 'The clock also resets the flag high 2 serout 1,T2400,(var_in) if var_in = $d1 then SetHexFlag if var_in = $d0 then ClearHexFlag if DisplayHex = 0 then main DisplayHexValue: serout 1,T2400,(40) b1 = var_in & $F0 b1 = b1 / 16 gosub writehex b1 = var_in & $0F gosub writehex serout 1,T2400,(41," ") goto main SetHexFlag: DisplayHex = 1 goto DisplayHexValue ClearHexFlag: DisplayHex = 0 goto main ' ***** Shiftin LSB first, Data Pre-Clock ***** ' Shift in the data LSB first into variable var_in ' Read data before sending clock pulse ' Using clock output pin sclk ' Using data input pin serdata shiftin_LSB_Pre: let var_in = 0 for counter = 1 to bits ' number of bits var_in = var_in / 2 ' shift right as LSB first if serdata = 0 then skipLSBPre var_in = var_in + MSBValue ' set MSB bit if serdata = 1 skipLSBPre: pulsout sclk,4 ' pulse clock to get next data bit next counter return writehex: if b1 < 10 then number b1 = b1 + "W" goto writeit number: b1 = b1 + "0" writeit: serout 1,T2400,(b1) return