Professional Documents
Culture Documents
Question: Read continuously input values (as a byte) and write to the
outputs (LED)
a) Same value
b) Complement
c) Opposite (negate)
d) Double value
e) Half value
f) Half +5
In each part , I will explain the steps for solving in order to accomplish the
objective of our experiment.
Solution:
a) Same value:
Suppose I have entered the value 3 (base 10) as an input to the micro, then
I have to see the same value in port B
A7 A6 A5 A4 A3 A2 A1 A0
In port B (output section) we will have the same value
0000 0011
B7 B6 B5 B4 B3 B2 B1 B0
From these boxes we can see that when we apply the input 3 I will see 2
LED ON ( B0 and B1) .
Code:
MOVWF PORTB
GOTO MAIN }
b) Complement
To explain this part, I will take as an example the easiest number which is 0.
If 0 is assigned as an input to port A, that means I will see all the LEDs ON
because the complement of 0 is simply 1.
0000 0000
Port A
A7 A6 A5 A4 A3 A2 A1 A0
B7 B6 B5 B4 B3 B2 B1 B0
{ MOVF PORTA,W
MOVWF TEMP
COMF TEMP,W
MOVWF PORTB }
c) opposite (negate):
The goal of this part is to see the opposite value of any input.
For instance, if the input is 3(base 10), I want to see in the output the
number -3.
A7 A6 A5 A4 A3 A2 A1 A0
First Complement
1111 1100
ADD +1
Code:
1111 1101 Port B
B7 B6 B5 B4 B3 B2 B1 B0
{MOVF PORTA,W
MOVWF TEMP
COMF TEMP,W
ADDLW H'01'
MOVWF PORTB }
From this flow chart we can see that this part is the same as b)
(complement) and the only difference that we add +1 to our code.
The double and half are very similar to each other , because the two of
them follows the same way which is the rotation method, with a small
difference between them.
Let us take for example number 4(base 10). The double is 8 and the half is
2.
{The 1 is moved to the right and a 0 will come from the carry to A7}
From these figures we can deduce that d + e + f have the same code; only
the sense of rotation will be different. And for f) we only add +5 to our code
Code:
{ MOVF PORTA,W
MOVWF TEMP
MOVWF PORTB }