Can I have 5 inputs that when one is high, the corresponding output (5 outputs) is high and stays high until another input gets high? In other words the input will not stay high, but I want the output to stay high until a different input gets high. I know I need an interrupt, but a point in the right direction would be appreciated.
You can do that. You can do it using interrupts, but you can't have 5 interrupt lines. There is an interrupt on the 16F877 that sets a flag each time PORTB pin7-pin4 changes.
You can also do something like this, suppose your 5 inputs are in PortB0-4 and your 5 outputs are at PortC0-4
Code:
INPUTS var byte
OUTPUTS var PortC
PortB = %00011111
PortC = %11100000
Start:
OldInputs = Inputs
INPUTS = PortB
If OldInputs <> INPUTS then
Outputs = INPUTS
endif
goto Start
Here is a sample coded in '84 assembly. It does not need interrupts and is probably just as fast.
Code:
PORTA_SAVE EQU 0Ch
TEMP_REG EQU 0Dh
START:
MOVLW B'00011111' ; MAKE ALL PINS INPUT
TRIS PORTA
MOVLW B'00000000' ; MAKE ALL PINS OUTPUT
TRIS PORTB
;
CLRF PORT_SAVE
CLRF PORTB
LOOP:
COMF PORTA_SAVE,W
MOVWF TEMP_REG
MOVF PORTA,W
MOVWF PORTA_SAVE ; SAVE FOR NEXT PASS
ANDWF TEMP_REG,W ; DETECT RISING EDGE
ANDLW B'00011111' ; MASK OUT UNUSED PINS
BTFSS STATUS,Z
MOVWF PORTB ; OUTPUT TO PORT THE ACTIVE PIN
;
GOTO LOOP