Thread: Masking(or ...)

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    21

    Masking(or ...)

    hi all,


    I am currently doing some embedded programming on microcontroller. What i don't understand is how do i test a pin in a particular port if it is high or low in C?
    lets say i want to see if port A pin 1 is high. can i use masking? How does masking is used actually?

    lets say i have

    Code:
    porrtAmask = 2 ;    //00000010
    if i use

    Code:
    if(mask & portregister);    //portregister is the place where MCU  
                                             //keeps the data
    I know that AND will only result 1 if both is but will it tell me that port A pin 1 is high?


    00000010-----portAmask
    00000010-----portregister
    --------------
    00000010 ==> this is 0x02H

    so how the if loops above works?

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    r u trying to say that the data in the portregister automatically implies that it has come from portA?
    i dont think that is true.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    21
    It should be PortDataRegister.this should be data latch on the port.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    how many pins r included in the port? is that a serial or parallel port?

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read the bitwise FAQ.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > r u trying
    Please try and use "you" and "are"
    This cryptic language is irritating enough for native speakers, nevermind all the people who use English as a foreign language.

Popular pages Recent additions subscribe to a feed