No, not really.
That has been the point of this discussion.
We would not want PBP to do the interim calculations as a byte, we would want PBP to do them as a bit.
The issue is that in this statement "Report = 48 + !Mypin"
Report is a byte variable, 48 will be treated as a constant and Mypin is a bit.
Sounds good so far, but, when PBP looks at this statement it will treat the !Mypin as a byte output in the calculation step.
It does this because "Report" on the left side is a byte variable.
What we want is if Mypin = 0 then Report = 49; If Mypin = 1 then Report = 48.
But here is what happens.
Pseudocode for the PBP ASM Macros used for the following Statement: Report = 48 + !Mypin
Code:
Step 1. Perform a Logical NOT on Mypin.
Clear the W register (Set it to 0)
If Mypin is a zero then
Store 255 decimal in the W register 'This is because Report will ultimately get the value, so PBP starts treating all the output variables as bytes
else
Store 0 in W register
endif
Move W register to a temporary "byte" variable T1
Step 2. Add 48 to temporary "byte" variable T1
Step 3. Move Temporary "byte" variable T1 to "byte" variable Report
So if you start with Mypin = 0, then
Code:
Step 1. T1 = 255
Step 2. T1 = 255 + 48 = 47 ' This is because a byte variable is unsigned in PBP
Step 3. Report = 47 'We wanted Report to equal 49 not 47
If you start with Mypin = 1
Step 1. T1 = 0
Step 2. T1 = 0 + 48 = 48
Step 3. Report = 48 'This is what we wanted.
So the issue as I can see is that to perform this logic as we "want" it to work, you need to manually perform an interim step
and store the current value of Mypin in a "bit" variable. Then perform a logical NOT on the "bit" variable. Then add 48 and the "bit" variable
and store the answer in report.
myBit var bit
Mypin var PORTB.6
Report var byte
myBit = Mypin
myBit = !myBit
Report = 48 + myBit
This works.
Bookmarks