Originally used in an 8051 based laser tag system although easily cross assembled into AVR assembler. No need for interrupts or timers, just simple timing loops.
Here is part of the original code:-
LOOP1: JB TXD,LOOP1 TXD2LO: SETB TXD3 ;turn on I/R modulation JB TXD,TXD2HI ;delay ~13uS JB TXD,TXD2HI ;and check if Txd goes high JB TXD,TXD2HI ;and exit if it does JB TXD,TXD2HI JB TXD,TXD2HI JB TXD,TXD2HI TXD2HI: CLR TXD3 ;Txd went high,I/R mod off. NOP ;38K timing balance JB TXD,LOOP1 ;exit if Txd goes low JB TXD,LOOP1 ;delay ~13uS JB TXD,LOOP1 JB TXD,LOOP1 JB TXD,LOOP1 AJMP TXD2LO ;Txd still low, repeat 38K
Called immediately after sending a byte to the UART.
You will need to detect transmit buffer empty(UDRE) in LOOP1 and execute a RET.
Use PINx to test the state of the Txd pin ( JB TXD)
Txd is the UART transmit pin and TXD3 is the port bit that drives an N channel FET, driving an I/R diode with series resistor to Vcc/Vbatt.
Works at baud rates up to 1600 or so.
Keep the overall timing loop to 25-26uS for 38KHz modulation.