

Resolution	equ	8				;Desired resolution (in steps - not bits!)
			
PWMMaster:	ds	1				;Continuous master counter
			
PWMArray:	ds	8					;Settings
PWMCounters:	ds	8				;Channel counters
			
timerisr:		djnz	PWMMaster,noreset			;Bump master counter, don't jump if zero
			
		mov	PWMMaster,#Resolution		;Reset master counter
		mov	PWMCounters + 0,PWMArray + 0	;Copy settings to channel counters
		mov	PWMCounters + 1,PWMArray + 1	
		mov	PWMCounters + 2,PWMArray + 2	
		mov	PWMCounters + 3,PWMArray + 3	
		mov	PWMCounters + 4,PWMArray + 4	
		mov	PWMCounters + 5,PWMArray + 5	
		mov	PWMCounters + 6,PWMArray + 6	
		mov	PWMCounters + 7,PWMArray + 7	
		mov	p1,#0ffh				;All port pins high
			
		reti		;Done
			
noreset:		djnz	PWMCounters + 0,$+2		;Bump channel 0 counter
		clr	p1.0				;Reset port pin when it crosses zero
			
		dec	PWMCounters + 1,$+2	
		clr	p1.1	
			
		dec	PWMCounters + 2,$+2	
		clr	p1.2	
			
		dec	PWMCounters + 3,$+2	
		clr	p1.3	
			
		dec	PWMCounters + 4,$+2	
		clr	p1.4	
			
		dec	PWMCounters + 5,$+2	
		clr	p1.5	
			
		dec	PWMCounters + 6,$+2	
		clr	p1.6	
			
		dec	PWMCounters + 7,$+2	
		clr	p1.7	
			
		reti		

