Serial Input to a Terminal (BX-24):
This circuit uses the BX to send bytes to the terminal. In this case I used a momentary pushbutton to put an ASCII character "1" on the screen. When the button is not pressed the ASCII character "0" is shown. To get these characters to display on screen, the BX actually sends out the ASCII numerical value. For example, when the button is not pressed we send the number 48 which corresponds to char "0". When the button is pressed we add 1 and get 49, which corresponds to the char "1".
In this example we use COM3 on the BX to put values out on a terminal program, in this case Zterm, which used to be free, but now you can download it here for $20.
Adding a Potentiometer :
The screen-grab below shows what happens when the momentary pushbutton is replaced with a 10kOhm potentiometer. Notice that the pot scales through all the ASCII characters, some of which may be undefined in the standard ASCII set. Example code can be found below.
dim inputBuffer(1 To 13) as byte '4-byte output buffer.
dim outputBuffer(1 To 50) as byte '1-byte output buffer.
dim thisByte as byte
sub main ()
call delay(0.5) ' start program with a half-second delay
' define which pins COM3 will be
' (input pin, output pin, baud mode):
call defineCom3(12,11,bx1000_1000)
' set aside memory for input and output:
call openQueue(inputBuffer, 13)
call openQueue(outputBuffer, 50)
' open COM3:
call openCom(3, 9600, inputBuffer, outputBuffer)
do
' read the value from the potentiometer
' note: getADC(pin) returns an integer rather than byte,
' so we cast it as a byte
thisByte = cByte(getADC(13)\4)
'send it out the serial port:
call putQueue(OutputBuffer, thisByte, 1)
loop
end sub
|