program TestD7In;
{Assumes a switch wired to D7 which
results in that line being high if
switch NOT pressed, low if pressed.
The two "if" structures are alternatives.
You can have the switch status reported
via the LCD and/or an LED on D0
DO NOT include the def_out line if your
Pascalite's d0 line is connected to
anything that will drive it high or low.}
var bTmp:byte;
begin
def_out(d0);{If you have an LED on d0}
repeat
read(portd,bTmp);
bTmp:=bTmp and 128;
if bTmp=128 then write(LCD,48) {no ; here}
else write(LCD,49);
if bTmp=128 then reset(d0) {no ; here}
else set(d0);
until 4=5;
end.
Now check that your RS-232 / Hyperterminal connection is working. See my previous RS-232 tutorial on this.
program DemoRS232;
var bTmp:byte;
begin
def_out(d0);
write(LCD,255); {clears LCD}
repeat
set(d0);{turns LED on}
read(portd,bTmp);
bTmp:=bTmp and 128;
if bTmp=0 then begin
write(LCD,"hi");
write(RS232,"From Pascalite");
write(RS232,13,10);
reset(d0);
delay(500);
end;
until 4=5;
end.
Now make the following additional setting to your Hyperterminal's Pascalite "Connection", i.e. the config file that you use when connecting to the Pascalite via Hyperterminal. In Hyperterminal, invoke...
if RS232_New_Byte then begin
read(RS232,bTmp);
write(LCD," Saw byte FROM RS232 ");
reset(d0);delay(100);{For LCD-less people}
set(d0);delay(100);
reset(d0);delay(100);
set(d0);delay(100);
reset(d0);delay(100);
set(d0);delay(100);
end;
When you run the program now, if you press a key on the PC running Hyperterminal (if you remembered to reconnect!), you should see "Saw byte from RS232 on the LCD, and some flashing on the LED.
program Demo2RS232;
var bTmp,bD7,bFrmRS232:byte;
procedure RS232CRLF;
{Do Carriage Return / Line Feed (start new line}
begin
write(RS232,10);
write(RS232,13);
end;
procedure ReportState;
{Purists would object to my access
of a global variable within this procedure}
begin
RS232CRLF;
if bD7=0 then write(RS232,"D7 is low"){no ; here}
else write(RS232,"D7 is high");
RS232CRLF;
end; {procedure}
begin {main}
def_out(d0);
RS232CRLF;
repeat
set(d0);{turns LED on}
write(LCD,255); {clears LCD}
read(portd,bTmp);
bD7:=bTmp and 128;
if bD7=0 then begin
write(LCD,"D7 is low");
reset(d0);
end {no ; here}
else write(LCD,"D7 is high");
if RS232_New_Byte then begin
read(RS232,bFrmRS232);
bTmp:=0;{Will flag if s or S sent from RS232.
0 means it was not}
if bFrmRS232=83 then bTmp:=1;{Code for "S"}
if bFrmRS232=115 then bTmp:=1;{Code for "s"}
if bTmp=1 then ReportState;
write(LCD," Saw byte from RS232 ");
reset(d0);delay(100);{For LCD-less people}
set(d0);delay(100);
reset(d0);delay(100);
set(d0);delay(100);
reset(d0);delay(100);
set(d0);delay(100);
end;
delay(300);
until 4=5;
end.
|
|