I have a number of buttons in my program, all are working except for the select button (SD). I have tried hooking the button to a different port with the same problem, I have swapped the button with others and the button itself works. So I am assuming its in the code somewhere.

Im sure there are inefficiencies in the code, let me know if there are really bad ones.

thanks

p.s. I know I havent coded in the 2nd and 3rd hpwm lines yet, I only have 1 color LED hooked up to the board so far.


TRISB = %00000000 'portb 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 1 pin port
DEFINE CCP2_BIT 1 'Hpwm 1 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

rval = 0 'red at 0
gval = 0 'green at 0
bval = 0 'blue at 0
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:
lcdout $fe, 1, " R", DEC3 rval, " G", $FE, $C0, DEC3 gval, " B", DEC3 bval
hpwm 1, rval, 5000 'set dim level

sd:
button portb.7,1,255,0,B2,0,bru 'detect select button
pause 20
goto adjr
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,bru 'detect tungsten button
pause 20
goto tungsten

brup: 'brightness up
rval = rval + 1
gval = gval + 1
bval = bval + 1
hpwm 1, rval, 5000
pause 100
goto home
brdown: 'brightness down
rval = rval - 1
gval = gval - 1
bval = bval - 1
hpwm 1, rval, 5000
pause 100
goto home

adjr: 'adjust red level
lcdout $fe, 1, "Red", $FE, $C0, DEC3 rval '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,100,1,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
lcdout $fe, 1, "Green", $FE, $C0, DEC3 gval '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,100,1,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
lcdout $fe, 1, "Blue", $FE, $C0, DEC3 bval '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,100,1,B2,0,bu
pause 20
goto home 'goto home
bup: 'blue up
bval = bval + 1
hpwm 1, bval, 5000
pause 100
goto adjb
bdown: 'blue down
bval = bval - 1
hpwm 1, 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
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