View Full Version : variable to equal low 4 bits of portB, and OUTPUT b4-b7
reaper0995
- 29th April 2008, 18:16
i am putting a 4 bit binary number to portB on a 16f88. there are 8 bits on portB, and this is what i have:
____________________
keyvalue var byte
keyvalue = PORTB
____________________
now, i want to be able to use b.4-b.7, and not make my code just a ton of if statements. i could do "if (portb.1 == 1 && portb.2 == 1 &&..........." etc, but that is kinda a lot for 9 numbers (i only need values of 1 through 9).
basically, i want to have the high 4 bits of portB to be OUTPUTS.
reaper0995
- 29th April 2008, 18:23
another thing.... if i could do an array, that would be fine too. i just dont know if that would help me get the high bits free for outputs....
----------------
keyvalue var byte
pins[1] = %00000001
pins[2] = %00000010
......
pins[9] = %00001000
keyvalue = pins
----------------
but i think this does the same thing and "locks" the upper 4 bits as permanent inputs.....
:(
skimask
- 29th April 2008, 18:33
TRISB = %00001111
keyin var byte
keyin = portb
keyin = keyin << 4
portb = keyin
or like I usually do:
TRISB=15:keyin var byte:portb=portb<<4
but this method could present problems...
reaper0995
- 30th April 2008, 07:28
i think i am going to try this tomorrow....
keyvalue = portB & $0F 'bitwise 00001111
trisB.7 = 0
XXXXXXXXXXXXXX
trisB.7 = 1
on a side note, i was namely trying to emit sound on the "sound" command... since it can only be done on portB, and so i tried to dot he sound command, and it worked. on the plus side as well, the speaker is grounded so it was a convienient "pull-down"
sayzer
- 30th April 2008, 07:31
May be something like this could help you.
<font color="#000080"><i>'============== Name Pins =================
</i></font>A <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000"><b>7
</b></font>B <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000"><b>6
</b></font>C <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000"><b>5
</b></font>D <font color="#000080"><b>VAR </b></font>PORTB.<font color="#FF0000"><b>4
</b></font>MyPort <font color="#000080"><b>VAR BYTE
</b></font>MyPort <font color="#000080"><b></font>=<font color="#FF0000"><b> 0</b>
</b></font>Loop:
<font color="#000080"><b>GOSUB </b></font>SetPins
<font color="#000080"><b>IF </b></font>MyPort = <font color="#FF0000"><b>2 </b></font><font color="#000080"><b>THEN </b></font>SayHello <font color="#000080"><i>' Example to use pin assignment.
</i><b>GOTO </b></font>Loop
SayHello:
<font color="#000080"><b>LCDOUT </b></font><font color="#FF0000"><b>$fe</b></font>,<font color="#FF0000"><b>1</b></font>,<font color="#008000"><b>"HELLO"
</b></font><font color="#000080"><b>PAUSE </b></font><font color="#FF0000"><b>1000
</b></font><font color="#000080"><b>GOTO </b></font>Loop
SetPins:
MyPort.<font color="#FF0000"><b>0 </b></font>= A
MyPort.<font color="#FF0000"><b>1 </b></font>= B
MyPort.<font color="#FF0000"><b>2 </b></font>= C
MyPort.<font color="#FF0000"><b>3 </b></font>= D
<font color="#000080"><b>RETURN
END
</b></font>
skimask
- 30th April 2008, 20:01
... since it can only be done on portB
Why is it limited to Port B?
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.