Programing Question


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Location
    California USA
    Posts
    7

    Cool Programing Question

    Hello All,
    I got a MELabs LabX1 and I don't know whay some things are in the Key Scan routine mean.
    The code is

    getkeyu:
    ' Wait for all keys up
    PORTB = 0 ' All output pins low
    TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
    If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop

    Pause 50 ' Debounce

    getkeyp:
    ' Wait for keypress
    For col = 0 to 3 ' 4 columns in keypad
    PORTB = 0 ' All output pins low
    TRISB = (dcd col) ^ $ff ' Set one column pin to output
    row = PORTB >> 4 ' Read row
    If row != $f Then gotkey ' If any keydown, exit
    Next col

    Goto getkeyp ' No keys down, go look again

    gotkey: ' Change row and column to key number 1 - 16
    key = (col * 4) + (ncd (row ^ $f))
    Return ' Subroutine over

    Can someone tell me what that the ! means and the ^ means in the code?

    Thank for your help.
    Willie

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    != means "Not Equal" could use <> instead

    ^ means "Bitwise Exclusive OR"

    4.17.14. Bitwise Operators

    Bitwise operators act on each bit of a value in boolean fashion. They can be used to isolate bits or add bits into a value.

    B0 = B0 & %00000001 ' Isolate bit 0 of B0
    B0 = B0 | %00000001 ' Set bit 0 of B0
    B0 = B0 ^ %00000001 ' Reverse state of bit 0 of B0
    Last edited by DynamoBen; - 20th February 2006 at 01:39.

  3. #3
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216


    Did you find this post helpful? Yes | No

    Default Butting in

    Just reading this reply, DynamoBen, and have come up with a question with the Math Operators.

    Using the BITWISE NOT ~ I guess B0 = B0 ~ %11111111 would invert the whole byte? and B0 = B0 ~ % 00001111 would invert the lower nibble? So the 0 means leave that bit alone, and 1 means invert that bit?

    Right or wrong???????

  4. #4
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    When dealing with bitwise Operators:

    0 means leave that bit alone
    1 means take action based on operator

    You have the hang of it basically think of them as filters.

    Using your code $F = %00001111

Similar Threads

  1. ADCIN question
    By Greg McFadden in forum General
    Replies: 4
    Last Post: - 16th September 2008, 02:53
  2. FREQOUT - PWM question
    By Etcho in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th February 2007, 23:51
  3. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  4. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  5. Timer / CCP Question
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd November 2005, 08:22

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