Re: decimal input on portB
Sancerre, I would:
1. read the port of choice into a single BYTE size variable.
2. AND port read variable with $F0 and place into separate variable to separate the upper nibble. (4 bits)
3. AND port read variable with $0F and place into separate variable to separate the lowerr nibble. (4 bits)
There you have it. I am assuming you are talking about BCD when you are talking about decimal?
Re: decimal input on portB
One way to accomplish this is this way.
This will copy the upper 4 bits of the value of PORTB into a new byte variable in the lower 4 bit positions and will copy the lower 4 bits of the value of PORTB into another byte variable in the lower 4 bit positions.
Code:
myPortB var byte
HighNib var byte
LowNib var byte
myPortB = PortB
HighNib = myPortB >> 4 'Right shift myPortB 4 bits, (moves bits 7:4 to bits 3:0 and then set bits 7:4 to 0)
LowNib = myPortB & %00001111 'Mask off bits 7:4 to 0, Only get bits 3:0
So if PortB = %10010110 '$96
Then
HighNib = %00001001 '$09
LowNib = %00000110 '$06
Re: decimal input on portB
Hi all,
Decimal or Hex ? It's depend of BRANCH syntax. Can I write something like
BRANCH PORTB [dog, cat,fish] ???
For nibbles, I can choose between
initial:
TRISB = 111111
SWVAR VAR BYTE
SWVAR1 VAR BYTE
SWVAR2 VAR BYTE
code1:
SWVAR = PORTB
SWVAR1 = SWVAR & $0F
SWVAR2 = SWVAR & $F0
or code2:
SWVAR1 = SWVAR >> 4 'Right shift myPortB 4 bits, (moves bits 7:4 to bits 3:0 and then set bits 7:4 to 0)
SWVAR2 = SWVAR & %00001111 'Mask off bits 7:4 to 0, Only get bits 3:0
switches will be active when pulling down... Do I change something in my code ?
Thanks for your time. Have a nice day. Oleg
Re: decimal input on portB
What version of PBP are you using?
Re: decimal input on portB
Bonjour
Quote:
Originally Posted by
Tabsoft
What version of PBP are you using?
PBP 2,5.
Have a nice day.
Re: decimal input on portB
Yes, you could use the BRANCH command as you have described, "BRANCH PORTB [dog, cat,fish]".
That being said, I don't think I would use it that way.
The BRANCH command has the following syntax, "BRANCH Index,[Label{,Label...}]"
One issue in using the BRANCH command this way is that using a byte variable or Port Alias for the "Index" means you can have 256 possible values (0-255).
Which might require you to create 256 Labels and add them to the Label list in the BRANCH command.
The "Index" is just a number pointing to the list of "Labels" in the BRANCH command. E.g. BRANCH Index, [Label_0, Label_1, Label_2, ...]
If Index = 0 then the program will Branch to Label_0, if Index = 1 then the program will Branch to Label_1, etc.
If you are using the value of PORTB, there can be up to 256 different values which would make for one very long Branch command.
"BRANCH Index,[Label_0, Label_1,... Label_255]"
If it were me I would do something like this.
Code:
myPortB var byte
myPortB = PORTB
if myPortB = 1 then GOTO Label_1
if myPortB = 2 then GOTO Label_2
etc.
Label_1:
'Do something
Label_2:
'Do something
This gives you the power to pick and choose which values of PORTB you want to act on.
You could also replace the GOTO portion above with GOSUB, which will jump to the Label_x, then at the end of your subroutine (Label_x) the "Return"
command will cause the program to return back to the next instruction after the GOSUB.
Code:
if myPortB = 1 then GOSUB Label1
if myPortB = 2 then GOSUB Label2
etc.
Label_1:
'Do something
return
Label_2:
'Do something
return
You could similarly use the Select Case command.
Re: decimal input on portB
This wouldn’t be needed if shift shifts in zero values which I think it does:
Code:
SWVAR2 = SWVAR & %00001111 'Mask off bits 7:4 to 0, Only get bits 3:0
Re: decimal input on portB
Hi all,
thanks for your valuable help. Following your advices, my code can look like :
TRISB = %11111111
TRISA = %00000
SWVAR VAR BYTE
SWVAR1 VAR BYTE
SWVAR2 VAR BYTE
SWVAR = PORTB
SWVAR1 = SWVAR >> 4 'Right shift myPortB 4 bits, (moves bits 7:4 to bits 3:0 and then set bits 7:4 to 0)
SWVAR2 = SWVAR & %00001111 'Mask off bits 7:4 to 0, Only get bits 3:0
IF SWVAR1 <>0 THEN GOTO SUITE
if SWVAR2 = 1 then GOTO sound1
if SWVAR2 = 2 then GOTO sound2
if SWVAR2 = 3 then GOTO sound3
...
ENDIF
SUITE:
if SWVAR1 = 1 then GOTO sound1
if SWVAR1 = 2 then GOTO sound2
if SWVAR1 = 3 then GOTO sound3
...
sound1:
FREQOUT PORTA.0,4000,500
sound2:
FREQOUT PORTA.0,4000,1000
sound3:
FREQOUT PORTA.0,4000,1500
sound4:
FREQOUT PORTA.0,4000,2000
Have a nice day.
Oleg