
PWMPos  EQU R7
PrePWM  EQU R5
PosPWM  EQU R6
PanPWM  EQU 76H

ORG 0000H               ;RESET VECTOR
        SJMP CONFIG

ORG 000BH               ;TIMER ZERO OVERFLOW
        CJNE PrePWM,#0,T0IEndDecPre ;if not zero do 800 before pwm
        CJNE PosPWM,#0,T0IEndDecPos ;if not zero do 20ms after pwm
        ;if both zero time to PWM positioning
        
        DEC PWMPos
        MOV A,PWMPos
        CJNE A,PanPWM,$+3
        MOV P2.0,C                  ;Set output to servo
        
        CJNE PWMPos,#0,T0IEnd       ;check for PWM end, prepare for post PWM
        MOV PosPWM,#??              ;here should set to wait the post 20ms

T0IEndDecPre:
        DEC PrePWM
        JMP T0IEnd

T0IEndDecPos:
        DEC PosPWM
        
T0IEnd: 
        CLR T0
        RETI

CONFIG:
        MOV TMOD,#00000010B ;T0 autoreload
        MOV TH0,#12          ;Reload Value
        MOV TL0,#12
        
        SETB EA
        SETB ET0
