Lab3:Condition-flow (Bit and Byte Test) : Using The Bit Method: This Method Simply Consist of Testing
Lab3:Condition-flow (Bit and Byte Test) : Using The Bit Method: This Method Simply Consist of Testing
Solution : a) Using the bit method: this method simply consist of testing
each bit ( ( RA3 ) and ( RA0 ) here ) and moving the corresponding output to
PORTB
Flow-Chart: (Bit method) Start
NO NO
S1 S0
LEDS (OFF)
ON ON
YES
YES
LEDS (0F)
NO
S0
LEDS (F0)
ON
YES
LEDS (ON)
Code:
BITTEST BTFSS PORTA,RA3
GOTO CASEA
BTFSS PORTA,RA0
GOTO CASEC
MOVLW H'FF'
MOVWF PORTB
GOTO BITTEST
GOTO CASEB
MOVLW H'0F'
MOVWF PORTB
GOTO BITTEST
MOVWF PORTB
GOTO BITTEST
MOVWF PORTB
GOTO BITTEST
S1 S1
b) Using byte method:
PORTA A7 A6 A5 A4 A3 A2 A1 A0
Any
input x x x x x x x x
value
AND
with 0 0 0 0 1 0 0 1
H’09’
Case
RESULT 0 0 0 0 0 0 0 0
0
Of AND
Case
Betwee 0 0 0 0 0 0 0 1
1
n
Case
Input 0 0 0 0 1 0 0 0
2
and
Case
H’09’ 0 0 0 0 1 0 0 1
3
1) The input is ANDed with H’09’. The purpose of the AND is to reduce
the cases which we need to study.
Note: in the byte method, we do not always use H’09’ as the number with
the AND operation; to know which number we use we look at the switches
position and we conclude the number from these swtiches .
For instance if have S1 at A1 and S0 is still the same, the number with AND
would be : H’03’.
Flow-Chart:
F 0
S ta r t
C o n fi + In it N
= 11 LEDs O N
= 10
R e a d In p u t V a lu e
Y
LEDs O FF
= 00
N
Code:
ANDLW H'09'
MOVWF RESULT
MOVF RESULT,W
SUBLW H'00'
BTFSS STATUS,Z
GOTO CASE2
MOVLW H'00'
MOVWF PORTB
GOTO CASE1
SUBLW H'01'
BTFSS STATUS,Z
GOTO CASE3
MOVLW H'0F'
MOVWF PORTB
GOTO CASE1
CASE3 MOVF RESULT ,W
SUBLW H'08'
BTFSS STATUS,Z
GOTO CASE4
MOVLW H'F0'
MOVWF PORTB
GOTO CASE1
MOVWF PORTB
GOTO CASE1