Anthony,
Thanks for the reply.
The Pic is set up with a 4Mhz crystal with 33pF ceramic caps on
Pins#15 and 16. A 4K7 resistor from 5V+ goes to a tactile switch to V-
with a 100ohm resistor at the junction to PIN#4 MCLR. Pin#14 Vdd goes
to V+ with a 0.1uF ceramic cap to V-. RB0 and RB1 have 10K resistors
and tactile switches for positive pulses and RB2 is connected directly
to a small transducer. RB3/4/5/6/7 go to 330ohm resistors and LEDs to
V-. I haven't connected any more LEDs since I can't get past RB3/LED#1
The code is almost too embarrassing to post but in my defence it's
over twenty years since I last tried BASIC and COBOL at school. I
believe I'm getting better... I would hope so! Can't think of a way
past the IF_THENs or another way to do it.
Any advice, pointers appreciated.
Andrew.
''''''''''''''''''''''''''
' LED INDICATOR '
''''''''''''''''''''''''''
'Ten second, ten LED, one second increment/decrement incicator.
'If Button#1 depressed for over 10 seconds the excess is ignored.
DEFINE LOADER_USED 1
''''''''''''''''''''''''''
' HARDWARE STARTUP SETUP '
''''''''''''''''''''''''''
TRISA = %00000 'Set PORTA to all output
PORTA = 0 'PORTA (133) outputs off
TRISB = %00000011 'Set PORTB to all output but RB0 and RB1
PORTB = 0 'PORTB (134) outputs off
CLEAR 'Clear all vairables and buffers
''''''''''''''''''''''''
' INITIALIZE VAIRABLES '
''''''''''''''''''''''''
W0 VAR WORD '16 bit PULSIN vairable
W1 VAR WORD '16 bit PULSIN vairable
W2 VAR WORD '16 bit time vairable
''''''''''''''''
' STARTUP BEEP '
''''''''''''''''
GOSUB BEEP 'Sound a double beep on PORTB RB2
''''''''''''''''
' MAIN PROGRAM '
''''''''''''''''
LOOP1:
W0 = 0 'Zero W0
PULSIN 0,1,W0 'BUTTON#1 on RB0, measure high pw to W0
W2 = W2 + W0 'Add W0 to W2
W1 = 0 'Zero W1
PULSIN 1,1,W1 'BUTTON#2 on RB1, measure high pw to W1
W2 = W2 - W1 'Subtract W1 from W2
IF W2 >= 100 THEN LED1 'One second
IF W2 >= 200 THEN LED2
IF W2 >= 300 THEN LED3
IF W2 >= 400 THEN LED4
IF W2 >= 500 THEN LED5
'IF W2 >= 600 THEN LED6
'IF W2 >= 700 THEN LED7
'IF W2 >= 800 THEN LED8
'IF W2 >= 900 THEN LED9
'IF W2 >= 1000 THEN LED10 'Ten seconds
GOTO LOOP1
LED1:
PORTB.3 = 1 'Light LED1 - 1 sec
GOTO LOOP1
LED2:
PORTB.4 = 1 'Light LED2 - 2 sec
GOTO LOOP1
LED3:
PORTB.5 = 1 'Light LED3 - 3 sec
GOTO LOOP1
LED4:
PORTB.6 = 1 'Light LED4 - 4 sec
GOTO LOOP1
LED5:
PORTB.7 = 1 'Light LED5 - 5 sec
GOTO LOOP1
'LED10:
'PORTA??? 'Light LED10 - 10 sec
'W2 = 1000 'Set time to 10 seconds
'GOSUB BEEP 'Max time warning beep
'GOTO LOOP1
END
'''''''''''''''
' SUBROUTINES '
'''''''''''''''
BEEP:
SOUND PORTB.2, [120,10,60,10] 'Sound a double beep on PORTB RB2
RETURN