![]() |
Sending Commands in BASIC to ADR Interfaces OPENING A SERIAL FILESending commands to the ADR101 10 OPEN "COM1:9600,n,8,1,CS,DS,RS" AS#1 This line opens a serial file and labels it as serial file #1. This allows access to the ADR101 using PRINT#1 and INPUT#1 commands.
SENDING COMMANDSSending commands in BASIC to the ADR101 can be done using PRINT#1 commands. For example, sending an RA0 command could be done as shown below; 20 PRINT#1, "RA0" Extra spaces inside the quotes are ignored by the ADR101. Avoid
sending commands on consecutive lines because a carriage return 20 PRINT#1, "CPA00000000" 30 REM FORCES Variable names may also be used with PRINT#1 commands. One example of this shown below. This program configures PORT A as output and the increments it from 0 to 255. 10 OPEN "COM1:9600,n,8,1,CS,DS,RS" AS#1
20 PRINT#1, "CPA00000000"
30 FOR X = 0 to 255
40 PRINT#1, "MA",X
50 NEXT X
60 END
RECEIVING DATAWhen reading analog inputs or the digital port, data is sent from the ADR101 to the computers serial buffer. This data can be retrieved using INPUT#1 commands. The INPUT#1 command should be used following PRINT#1 commands if data is expected to be sent by the ADR101. If a single piece of data is expected then one variable name should be used with the INPUT#1 command. If eight pieces of data are to be received as with the RPA command then eight variable names must be used with the INPUT#1 command. Examples of both cases are shown below; 20 PRINT#1, "RA0"
30 INPUT#1, ANADAT
40 PRINT#1, "RPA"
50 INPUT#1, PA7,PA6,PA5,PA4,PA3,PA2,PA1,PA0
The variable names used in the INPUT#1 commands now contain the data sent by the ADR101. The data can now be scaled, printed, displayed, saved or whatever is required by the application.
A BASIC PROGRAM EXAMPLEA complete BASIC program which reads analog port 0 and sets PA0 if the analog port is above 50% ( 2.5 volts ) is shown below; 10 OPEN "COM1:9600,n,8,1,CS,DS,RS" AS#1 ;opens and configures serial file 20 PRINT#1, "CPA11111110" ;configures PA0 as output 30 REM FORCES |
|