
 CPU 8051
 INCLUDE stddef51

PWM_OFFVALUE    EQU   10
PWM_ONVALUE     EQU   11
PWM_COUNT       EQU   12
PWM_OUT         EQU P3.0

 SEGMENT code

 ORG 0h

        jmp start

; Interruptbehandlungsroutine Timer 0
; Jeder Durchlauf braucht 9 Zyklen

 ORG 0Bh

        djnz PWM_COUNT, pwm_exit
        jb PWM_OUT, pwm_on

pwm_off:

        mov PWM_COUNT, PWM_ONVALUE
        setb PWM_OUT
        reti
pwm_on:        

        mov PWM_COUNT, PWM_OFFVALUE
        clr PWM_OUT

pwm_exit:

        reti

; Initialisierung

start:

        mov TL0, #235
        mov TH0, #235
        mov SP,  #20h
        mov TMOD,#2
        mov TCON,#16
        mov IE,  #130

; Hauptprogramm
main:

        ; quick 'n dirty Parameter als Test von P1 holen
        mov a,P1
        subb a,#20
        mov PWM_ONVALUE, a
        subb a,#255
        mov PWM_OFFVALUE, a
        jmp main
END

---------------------------------------------------------------
