the use of ASCII, which requires each program data byte
to be expressed as two hex characters. This demands
that nearly twice as many bytes be transferred as might
otherwise be required. This is not a severe limitation, how-
ever, since typical file transfer times are less than one
minute. Overall, the simplicity of the custom FTP/hex
packet format implementation outweighs the drawbacks.
Remote Station
The remote station in the test configuration consists of the
display application and programmer circuits, described
previously, connected to a Hayes-compatible,
Prometheus 1200 baud modem. During normal operation,
the application executes its internal program while the mo-
dem and programmer monitor the phone line for incoming
calls.
After a call has been detected and a connection estab-
lished, the programmer forces the application to suspend
execution of its program. The new program is then down-
loaded and programmed into the AT89C51 embedded in
the application. When programming is complete, the ap-
plication is allowed to begin execution of its new program,
and the programmer returns to monitoring the phone line
for the next call.
The programmer powers up with its programming control
outputs inactive, allowing the application to run normally.
After configuring the modem to answer incoming calls, the
programmer puts itself to sleep. The programmer will not
disturb the application until a new program is to be down-
loaded.
The programmer controls the modem by sending ASCII
command strings over the serial interface, to which the
modem responds with Hayes-style ASCII numeric codes.
The software is designed for use with Hayes-compatible
modems, which includes the Prometheus ProModem
1200 used here.
The serial interface, through which the programmer con-
nects to the modem, supports two handshaking signals,
DTR and DSR. On power up, the programmer asserts
DTR, to which the modem responds by asserting DSR. If
the modem should fail to respond to any command, in-
cluding the command to hang up, the programmer deas-
serts DTR, which forces the modem to drop the line.
The modem monitors the phone line while the program-
mer sleeps, waiting for an incoming call. When a call is
detected, the modem answers and attempts to establish
communication with the caller. If a connection is estab-
lished, the modem sends a code to the programmer, wak-
ing it up. The programmer verifies the connect code and
begins polling for a valid packet header.
Incoming packets must arrive fewer than thirty seconds
apart, or the modem drops the line (hangs up) and the
programmer returns to sleep, waiting for the next call. If
the caller hangs up, the thirty second period must expire
before another call will be answered. Calls incoming dur-
ing the reset delay period are ignored.
If a valid packet header is received prior to the expiration
of the reset delay period, the programmer will attempt to
read and validate the incoming packet. At any time during
packet reception, an invalid character, parity error or time-
out during character reception will cause the partial
packet to be declared invalid and discarded.
Two packet types are defined: data and end-of-file. A data
packet contains five fields in addition to the packet
header, one of which is a variable length data field. The
data field contains program data to be written into the
AT89C51 controller in the application. The load address
field contains the address at which the data is to be writ-
ten. The end-of-file packet contains the same fields as the
data packet, except that the data field is empty. This
packet type has special meaning to the programmer, as
explained below.
Any packet which contains an invalid record type, record
length or checksum is invalid. Program data accumulated
during the processing of an invalid packet is discarded.
The programmer sends a NAK to the transmitter to signal
reception of an invalid packet and resumes polling for a
valid packet header.
Receipt of the first valid data packet causes the program-
mer to interrupt the application controller. The controller
responds to the interrupt by abandoning execution of its
usual program and displaying a message indicating that
programming is taking place. If this is the first valid data
packet since power was applied or an end-of-file packet
was received, the programmer asserts the control signals
necessary to erase the program memory in the applica-
tion controller. The programmer then places the controller
in programming mode.
The first and subsequent valid data packets are dissected
as they are received and the data which they contain is
programmed into the application controller at the address
indicated in the packet load address field. After program-
ming, the data is read back from the controller and verified
against the received packet data. Successful verification
indicates that programming was successful, causing the
programmer to send ACK to the transmitter. The program-
mer then resumes polling for a valid packet header, sub-
ject to the thirty second reset delay.
If programming fails, the programmer sends CAN to sig-
nal the transmitter to abort the file transfer. The modem
drops the line and the programmer returns to sleep, wait-
ing for the next call. The application controller is left in pro-
gramming mode, preventing it from executing the incom-
plete or invalid program which it contains.
4-12
Microcontroller