OK, well now that you already have it working ... 
I finally got mine working too.
This one doesn't use interrupts, and is essentially the example I gave in post#3, expanded to meet the other requirements.
May not be any help to you, but it might give some more ideas.
View Highlighted code
Code:
CLEAR
INCLUDE "AllDigital.pbp" ; Disable Analog functions
DEFINE OSC 8
OSCCON = %01110001
SW1 VAR PORTB.0
SW2 VAR PORTB.1
SW3 VAR PORTB.2
SW4 VAR PORTB.3
SW5 VAR PORTB.4
SW6 VAR PORTB.5
LED1 VAR PORTC.0
LED2 VAR PORTC.1
LED3 VAR PORTC.2
LED4 VAR PORTC.3
LED5 VAR PORTC.4
LED6 VAR PORTC.5
PZ VAR PORTC.6 ; piezo (beep)
TR1 VAR PORTA.0
TR2 VAR PORTA.1
TR3 VAR PORTA.2
TR4 VAR PORTA.3
TR5 VAR PORTA.4
TR6 VAR PORTA.5
;---[Adjustable delay times]------------------------------------------------
DebounceTime CON 25 ; (ms) button debounce time
ChargeDelay CON 10000 ; (ms) delay before it starts charging
ProgDelay CON 5000 ; (ms) time to hold button for program mode
ProgHold CON 3000 ; (ms) of inactivity to end Program Mode
MaxCharge CON 12 ; (hours) Maximum Charge Time [MAX 18]
;---------------------------------------------------------------------------
Counters VAR WORD[6] ; 6 words, for 6 buttons
ProgCounter VAR WORD[6] ; counts buttom time to enter Program Mode
Debounce VAR BYTE[6] ; debounce counters
ChargeTime VAR BYTE[6] ; counts charging time (hours) in Prog mode
ChannelStates VAR BYTE[6] ; Channel state flags
ChannelState VAR BYTE
LastState VAR ChannelState.0 ; state of SW pin during last loop
Pressed VAR ChannelState.1 ; Button has been pressed
ProgramMode VAR ChannelState.2 ; indicates currently in program mode
ChargeMode VAR ChannelState.3 ; indicates currently in charge mode
T0IF VAR INTCON.2 ; TMR0 overflow flag
I VAR BYTE ; general use in for next
X VAR BYTE
TempW VAR BYTE
OneSecond VAR WORD
SecondsChanged VAR BIT
PinState VAR BIT
OneSecond = 1000
OPTION_REG = %01010100 ; WPUon, TMR0 1:32 prescaler, internal clk
DATA @0, 3, 3, 3, 3, 3, 3 ; set default Charge Time to 3 hours
sound pz,[123,10] ; beep on power-up
;----[Main Loop]------------------------------------------------------------
Main:
WHILE !T0IF : WEND ; wait for timer to overflow
TMR0 = 193 ; load timer for 1ms
T0IF = 0 ; reset the overflow flag
OneSecond = OneSecond - 1 ; count off 1 second intervals
IF OneSecond = 0 THEN ; for charge timers
OneSecond = 1000
SecondsChanged = 1
ENDIF
;-----------------------------------
FOR X = 0 to 5 ; cycle thru Channels
ChannelState = ChannelStates(X) ; get this channels state flags
GOSUB GetSWState ; get the current state of the SW
IF PinState != LastState THEN ; debounce the pin
LastState = PinState
Debounce(X) = DebounceTime
ENDIF
IF Debounce(X) > 0 THEN ; If debouncing
Debounce(X) = Debounce(X) - 1 ; decrement the counter
IF Debounce(X) = 0 THEN ; when it gets to 0
Pressed = !PinState ; button is stable, get the state
IF Pressed THEN ;==== Button Pressed Event =========
IF ChargeMode THEN ; If we're in charge mode
ChargeMode = 0 ; cancel charge mode
Counters(X) = 0 ; clear the counter
GOSUB TriacOFF ; turn off the triac
ELSE
IF ProgramMode THEN ;---- Program Mode------------------
IF ChargeTime(X) < MaxCharge THEN ; limit to Max charge time
Counters(X) = ProgHold ; reset Prog mode Timeout
ChargeTime(X) = ChargeTime(X) + 1 ; increment # of hours
GOSUB Beep ; beep on each button press
ELSE ; If Max has been reached
sound pz,[123,10] ; funky beep
sound pz,[50,10]
ENDIF
ELSE ;---- Normal Mode ------------------
ProgCounter (X) = ProgDelay ; start program detect delay
IF Counters(X) = 0 THEN ; if not counting yet
Counters(X) = ChargeDelay ; Set Delay before Charge mode
' READ X, ChargeTime(X) ; get charge time from EEPROM
' for i = 1 to ChargeTime(X) ; beep once for each hour
' GOSUB Beep ; so user knows current
' next i ; charge time before it starts
GOSUB LEDON ; turn on LED
ENDIF
ENDIF
ENDIF
ELSE ;---- button released --------------
ProgCounter (X) = 0 ; stop looking for program press
ENDIF
ENDIF
ENDIF
IF ProgCounter(X) > 0 THEN ;---- Program Delay counter --------
ProgCounter(X) = ProgCounter(X) - 1
IF ProgCounter(X) = 0 THEN ; when it times out
Counters(X) = 0 ; stop the Charge Delay period
Counters(X) = ProgHold ; reset Program inactivity Timeout
ChargeTime(X) = 0 ; clear the hour counter
for i = 1 to 11 ; beep 11 times as requested
GOSUB Beep
next i
ProgramMode = 1 ; -- Enter Program Mode --
ENDIF
ENDIF
IF Counters(X) > 0 THEN ;---- Main Delay Timers------------
IF ChargeMode THEN ;** In Charge Mode, time counts
IF SecondsChanged THEN ; in seconds **
Counters(X) = Counters(X) - 1
IF Counters(X) = 0 THEN ; End of Charge Time
GOSUB TriacOFF ; turn off the Triac
ChargeMode = 0 ; cancel charge mode
ENDIF
ENDIF
ELSE
Counters(X) = Counters(X) - 1 ;** Normal mode counts ms **
IF Counters(X) = 0 THEN ; if counter timed out
IF ProgramMode THEN ; and already in prog mode
ProgramMode = 0 ; End Programming Mode
GOSUB LEDOFF ; everything OFF
GOSUB TriacOFF
IF ChargeTime(X) > 0 THEN ; if user entered a charge time
WRITE X, ChargeTime(X) ; save it to EEPROM
ELSE ; if user didn't enter charge time
READ X, ChargeTime(X) ; restore time from EEPROM
ENDIF
for i = 1 to ChargeTime(X) ; beep once for each hour
GOSUB Beep
next i
ELSE ;---- End of delay before charge --
ProgCounter(X) = 0 ; Stop looking for program press
GOSUB LEDOFF ; LED OFF
GOSUB TriacON ; Triac ON - Start Charge
READ X, TempW ; Get charge time from EEPROM
Counters(X) = TempW * 3600 ; seconds to charge
ChargeMode = 1
ENDIF
ENDIF
ENDIF
ENDIF
ChannelStates(X) = ChannelState ; save channels state flags
NEXT X ; Do the next channel
SecondsChanged = 0 ; clear SecondsChanged notification
GOTO Main
;----I/O for each channel---------------------------------------------------
GetSWState:
SELECT CASE X ; get state of this channels pin
CASE 0 : PinState = SW1
CASE 1 : PinState = SW2
CASE 2 : PinState = SW3
CASE 3 : PinState = SW4
CASE 4 : PinState = SW5
CASE 5 : PinState = SW6
END SELECT
RETURN
LEDON:
SELECT CASE X ; turn ON the appropriate LED
CASE 0 : HIGH led1
CASE 1 : HIGH led2
CASE 2 : HIGH led3
CASE 3 : HIGH led4
CASE 4 : HIGH led5
CASE 5 : HIGH led6
END SELECT
RETURN
LEDOFF:
SELECT CASE X ; turn OFF the appropriate LED
CASE 0 : LOW led1
CASE 1 : LOW led2
CASE 2 : LOW led3
CASE 3 : LOW led4
CASE 4 : LOW led5
CASE 5 : LOW led6
END SELECT
RETURN
TriacON:
SELECT CASE X ; turn ON the channels Triac
CASE 0 : HIGH TR1
CASE 1 : HIGH TR2
CASE 2 : HIGH TR3
CASE 3 : HIGH TR4
CASE 4 : HIGH TR5
CASE 5 : HIGH TR6
END SELECT
RETURN
TriacOFF:
SELECT CASE X ; turn OFF the channels Triac
CASE 0 : LOW TR1
CASE 1 : LOW TR2
CASE 2 : LOW TR3
CASE 3 : LOW TR4
CASE 4 : LOW TR5
CASE 5 : LOW TR6
END SELECT
RETURN
;----Beep-------------------------------------------------------------------
Beep:
GOSUB LEDON ; flash LED when beeping
sound pz,[123,10]
GOSUB LEDOFF
pause 50
RETURN
There are a few commented lines in the "Normal Mode" section that will beep the number of hours when entering the "Delay before Charge" time. I thought it was handy to know how long it was set for before it starts charging.
HTH,
Bookmarks