Since HPWM cant operate in 3 channels and it has to be configured manually, I was wondering if someone could help me incorporate it into my code correctly? Theres quite a bit of stuff going on in that code and I dont want it placed inproperly in my script.
my script:
[html]
TRISB = %10000000 'portb 7 input 6-0 output
ADCON1 = %11111111 'all ports digital
define OSC 4 '4mhz oscillator
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0)
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 6 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us
DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit
DEFINE CCP3_REG PORTB 'Hpwm 3 pin port
DEFINE CCP3_BIT 5 'Hpwm 3 pin bit
B0 Var Byte 'up button
B1 var byte 'down button
B2 var byte 'select button
B3 var byte 'daylight button
B4 Var byte 'tungsten
B9 var byte 'lock button
B10 var byte 'power button
rval var byte 'red
gval var byte 'green
bval var byte 'blue
lcdrval var byte 'red lcd value
lcdgval var byte 'green lcd value
lcdbval var byte 'blue lcd value
rval = 255 'red at 255
gval = 255 'green at 255
bval = 255 'blue at 255
B0 = 0 'zero button up
B1 = 0 'zero button down
B2 = 0 'zero select button
B3 = 0 'zero daylight button
B4 = 0 'zero tungsten button
B9 = 0 'zero lock button
B10 = 0 'zero power button
while portc.6 = 0 'power button
wend
main:
high portc.4 'power indicator
pause 500 '.5 second delay
LCDOUT $FE, 1, "LEADS ", $FE, $C0, "by MSL" 'tag line
pause 1000 '1 second delay
home:
lcdrval = ~rval 'invert red for display
lcdgval = ~gval 'invert green for display
lcdbval = ~bval 'invert blue for display
lcdout $fe, 1, " R", DEC3 lcdrval, " G", $FE, $C0, DEC3 lcdgval, " B", DEC3 lcdbval
hpwm 1, rval, 5000 'set red dim level
hpwm 2, gval, 5000 'set red dim level
hpwm 3, bval, 5000 'set red dim level
bru:
BUTTON porta.0,1,100,1,B0,0,brd 'detect + button
pause 20
goto brup
brd:
button porta.1,1,100,1,B1,0,ld 'detect - button
pause 20
goto brdown
ld:
button portc.7,1,255,0,B9,0,pd 'detect lock button
pause 20
goto lock
pd:
button portc.6,1,255,0,B10,0,dd 'detect power button
pause 20
goto power
dd:
button portc.5,1,255,0,B3,0,td 'detect daylight button
pause 20
goto daylight
td:
button portc.4,1,255,0,B4,0,sd 'detect tungsten button
pause 20
goto tungsten
sd:
button portb.7,1,255,0,B2,0,bru 'detect select button
pause 20
'if portb.7 = 1 then
goto adjr
'else
'goto bru
'endif
brup: 'brightness up
rval = rval + 1
gval = gval + 1
bval = bval + 1
hpwm 1, rval, 5000 'set red dim level
hpwm 2, gval, 5000 'set green dim level
hpwm 3, bval, 5000 'set blue dim level
pause 100
goto home
brdown: 'brightness down
rval = rval - 1
gval = gval - 1
bval = bval - 1
hpwm 1, rval, 5000 'set red dim level
hpwm 2, gval, 5000 'set green dim level
hpwm 3, bval, 5000 'set blue dim level
pause 100
goto home
adjr: 'adjust red level
lcdrval = ~rval 'invert red for display
lcdout $fe, 1, "Red", $FE, $C0, DEC3 lcdrval 'display red level
ru: 'check up button
BUTTON porta.0,1,100,1,B0,0,rd ' Check button
pause 20
goto rup
rd: 'check up button
button porta.1,1,100,1,B1,0,sd2
pause 20
goto rdown
sd2: 'check for select button
button portb.7,1,255,0,B2,0,ru
pause 20
goto adjg 'goto adjust green
rup: 'red up
rval = rval + 1
hpwm 1, rval, 5000
pause 100
goto adjr
rdown: 'red down
rval = rval - 1
hpwm 1, rval, 5000
pause 100
goto adjr
adjg: 'adjust green
lcdgval = ~gval 'invert green for display
lcdout $fe, 1, "Green", $FE, $C0, DEC3 lcdgval 'display green level
gu: 'check up button
BUTTON porta.0,1,100,1,B0,0,gd ' Check button
pause 20
goto gup
gd: 'check down button
button porta.1,1,100,1,B1,0,sd3
pause 20
goto gdown
sd3: 'check select button
button portb.7,1,255,0,B2,0,gu
pause 20
goto adjb 'goto adjust blue
gup: 'green up
gval = gval + 1
hpwm 2, gval, 5000
pause 100
goto adjg
gdown: 'green down
gval = gval - 1
hpwm 2, gval, 5000
pause 100
goto adjg
adjb: 'adjust blue
lcdbval = ~bval 'invert blue for display
lcdout $fe, 1, "Blue", $FE, $C0, DEC3 lcdbval 'display green level
bu: 'check up button
BUTTON porta.0,1,100,1,B0,0,bd ' Check button
pause 20
goto bup
bd: 'check down button
button porta.1,1,100,1,B1,0,sd4
pause 20
goto bdown
sd4: 'check select button
button portb.7,1,255,0,B2,0,bu
pause 20
goto home 'goto home
bup: 'blue up
bval = bval + 1
hpwm 3, bval, 5000
pause 100
goto adjb
bdown: 'blue down
bval = bval - 1
hpwm 3, bval, 5000
pause 100
goto adjb
lock: 'lock the keys
high portc.3 'lock indicator
pause 1000
while portc.7 = 0 'wait for unlock
wend
low portc.3 'lock indicator
goto home
power: 'power down display and LEDs
low portc.4 'take down power indicator
hpwm 1, 0, 5000 'take down red channel
hpwm 2, 0, 5000 'take down green channel
hpwm 3, 0, 5000 'take down blue channel
lcdout $fe, 1 'clear display
pause 1000
while portc.6 = 0 'wait for power on
wend
high portc.4 'put up power indicator
goto home
daylight: 'set color levels to approx 5600k
rval = 255
gval = 255
bval = 252
goto home
tungsten: 'set color levesl to approx 3200k
rval = 255
gval = 241
bval = 224
goto home
end
[/html]
Bookmarks