Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Definizioni.
6-9VDC 15 14 Vdd 13 12
9 Vdc
Battery Red
Black
X4 X5
Pwr
Vdd Vin Vss
Vss Vss X3
P0 P1
P2 P3 P15
P4 P5 P14
P6 P7 P13
P8 P9 P12
Sout Vin P10 P11 P11
Sin Vss P12 P13 P10
ATN Rst P14 P15 P9
Vss Vdd Vdd Vin P8
P0 P15 X1 P7
P1 P14 P6
P2 P13 P5
P3 P12 P4
P4 P11 P3
P5 P10 P2
Reset P1
P6 P9
P7 P8 P0
X2
0 1 2
PORTE LOGICHE. Il BS2 è dotato di 24 piedini dei quali 16 sono porte logiche, cioè dei contatti
utilizzabili in input ed output, i rimanenti 8 sono contatti tra cui la messa a terra. Ciascuna porta
logica può essere assimilata ad un interruttore che può essere aperto o chiuso.
LABEL. Con il termine label (etichetta) si identifica una posizione precisa all’interno di un
programma redatto in P BASIC. Lo scopo dell’etichetta è quello di creare un indirizzo rispetto al
quale si possa indicare “un salto di programma”.
1/5
ELEMENTI DI PROGRAMMAZIONE IN LINGUAGGIO P-BASIC
DEFINIZIONI E PRINCIPALI ISTRUZIONI E COMANDI
In informatica esistono due regole molto importanti seguite dai programmatori per contenere gli
errori di programmazione:
- redigere il flow-chart prima della stesura del listato in modo da ordinare logicamente i
passaggi principali del programma;
- redigere il programma un blocco alla volta per passare a quello successivo solo dopo aver
testato con successo solo il blocco precedente.
VARIABILI. Le variabili devono essere dichiarate per prime (dalla seconda riga del listato in poi);
l’utente ha il compito di attribuire un nome alla variabile e la sua tipologia secondo la seguente
sintassi:
X var word dove: X è il nome della variabile, var indica che X è una variabile, word indica il tipo di
variabile (word:alfanumerico; in:input; bin:binario).
GOTO Questo comando (letteralmente vai a) indirizza il puntatore del listato ad una
etichetta specificata consentendo al programma di compiere un salto di istruzioni.
IF...THEN… ELSE It tests a condition and, if that condition is true, goes to a point in the
program specified by an address label. The condition that IF...THEN tests is written as a
mixture of comparison and logic operators.
ON...GOTO. This works exactly the same as the previous IF...THEN example.
BRANCH. E’ di per sé un ciclo “IF THEN” multiplo che consente la gestione di più stati
combinati provenienti da input esterni
LOOPING
DO...LOOP. Loops let your program execute a series of instructions indefinitely, or until a
specified condition terminates the loop.
2/5
ELEMENTI DI PROGRAMMAZIONE IN LINGUAGGIO P-BASIC
DEFINIZIONI E PRINCIPALI ISTRUZIONI E COMANDI
FOR...NEXT Viene utilizzato quando si hanno una o più variabili; la parola FOR viene
seguita dal nome della variabile e subito dopo vengono indicate le specifiche; la parola
NEXT viene inserita nelle righe successive per chiudere il campo di funzionamento
EXIT 2.5
EEPROM ACCESS
RAM ACCESS
NUMERICS
LOOKUP 2
LOOKDOWN
DIGITAL I/O
INPUT There are several ways to make a pin an input. When the BASIC Stamp is reset, all
of the pins are inputs. Commands that rely on input pins, like PULSIN and SERIN,
automatically change the specified pin to input. Writing 0s to particular bits of the variable
DIRS makes the corresponding pins inputs. And then there’s the INPUT command.
When a pin is an input, your program can check its state by reading from the corresponding
INS variable (PINS on the BS1).
OUTPUT. There are several ways to make a pin an output. Commands that rely on output
pins, like PULSOUT and SEROUT, automatically change the specified pin to output. Writing
1s to particular bits of the variable DIRS makes the corresponding pins outputs. And then
there’s the OUTPUT command.
When a pin is an output, your program can change its state by writing to the corresponding
bit in the OUTS variable (PINS on the BS1).
REVERSE
LOW. The LOW command sets the specified pin to 0 (a 0 volt level) and then sets its mode
to output.
HIGH. The HIGH command sets the specified pin to 1 (a +5 volt level) and then sets its
mode to output.
TOGGLE
PULSIN. PULSIN is like a fast stopwatch that is triggered by a change in state (0 or 1) on the
specified pin.
3/5
ELEMENTI DI PROGRAMMAZIONE IN LINGUAGGIO P-BASIC
DEFINIZIONI E PRINCIPALI ISTRUZIONI E COMANDI
PULSOUT. PULSOUT sets Pin to output mode, inverts the state of that pin; waits for the
specified Duration; then inverts the state of the pin again; returning the bit to its original state.
ASYNCHRONOUS I/0
OWOUT
SHIFTIN
SHIFTOUT
I2CIN
I2COUT
PARALLEL I/O
LCDCMD
LCDIN
LCDOUT
ANALOG I/O
PWM
POT
RCTIME
TIME
PAUSE Questo comando imposta una pausa espressa in millisecondi durante il quale la
BS2 funziona esattamente come un timer.
POLLWAIT
SOUND
4/5
ELEMENTI DI PROGRAMMAZIONE IN LINGUAGGIO P-BASIC
DEFINIZIONI E PRINCIPALI ISTRUZIONI E COMANDI
SOUND. SOUND generates one of 255 square-wave frequencies on an I/O pin. The output
pin should be connected as shown in the circuits below.
FREQOUT. E’ seguito dal numero della porta logica sul quale deve essere attivato, dalla
durata del segnale emesso espressa in millesimi di secondo e dalla frequenza con cui deve
dare il segnale di uscita.
DTMFOUT
POWER CONTROL
NAP
SLEEP
END. END puts the BASIC Stamp into its inactive, low-power mode.
PROGRAM DEBUGGING
5/5