variable to equal low 4 bits of portB, and OUTPUT b4-b7


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Posts
    9

    Thumbs up variable to equal low 4 bits of portB, and OUTPUT b4-b7

    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.
    Last edited by reaper0995; - 29th April 2008 at 18:26.

  2. #2
    Join Date
    Mar 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    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.....



  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    TRISB = %00001111
    keyin var byte
    keyin = portb
    keyin = keyin << 4
    portb = keyin
    or like I usually do:
    Code:
    TRISB=15:keyin var byte:portb=portb<<4
    but this method could present problems...
    Last edited by skimask; - 29th April 2008 at 18:35.

  4. #4
    Join Date
    Mar 2008
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    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"

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by reaper0995 View Post
    ... since it can only be done on portB
    Why is it limited to Port B?

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    May be something like this could help you.

    Code:
    <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>&quot;HELLO&quot;
          </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>
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. PIC16F877A for application in mobile robot...
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th January 2009, 14:47
  2. problem with input and output (18F452)
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th March 2008, 23:21
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts