Old example:
An example program to be debugged has the keyboard 
  monitor included at the end. This program can be downloaded and assembled without 
  modification to test the monitor. The example program under test transmits a 
  number and a constant string to the PC terminal emulator as long as RXchar='g', 
  and stops if RXchar<>'g'. Note that this use of a 'g' 
  command is not the monitor command, but the program under test. The monitor 
  does nothing until the user presses 'esc' on the PC keyboard, then 
  displays a '>' prompt. At this point any of the other monitor 
  commands may be used. Near the beginning of the program there is a short macro 
  defined which calls the UART RXdone ISR as a subroutine. This produces a software 
  interrupt to enter the monitor. The macro is shown below. 
.macro break 
    cli 
    rcall RXisr 
.endmacro
Whenever the symbol break is inserted into the program under test, 
  the monitor will be entered without a keystroke from the user. All of the monitor 
  commands can them be used. 
Note that the example program defines a interrupt vector to RXisr 
  and defines a register called RXchar to receive characters. Due 
  to the way registers are saved in the ISR, RXchar must be a register 
  below r27. The program under test might start with:
;a received character passed back from RXisr .def RXchar =r20 ;RXchar must be in a register below r27 ;The following macro calls the ISR as if it is a subroutine ;You can put it your program whenever you want to enter the ;keyboard monitor .macro break cli rcall Monitor .endmacro .cseg .org $0000 rjmp RESET ;reset entry vector reti reti reti reti reti reti reti reti rjmp RXisr ;UART receive and monitor entry reti reti reti RESET: ldi temp, LOW(RAMEND) ;setup stack pointer out SPL, temp ldi temp, HIGH(RAMEND) out SPH, temp ;setup UART -- enable RXdone int, and RX, TX pins ldi temp, 0b10011000 out UCR, temp ;set baud rate to 9600 ldi temp, 25 ;9600 baud out UBRR, temp ;the rest of the program under test ... ... ;at the end iclude the monitor .include "keymon1.inc"
An include file with just the keyboard monitor can be inserted at the end of any program unter test.