$include (C8051F410.INC) DSEG at 020h i: DS 1 ; running index, 0..255 n: DS 1 ; duty cycle parameter, n/256 dn: DS 1 ; step of changing the duty cycle parameter LED EQU P0.2 CSEG at 0000h jmp Main ORG 000Bh jmp Timer0IRQ ORG 002Bh jmp Timer2IRQ Timer0IRQ: ; Timer 2 interrupt routine push acc ; save accumulator push psw ; save program status word clr TF0 ; clear overflow flag mov TH0,#0B0h ; repeat time = 65536-(TH0*256+TL0)/(sysclk/12) mov TL0,#040h ; mov a,n ; n=n+dn add a,dn ; mov n,a ; pop psw ; restore program status word pop acc ; restore accumulator reti Timer2IRQ: ; Timer 2 interrupt routine push acc ; save accumulator push psw ; save program status word mov TMR2CN,#04h ; clear interrupt flag inc i ; increment variable mov a,n ; clr c ; clear carry flag subb a,i ; calculate n-i mov LED,c ; c=1, if n