Mosaic
Well-Known Member
Code:
Brightness; S'ware PWM (uses 3 GPRs) on a 3 bit (8 step) base, LEDdrive GPR bits 0,2 are the common anodes in this case. At about a 1.37ms prg loop speed (my app. prg) 100% DC period is 11mSec or 90Hz refresh.
incf LUXCTRL,w; 100% DC timebase. GPR register
andlw .7; lower 3 bits
movwf LUXCTRL; range 0-7.
subwf LUX_setpt,w; Brightness PWM setting, GPR register. Range = 0 (12.5%) thru 7 (100%) for dimmest to brightest.
movf LEDdrive,w; buffer GPR register for common anodes avoids Read Modify Write issues.
iorlw b'00000101'; set B0 & B2 as hi by default
skpc
andlw b'11111010'; disable active common anodes if no carry.
movwf LEDport; mapped to actual pic PORT, eg #define LEDport PORTB
return