' -----[ Title ]------------------------------------------------------ ' ' File......: KEYBTST.BS2 ' Purpose...: Send characters to a PC via AT keyboard port. ' Author....: Christer Johansson [cj@hth.com] ' Version...: 0.12 ' Started...: 960613 ' Updated...: 960627 ' ' -----[ Program Description ]---------------------------------------- ' ' This simple program shows how to connect a BASIC Stamp II to the AT ' keyboard port on a PC and to send characters when one of six buttons ' is pressed. Please read KEYBTST.TXT for more information about it's ' limitations and for a simple shecmatic. ' -----[ Constants ]-------------------------------------------------- ' datpin con 0 'Keyboard Data clkpin con 1 'Keyboard Clock btn00 con 2 'Button 0 btn01 con 3 'Button 1 btn02 con 4 'Button 2 btn03 con 5 'Button 3 btn04 con 6 'Button 4 btn05 con 7 'Button 5 ' -----[ Variables ]-------------------------------------------------- ' temp var B2 'Temp variabel char var W2 'Variabel containing the character breakcode var W3 'Variabel containing "Breakcode" extcode var W4 'Variabel containing "Extended charcode" ' -----[ Initialization ]--------------------------------------------- ' 'Set pin 0 and 1 as outputs, rest as inputs Dirl= %00000011 'Set datpin and clkpin default to high (1) low datpin low clkpin 'Define breakcode ' s--DATA--PS (s=start, DATA=LSB First, P=parity, S=stop) breakcode=%11111000000 '/F0H 'Define extcode ' s--DATA--PS (s=start, DATA=LSB First, P=parity, S=stop) extcode=%11111100010 '/E0H ' -----[ Main Code ]-------------------------------------------------- ' start: temp=0 pause 1000 button btn00,0,255,100,temp,1,button00 button btn01,0,255,100,temp,1,button01 button btn02,0,255,100,temp,1,button02 button btn03,0,255,100,temp,1,button03 button btn04,0,255,100,temp,1,button04 button btn05,0,255,100,temp,1,button05 goto start ' -----[ Test Characters ]-------------------------------------------- ' ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit) 'char=%10110101110 '/SPACE 'char=%11100011110 '/a 'char=%11010010100 '/CR 'char=%11011001110 '/b 'char=%11100101110 '/t 'char=%10100101100 '/r 'char=%10011101110 '/d 'char=%10101111100 '/F1 'char=%11111000110 '/INS button00: 'Assign char a character with startbit, parity and stopbit. OBS inverted ! ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit) char=%11100011110 '/a gosub sendchar goto start button01: 'Assign char a character with startbit, parity and stopbit. OBS inverted ! ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit) char=%11010010100 '/CR gosub sendchar goto start button02: 'Assign char a character with startbit, parity and stopbit. OBS inverted ! ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit) char=%11011001110 '/b gosub sendchar goto start button03: 'Assigne char a character with startbit, parity and stopbit. OBS inverted ! ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit) char=%10110101110 '/SPACE gosub sendchar goto start button04: 'Assigne char a character with startbit, parity and stopbit. OBS inverted ! ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit) char=%10101111100 '/F1 gosub sendchar goto start button05: 'Assigne char a character with startbit, parity and stopbit. OBS inverted ! ' s--DATA--PS (s=startbit, DATA=LSB First, P=paritybit, S=stopbit) char=%11111000110 '/INS gosub sendextchar goto start ' -----[ Subroutines ]------------------------------------------------ ' sendchar 'Send character shiftout datpin,clkpin,1,[char\11] 'Send breakcode + character shiftout datpin,clkpin,1,[breakcode\11] shiftout datpin,clkpin,1,[char\11] return sendextchar 'Send extcode + character shiftout datpin,clkpin,1,[extcode\11] shiftout datpin,clkpin,1,[char\11] 'Send extcode + breakcode + character shiftout datpin,clkpin,1,[extcode\11] shiftout datpin,clkpin,1,[breakcode\11] shiftout datpin,clkpin,1,[char\11] return ' -----[ End ]--------------------------------------------------------