COM1_Write1CHAR

Purpose: Place one (1) BYTE, or CHAR (character) in the COM1 Transmit Buffer.
Assumes:   Interrupts are enabled.
Passed: R24  BYTE bDataByte   the data BYTE, having the value 7 through 254, to be enbuffered for transmission
Returns: R24  BYTE bDataByte same value as bDataByte passed
Alters: R25, R26, R27, R30, R31, and the FLAGs (SREG)
 

COM1_Write

Purpose: Place zero (0) to 255 BYTEs, or CHARs (characters) in the COM1 Transmit Buffer.
Assumes:   Same as COM1_Write1CHAR above, since this function calls it.
Passed: R25:R24  BYTE *   bptrBuffer   pointer to the buffer in SRAM or EEPROM or 328P FLASH to enbuffer for transmission   OR
R26:R25:R24  BYTE *   bptrBuffer   pointer to the 1284 or 2560 FLASH buffer (i.e., only when R20 = 0xFF.)
R22  BYTE bCount number of BYTEs to be enbuffered for eventual transmission.
R20  BYTE bSource data source: 0xFE selects EEPROM, 0xFF selects FLASH, any other value selects SRAM.
Returns: Nothing.
Alters: R20 through R27, R30, R31, and the FLAGs (SREG)
 
Example:  
PrintCHAR:
   PUSH    R31               ; This is the only Operating System Function which
   PUSH    R30               ;  calls COM1_Write1CHAR; all others which emit
   PUSH    R27               ;  strings use this one
   PUSH    R26
   PUSH    R25               ; Save ALL of the Registers COM1_Write1CHAR uses
   PUSH    R24
   CALL    ACOM1_Write1CHAR  ; Print the BYTE in R24
   RJMP    APrint_Common_Ret ; Jump to POP those 6 Registers and exit

Print_CommonWrite:
   PUSH    R31               ; This is the Only Operating System Function which
   PUSH    R30               ;  calls COM1_Write; all other use this one
   PUSH    R27
   PUSH    R26               ; Save MOST of the Registers which COM1_Write uses
   PUSH    R25               ;  (R20 to R23 are not saved, but may change)
   PUSH    R24               ; Print the string to which R25:R24 points, with
   CALL    ACOM1_Write       ;  R22 specifying byte count, R20 the data source

Print_Common_Ret:
   POP     R24               ; Since both routines need the same exit logic,
   POP     R25               ;  save a little codespace by doing it this way
   POP     R26
   POP     R27
   POP     R30
   POP     R31
   RET
Notes: The Operating System handles COM1 Transmit buffering as a circular FIFO queue. These are its low-level transmission character buffering System Functions.
These functions can block. In order to prevent them from blocking, the COM1 Transmit Status family of System Functions can be used to determine whether to generate output at a particular moment or wait until a later time.
Since COM1_Write uses COM1_Write1CHAR, if any BYTE value is less than 7 or equal to 255 (0xFF) in contained in the string passed to COM1_Write, that BYTE is simply skipped.
The PrintCHAR System Function, and all of the others which use it, including Print0xPrefix, PrintBINARY, the PrintBYTE family, PrintNewLine, the PrintSpace family, and the Print Space and CHAR family, all use the COM1_Write1CHAR System Function to perform their tasks.
PrintCHAR PUSHes all of the Registers which COM1_Write1CHAR uses, thereby providing more convenient "wrapper" functionality around COM1_Write1CHAR. Strongly consider using the print functions rather than using these two functions directly, unless there is some overriding reason to use them. Consider that all the print functions can block, and that when generating serial output, only about one character per millisecond is being output when using the 9,600 BPS COM rate, for example.
The Print*ASCIIz family and Print*String family, et al., call the COM1_Write System Function and provide the "wrapper" around COM1_Write, handling the saving of Registers which it uses.
Its *bHead (SRAM address 0x180) is the LSByte of the address of the next available position in the queue.
Its *bTail (SRAM address 0x181) is the LSByte of the address of the first (oldest) BYTE in the queue.
Dropin: 
(setup
code)
;   Setup for the COM1_Write1CHAR() call:
; Passed:  R24 BYTE bDataByte
; Returns: R24 BYTE bDataBYTE
; Alters:  R25, R26, R27, R30, R31, and the FLAGs

;   Setup for the COM1_Write() call:
; Passed:      R25:R24 BYTE * bPtrBuffer (all RAM or EEPROM and all 328P)  OR
;          R26:R25:R24 BYTE * bPtrBuffer (only for FLASH in 1284 or 2560)
;                  R22 BYTE   bCount  number of BYTEs to enbuffer (0 is valid)
;                  R20 BYTE   bSource 0xFE = EEPROM, 0xFF = FLASH, any other = SRAM
; Returns: Nothing.
; Alters:  R20 through R27, R30, R31, and the FLAGs
Also see:  The COM1 Receive Buffer status family of System Functions.