If serial I/O is only used for program upload, shell script operation may be
the most convenient way of testing with the shortest turn-around cycles.
The sample script file below, shows the principles of operating
#!/bin/sh
stty 9600 sane clocal -crtscts -hupcl </dev/ttyS1 # until stty 1.16
# stty -F /dev/ttyS1 9600 sane clocal -crtscts -hupcl # stty 2.0 or later
reset51 /dev/lp0
sleep 1
asem $1.a51
echo “U” >/dev/ttyS1
cp $1.hex /dev/ttyS1
echo “G 8000” >/dev/ttyS1
In this example, serial I/O is done over serial port /dev/ttyS1,
and the target system can be reset over printer port /dev/lp0.
First of all, the serial port /dev/ttyS1 is initialized to the desired
baudrate of 9600 Baud,
Then the reset51 program provided is executed to reset the target
system via printer port /dev/lp0. After that, the sleep command
waits until
Now
When finished, the
Finally the application program is started at address 8000H with the
command
To test an application program
test51 myprog
at the shell prompt, and see what you get.
Of course this was only a minimized example! In general you will not only
have to modify serial port, baudrate, reset port, and start address for
your local requirements, but also to do something for plausibility checking
and error handling.
For this, the more sophisticated script file boot has been provided.
It allows an easy change of all configuration parameters with any ASCII
editor. For further information see the commentary inside boot.
In principle, boot contains only those configuration data!
(The actual work is done by another script upload provided, which is
invoked by boot. If your stty command is version 2.0 or later,
better use the script file upload.new instead!)
A program
boot myprog
To get the boot script running, ensure that you have full read/write
access to the serial port used as upload device!
If a printer port is employed as reset device, the reset51 program
requires root privileges! (see below)
Finally, the reset51 program provided, may be worth a detailed explanation: When invoked, reset51 forms a reset pulse of the duration <pulsewidth> at the D0 and D1 outputs of a PC printer <port>, or at the DTR output of a serial <port>:
reset51 /dev/<port> [<pulsewidth>]
<
Legal <port> values are: | lp0, lp1, lp2, ttyS0, ttyS1, ttyS2, ttyS3, cua0, cua1, cua2, cua3, null |
Under Linux with kernels
From kernel
reset51 can only handle the four standard PC serial ports ttyS0 thru ttyS3.
(However, the boot script described above should also work with non-standard
serial ports, because it operates them with the stty command only!)
The serial ports ttyS0 and cua0 are equivalent, and so are ttyS1 and cua1,
and so on.
If /dev/null is specified as <port>, reset51 delays only
for <pulsewidth> ms.
The optional parameter <pulsewidth> is the duration of the reset pulse in ms.
Legal values are:
1 <= <pulsewidth> <= 65535.
(default is 50)
When invoked without parameters, a help screen is displayed.
In case of error, reset51 returns the exit code 1, 0 otherwise.
When executed, reset51 forms a positive pulse at D0
If the default pulse width of
Since reset51 needs direct access to I/O ports, it requires root privileges!
To make it available for all users, set the owner to “root” and set the
chown root reset51
chmod u+s reset51
For shell script operation, a reset line is highly recommended! If you don't have it, you will always have to press the reset button of the target system, before invoking the boot script. Since this may easily be forgotten, it is better to automate this step.