$mod652
org 0h
ljmp init

org 23h

PUSH PSW
PUSH ACC

JNB RI,$
MOV A,S0BUF
MOV TON,A
CLR RI

POP ACC
POP PSW

reti

org 100h
;------------------
init:

SETB ES0 ; enable serial interrupt
MOV S0CON,#50H ; SET TO SERIAL MODE1
MOV TMOD,#20H ; SET TIMER 1 TO MODE 2 (8 BIT AUTO RELAOD)
MOV TH1,#253 ;SET BAUD TO 9600
SETB TR1
SETB EA

ton equ r1 ;on time 
toff equ r2 ; off time
mov ton, #080h ; manually set on time to 080h (50%)
jmp loop
;------------------

;------------------
loop:
call makeon
setb p2.0
call delayon
clr p2.0
call makeon
call delayoff
jmp loop
;------------------

;------------------
makeon:

clr c ; clear carry bit for subtraction operation
mov a,#0FFh
subb a,ton ;subtract ton from acc (255) therefore giving us the value of toff
mov toff,a ;load up toff with the result of the subb
ret
;------------------


;------------------
delayon: ;this function loads acc with the value of ton then decrements till its zero and returns
mov a,ton 
delayona:
dec a
jnz delayona
ret
;------------------

;------------------
delayoff: ;this function loads acc with the value of ton then decrements till its zero and returns
mov a,toff
delayoffa:
dec a
jnz delayoffa
ret
;------------------


end