Below, we will analyze how you can wiggle individual bits, carry out certain straightforward
arithmetic, as well as data tables.
PIC Tutorial - 6..............................PIC Tutorial - 8
Logical Managers
Within the last tutorial I presented the Exclusive OR operation. The ExOR function is understood as a logical operator. Within this tutorial I will enlighten the additional logical operators that the PIC promotes. There won’t be any kind of case in point programs, however We will learn easy methods to use the operators by applying small areas of code. AND The AND function basically analyzes two bits and delivers a 1 whether they are the same, and a 0 in case they are distinctive. For instance, if we mentioned 1 AND 1, the outcome is 1, while in case we declared 1 AND 0 the consequence would be 0. Needless to say, we are able to evaluate words also, as well as all of the the AND function accomplishes is review the two terms bit by bit. The instance below demonstrates two 8-bit words becoming ANDed together with the product:
11001011
AND 10110011
Equals 10000011
I hope you agree, the outcome will simply possess a 1 whenever 2 1s hand in hand with one another in the a pair of words. We are able to utilize the AND function to verify the ports, for instance. In case we are checking a few I/O pins that are linked to a circuit, and we should keep an eye on a particular situation in which only a few of the pins are high, in that case we are able to pretty much read the port, after which AND the outcome with the condition we have been examining for, identical to the instance above. The PIC provides us two ingredients for AND.
They are ANDLW and ANDWF. ANDLW permits us to carry out an AND function with the details of the W register, and a amount that we stipulate.
The syntax is: ANDLW <number> wherein <number> is exactly what we are going to AND the contents of W with. The consequence of the AND function would be stored directly into the W register.
ANDWF permits us to carry out an AND function on the W register and a different register, for example a PORT. The syntax is: ANDWF <register>,d in which <register> is the register we are enthusiastic about, e.g. PORTA, and d shows the PIC where you should position the result. If d=0, the outcome is put in the W register, and of d=1 the end result is saved in the register we stipulated. The two parts of code below display a good example of each AND function. The initial is examining the status of the PORTA, in which we need to check if the inputs are 1100. We can place the outcome back into the W register
PIC Tutorial - 6..............................PIC Tutorial - 8
Logical Managers
Within the last tutorial I presented the Exclusive OR operation. The ExOR function is understood as a logical operator. Within this tutorial I will enlighten the additional logical operators that the PIC promotes. There won’t be any kind of case in point programs, however We will learn easy methods to use the operators by applying small areas of code. AND The AND function basically analyzes two bits and delivers a 1 whether they are the same, and a 0 in case they are distinctive. For instance, if we mentioned 1 AND 1, the outcome is 1, while in case we declared 1 AND 0 the consequence would be 0. Needless to say, we are able to evaluate words also, as well as all of the the AND function accomplishes is review the two terms bit by bit. The instance below demonstrates two 8-bit words becoming ANDed together with the product:
11001011
AND 10110011
Equals 10000011
I hope you agree, the outcome will simply possess a 1 whenever 2 1s hand in hand with one another in the a pair of words. We are able to utilize the AND function to verify the ports, for instance. In case we are checking a few I/O pins that are linked to a circuit, and we should keep an eye on a particular situation in which only a few of the pins are high, in that case we are able to pretty much read the port, after which AND the outcome with the condition we have been examining for, identical to the instance above. The PIC provides us two ingredients for AND.
They are ANDLW and ANDWF. ANDLW permits us to carry out an AND function with the details of the W register, and a amount that we stipulate.
The syntax is: ANDLW <number> wherein <number> is exactly what we are going to AND the contents of W with. The consequence of the AND function would be stored directly into the W register.
ANDWF permits us to carry out an AND function on the W register and a different register, for example a PORT. The syntax is: ANDWF <register>,d in which <register> is the register we are enthusiastic about, e.g. PORTA, and d shows the PIC where you should position the result. If d=0, the outcome is put in the W register, and of d=1 the end result is saved in the register we stipulated. The two parts of code below display a good example of each AND function. The initial is examining the status of the PORTA, in which we need to check if the inputs are 1100. We can place the outcome back into the W register
movlw 1100
ANDWF 05h,0
The second illustration might now verify the contents of the W register:
ANDLW 1100
OR
We have by now discovered one OR function, to be precise the XOR. This develops into a 1 if two bits are not the same, but are different. You can find another OR function called IOR, which is the inclusive OR. This function will generate a 1 in case either bit is a 1, but additionally if each bits are 1. Below is a clear-cut truth table to illustrate this:
A B O/P
0 0 0
0 1 1
1 0 1
1 1 1
Arithmetic Operators
ADD
This function accomplishes what usually it claims. It contributes two figures! In case the consequence of adding the two figures surpasses 8 bits, in that case a CARRY flag will probably be set. The CARRY flag is situated at address 03h bit 0. When this bit is scheduled, then the two figures surpassed 8 bits. When it is a 0, in that case the consequence is located within 8 bits. As before, the PIC delivers us two styles of ADD, specifically ADDLW and ADDWF. As you might have assumed, this is quite like the above function. ADDLW offers the contents of the W register to that we stipulate. The syntax is: ADDLW <number> ADDWF add the contents of the W register and some other register that we designate. The syntax is: ADDWF <register>,d is where <register is the register we specify and d tells the PIC where to place the outcome. If d=0, the result is put in the W register, and is d=1 it set up in the register that we selected.
SUB
At this point, I guess you can’t presume what this function conducts! Indeed, you suspected it, this function
subtracts one bit from another. Again the PIC provides us 2 tastes: SUBLW and SUBWF. The syntax is precisely the similar to for the ADD function, apart from evidently you type SUB in place of ADD!
ANDWF 05h,0
The second illustration might now verify the contents of the W register:
ANDLW 1100
OR
We have by now discovered one OR function, to be precise the XOR. This develops into a 1 if two bits are not the same, but are different. You can find another OR function called IOR, which is the inclusive OR. This function will generate a 1 in case either bit is a 1, but additionally if each bits are 1. Below is a clear-cut truth table to illustrate this:
A B O/P
0 0 0
0 1 1
1 0 1
1 1 1
Arithmetic Operators
ADD
This function accomplishes what usually it claims. It contributes two figures! In case the consequence of adding the two figures surpasses 8 bits, in that case a CARRY flag will probably be set. The CARRY flag is situated at address 03h bit 0. When this bit is scheduled, then the two figures surpassed 8 bits. When it is a 0, in that case the consequence is located within 8 bits. As before, the PIC delivers us two styles of ADD, specifically ADDLW and ADDWF. As you might have assumed, this is quite like the above function. ADDLW offers the contents of the W register to that we stipulate. The syntax is: ADDLW <number> ADDWF add the contents of the W register and some other register that we designate. The syntax is: ADDWF <register>,d is where <register is the register we specify and d tells the PIC where to place the outcome. If d=0, the result is put in the W register, and is d=1 it set up in the register that we selected.
SUB
At this point, I guess you can’t presume what this function conducts! Indeed, you suspected it, this function
subtracts one bit from another. Again the PIC provides us 2 tastes: SUBLW and SUBWF. The syntax is precisely the similar to for the ADD function, apart from evidently you type SUB in place of ADD!
Increment
In case we wished to include 1 to a number in the PIC, we could absolutely make use of the ADD function, and utilize the number one. ~The difficulty with this is that we must first place the figure into the W register, subsequently use ADDLW 1 control to increment it. In case we desired to include 1 to a register, it can be worse still. We first must place the number 1 into the W register, after that use ADDWF <register>,1. Therefore, for instance, to include 1 to location 0C, say, we would need to possess the following part of script:
movlw 01
addwf 0c,1
There exists an easier method of conducting this. We can exercise the command INCF. The syntax is: INCF <register>,d where <register>, is the register, or place, that we are concerned in, and d shows the PIC where you should position the outcome. In case d=0, the outcome is within the W register, and in case d=1, the consequence is set in the register we stipulated. By utilizing this individual instruction we are able to actually fifty percent of the coding. In case we desired the outcome restored into the W register, in that case employing the instance above, we might have had to include an additional command to shift the items of 0C back into the W register, after which place the 0C register back to no matter what it was. There exists increment command. It is INCFSZ. This command might increment the register that we stipulate, however if we the register equals 0 after the increment (that will occur while we include 1 to 127) after that the PIC will probably by pass the subsequent instruction. The portion of code below reflects this:
Loop incfsz 0C
Goto Loop
:
:
Remainder of program.
In the above portion of code, 0C is going to be incremented by 1. We next own an instruction that informs the PIC to return to our tag named Loop, and increment 0C by 1 again. This continues until 0C equals 127. In this circumstance, when we increment 0C by 1, 0C is going to now match 0. Our INCFSZ instruction could very well inform the PIC to omit the subsequent instruction, which in this instance is the goto declaration, hence the PIC will go forward with the remaining of the program.
Decrement
We have by now discussed the decrement function in earlier training, therefore I won’t revise
it anymore.
In case we wished to include 1 to a number in the PIC, we could absolutely make use of the ADD function, and utilize the number one. ~The difficulty with this is that we must first place the figure into the W register, subsequently use ADDLW 1 control to increment it. In case we desired to include 1 to a register, it can be worse still. We first must place the number 1 into the W register, after that use ADDWF <register>,1. Therefore, for instance, to include 1 to location 0C, say, we would need to possess the following part of script:
movlw 01
addwf 0c,1
There exists an easier method of conducting this. We can exercise the command INCF. The syntax is: INCF <register>,d where <register>, is the register, or place, that we are concerned in, and d shows the PIC where you should position the outcome. In case d=0, the outcome is within the W register, and in case d=1, the consequence is set in the register we stipulated. By utilizing this individual instruction we are able to actually fifty percent of the coding. In case we desired the outcome restored into the W register, in that case employing the instance above, we might have had to include an additional command to shift the items of 0C back into the W register, after which place the 0C register back to no matter what it was. There exists increment command. It is INCFSZ. This command might increment the register that we stipulate, however if we the register equals 0 after the increment (that will occur while we include 1 to 127) after that the PIC will probably by pass the subsequent instruction. The portion of code below reflects this:
Loop incfsz 0C
Goto Loop
:
:
Remainder of program.
In the above portion of code, 0C is going to be incremented by 1. We next own an instruction that informs the PIC to return to our tag named Loop, and increment 0C by 1 again. This continues until 0C equals 127. In this circumstance, when we increment 0C by 1, 0C is going to now match 0. Our INCFSZ instruction could very well inform the PIC to omit the subsequent instruction, which in this instance is the goto declaration, hence the PIC will go forward with the remaining of the program.
Decrement
We have by now discussed the decrement function in earlier training, therefore I won’t revise
it anymore.
Compliment
The final instruction in this discussion would reverse every single bit in the register that we stipulate. The syntax is: COMF <register>,d wherein <register is the register that we wish to reverse, and d will inform the PIC where to collect the result. If d=0, the result is saved in the W register. If d=1, the result is saved again into the register we assigned. The following example exhibits this instruction in practicality:
0C = 11001100
COMF 0C,1
0C = 00110011
This could be utilized, for instance, to swiftly swap the pins of a port from output to input and so on.
0 Response to "Understanding Logical and Arithmetic Operators: PIC Tutorial 7"
Posting Komentar