<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 01 Oct 1985 14:14:36 EDT
From   : David Towson (SECAD) <towson@AMSAA.ARPA>
Subject: 7000+ character tutorial on sending BREAK:

Fellow CP/Mers - In response to a recent request for information regarding
how to send BREAK from a microcomputer, here is a 7000+ character tutorial on
the subject.  Sample code is included.

     The American Standard Code for Information Interchange (ASCII) defines a
set of 128 characters that are encoded as the various combinations of seven
bits.  When this code is used over a serial asynchronous communications link,
some additional bits are added to the seven ASCII bits to form the total
"package" that is transmitted for each character sent.

     The term "asynchronous" means that the receiver doesn't know in advance
when a character is coming.  It just sits in an "idle" state until some special
event signals the start of a new character.  This idle state is caused by the
presence of a steady logic-one signal at the receiver input, and it can last
indefinitely.  The "special event" that signals the beginning of a new
character is a transition from the idle-state logic-one signal to a logic-zero
which lasts for one bit-time, and is known as a "start-bit".

     A start-bit "wakes-up" the receiver, which then records in some sort of
memory, typically a shift-register, the states of the next seven or eight bits.
Whether seven or eight bits are recorded depends on whether "parity" is being
used.  Parity is a simple error detection scheme that, though easily deceived,
is better than nothing.  It is implemented by adding an extra bit (the eighth
bit) to the existing seven ASCII bits such that the total number of logic-one
bits in the eight-bit group is either odd or even, depending on whether "odd
parity" or "even parity" is being used.  For example, the ASCII representation
for "A" is "1000001", which has an even number of 1's.  Therefore, adding even
parity results in "01000001", which still has an even number of 1's, whereas
the odd parity representation is "11000001".

     After the start-bit and seven or eight "data-bits", the receiver expects
to see a return to the logic-one state to signify the end of the character.
This logic-one state lasts for at least one bit-time, and is known as a
"stop-bit" (or bits).  Typically, one stop-bit is used for all speeds greater
than 110 baud, and two stop-bits are used at 110 baud and below.  This
convention derives from the mechanical roots of teleprinting, where the
electro-mechanical devices used to decode and print the received characters
needed time to stop quivering after each character before being ready to decode
and print the next.

     To summarize then, an ASCII character sent via an asynchronous serial
channel consists of one start-bit, seven or eight data-bits (depending on
whether parity is being used), and one or two stop-bits (depending on the
speed of transmission).  This brings us (at last) to the BREAK signal.

     The BREAK signal has its roots at least as far back as the days of
mechanical teleprinters, perhaps all the way back to electro-mechanical
telegraphy.  Early teleprinters used an electro-mechanical device called a
"selector" to perform the decoding function now done electronically by devices
such as the Universal Asynchronous Receiver Transmitter (UART).  The start-bit
caused a current flowing in the selector electro-magnet to cease, thereby
releasing a clutch that set into motion a complex mechanical process that
resulted in the printing of the received character.  This process made a
considerable noise, even when a non-printing character such as a space was
received.  If a steady logic-zero signal (no current in the selector magnet)
was presented to the receiving teleprinter, the machine emitted a steady
rhythmic clunking that was impossible to ignore.  Consequently, the machines
had a key labeled BREAK that merely opened the series DC circuit connecting
all transmitters and receivers in the teleprinter network, thereby getting the
attention of all operators.  There was also a BELL character, but this had to
be correctly decoded by a receiver in order to ring the bell, whereas the
BREAK was a "non-character" that could be used to interrupt a transmission-
in-progress, since it simply disrupted the whole network and made a lot of
noise at each receiving teleprinter.

     Today, the BREAK signal performs a similar function in a similar manner.
It is used now most often to gain the attention of a computer or other
machine, rather than to alert a human operator.  But it is still generated by
sending a logic-zero signal of indeterminate length, although by convention
some specific durations (typically in the 300 - 500 millisecond range) have
been adopted.  Modern electronic receiving circuits such as those whose names
end with "ART" (as in UART) interpret the beginning of the BREAK as a start-bit
followed by seven or eight logic-zero data-bits (the ASCII NUL character).  But
the expected stop-bit (return to logic-one state) is missing.  This causes the
receiving circuit to generate an error condition called "framing error", which
is typically signaled by the setting of an error-bit in the status register
of the receiving device.  How the "user machine" responds to this condition is
determined by the user-machine's software.

     The example to follow shows how a BREAK can be sent via software control
of a 1602 UART.  This device, which is typical of many such devices, has a
command instruction that forces the output to a logic-zero state until the
complementary instruction is issued.  The code is taken from my MODEM7 overlay
for the TRS-80 Model-I computer.  All code not needed for this specific
example has been deleted.

;.....
;
RESETP:                EQU     0E8H    ;Reset port for UART.
BAUDP:         EQU     0E9H    ;Data-rate port for UART.
CONTROLP:      EQU     0EAH    ;Status/control port for UART.
BRKMASK:       EQU     0FBH    ;And-mask to turn on break.
;
;.....
;
;
; UART initialization routine for TRS-80 Model I.
;
TRSINIT:       OUT     RESETP          ;Reset UART (data in A register is
                                       ;insignificant).
               MVI     A,55H           ;Use 55H for 300 baud.
                                       ;Use 77H for 1200 baud.
               OUT     BAUDP           ;Set UART data-rate.
;
               MVI     A,0ECH          ;Set UART for 8-bit word,
                                       ;no parity, no break and
               OUT     CONTROLP        ;DTR and RTS on.
               STA     CONTROLB        ;Save the UART control byte.
               RET                     ;
;
;
;.....
;
;
CONTROLB:      DB      0               ;UART control byte save.
;
;
;.....
;
;
; Routine to send a break-tone of approximately 300 ms duration.
;
SENDBRK:       PUSH    B               ;Save all double registers.
               PUSH    D               ;
               PUSH    H               ;
               LDA     CONTROLB        ;Get current UART control byte.
               ANI     BRKMASK         ;Change bit to turn on break.           
               OUT     CONTROLP        ;Send new byte to control port.
               MVI     B,3             ;Set count for timer.
               CALL    TIMER           ;Wait 300 milliseconds.         
               LDA     CONTROLB        ;Restore original control byte          
               OUT     CONTROLP        ;to turn off break.
               POP     H               ;Restore double registers.
               POP     D               ;
               POP     B               ;
               RET                     ;
;
;
;.....


Note that the particular control-bytes needed to program the 1602 UART were
determined from the 1602 data sheet.  It is pointless to attempt writing this
kind of code unless you have access to this kind of information.  Many readers
of info-cpm can help in this regard.

     Many other examples can be found in the overlay files on SIMTEL20 in
directories PD:<CPM.MODEM7> and PD:<CPM.MEX>, available via FTP with login
username "anonymous" and password "ftp" (or any other printing string).



                                               Dave
                                               <towson@amsaa.arpa>
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>