0% found this document useful (0 votes)
38 views

Lab3:Condition-flow (Bit and Byte Test) : Using The Bit Method: This Method Simply Consist of Testing

This document describes two methods - bit and byte - for determining the state of LED lights based on the positions of two switches using a PIC microcontroller. The bit method tests each bit individually and sets the LEDs accordingly. The byte method ANDs the switch input with a mask, compares the result to cases, and sets the LEDs based on the matching case. Both methods are implemented with flow charts and assembly code to check the switch states and control the LED outputs.

Uploaded by

Omar F'Kassar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Lab3:Condition-flow (Bit and Byte Test) : Using The Bit Method: This Method Simply Consist of Testing

This document describes two methods - bit and byte - for determining the state of LED lights based on the positions of two switches using a PIC microcontroller. The bit method tests each bit individually and sets the LEDs accordingly. The byte method ANDs the switch input with a mask, compares the result to cases, and sets the LEDs based on the matching case. Both methods are implemented with flow charts and assembly code to check the switch states and control the LED outputs.

Uploaded by

Omar F'Kassar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab3:Condition-flow(bit and byte test)

Objective: In this experiment, we will learn :


1) How to know the id of an unknown input using 2 methods: bits and
bytes . Also note that in the byte method we will learn the use of the
Z flag (zero flag) as we will explain later.
2) How to use the condition instruction(BTSS or BTFSC) which are the
keys in our code

Question: Write an assembly code which implements the following table:


S1 (RA3) S0 (RA0) LED
0 0 OFF
0 1 0F (base 16)
1 0 F0 (base 16)
1 1 ON

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

CONFI Port A input/ Port B output

RESULT and PORTB=00H INIT

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

CASEA BTFSS PORTA,RA0

GOTO CASEB

MOVLW H'0F'

MOVWF PORTB

GOTO BITTEST

CASEB MOVLW H'00'

MOVWF PORTB

GOTO BITTEST

CASEC MOVLW H'F0'

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

Explanation of the byte method:

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’.

2) We will have a random result which we will save it in a variable


named: RESULT
3) To have the id of RESULT, we will substract this variable with each
case
4) If for example, the Z flag in the file STATUS =1 ,that implies that the
variable is the same as the case and then we can move to the PORTB
the corresponding output.
5) This step is repeated for all cases.

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

A N D w ith H ' 0 9 '


Y
Y
0F
= 01

Y
LEDs O FF
= 00

N
Code:

CASE1 MOVF PORTA,W

ANDLW H'09'

MOVWF RESULT

MOVF RESULT,W

SUBLW H'00'

BTFSS STATUS,Z

GOTO CASE2

MOVLW H'00'

MOVWF PORTB

GOTO CASE1

CASE2 MOVF RESULT ,W

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

CASE4 MOVLW H'FF'

MOVWF PORTB

GOTO CASE1

 By finishing explaining these 2 methods, the objectives are done.

You might also like