
// bit banging to transmit at 1200 baud rate
// crystal freq is 11.0592MHz
DAT equ R2

		
	org 00h
	jmp main
; timer 0 interrupts here
	org 0Bh
T0int:	rrc A
	mov P3^1,C
	inc R1
	reti
; main routine
	org 100h
main:	setb P3^1
	mov IE,#82h		; timer 0 interrupt enable
	mov TH0,#0E8h 	  	; timer 0 mode 2 is enabled here
	mov TL0,#0E8h		; at 1200 baud rate
	mov TMOD,#02h		;

	mov R0,#100		; transmit a character 100 times
	mov DAT,#'U'		
repeat:	call byte_out				
	djnz R0,repeat
		
over:	jmp over

; routine to send out a byte
byte_out:
	setb TR0		; start timer
	mov A,#0x00	 	; send start bit
	mov R1,#00
wait1: 	cjne R1,#01,wait1	; wait till 1 bit is sent

	mov R1,#0			
	mov A,DAT		; send the character
wait2: 	cjne R1,#8,wait2	; wait till 8 bits is sent

	mov A,#0x01		; send stop bit
	mov R1,#00
wait3: 	cjne R1,#01,wait3	; wait till 1 bit is sent
	clr TR0
	ret
end