After some tweaking I have this pretty much working now. I can get it to ramp up slowly to full brightness, maintain a set level, be adjusted up and down, have the new value write to EEPROM and next time it is powered up it will ramp up to the last saved level. All I want to add now is ramp down at power off. Not a problem.
I'd like to reduce code size though. I have a lot of IF THEN's and a lot of FOR NEXT's. They are used to increment and decrement a byte value based on which level output is set.
This is the ramp up routine that seems to work well. The ramp down is similar. Any way to reduce this block of code in size?Code:rampup:l = 0 for l = 0 to led if L = 0 then fb = 0 CCP1CON = 0 ramp = 0 portc.2 = 0 endif IF L = 1 then fb = 10 endif if L = 2 then fb = 45 endif if L = 3 then pause 25 fb = 90 endif if L = 4 then pause 40 fb = 130 endif IF L = 5 then pause 50 fb = 170 endif if L = 6 then pause 75 fb = 280 endif if L = 7 then pause 100 fb = 450 endif adcin 1, temp If temp > fb and L > 0 then ramp = ramp - 1 IF ramp <= 0 then CCP1CON = 0 ramp = 0 portc.2 = 0 endif endif If temp < fb Then ramp = ramp + 1 If ramp >= 40 then ramp = 40 endif endif If ramp > 41 then ramp = 0 endif CCP1CON = 111100 PR2 = 44 high_duty=(ramp>>2) 'high 6 bits in CCPR1L low_duty=(ramp<<6) 'low two bits for CCP1CON low_duty=(low_duty>>2) 'shift back to CCP1CON<5:4> low_duty.3=1 'PWM configuration bit low_duty.2=1 'PWM configuration bit CCPR1L=high_duty CCP1CON = $0C T2CON = 4 pause 100 next l goto main




Bookmarks