Read and write port pin

A catchall for PSoC Mixed-Signal Array (microcontroller) discussions not captured by the other forums.

Moderator: ericb

Read and write port pin

Postby johnjcl on Thu Feb 09, 2006 10:45 am

How I can read (or write) if a pin this in low or high and thus to make an action. For example a jump. Please in assembler. 8)
johnjcl
User avatar
johnjcl
Newbie
Newbie
 
Posts: 9
Joined: Fri Nov 11, 2005 11:57 am
Location: Colombia

Postby wrightpc on Thu Feb 09, 2006 12:16 pm

Lets say you are using P2[0], and you want to jump to a high or low routine. You can use a mask to filter the pin and then choose based on Z flag...

Code: Select all
pin_check::
  mov  A, reg[PRT2DR]  ; read port2
  and A, 0x01                 ; mask out unwanted pins
  jz  pin_low                    ; if pin low then jump to pin_low
                                       ; else fall through to pin_high

pin high:
  ;DO STUFF HERE IF PIN HIGH
  ret

pin_low:
  ;DO STUFF HERE IF PIN LOW
  ret


Remember to set port P2[0] to High-Z, pullup or pulldown to allow for input. Feeding Vcc or GND to a STRONG pin is NOT a good look!!!

Hope this is what you are after.

I would advise that you open up some of the example projects and look how the code operates. This can give some of the greatest insights to a person just starting out.

Paul. :)
User avatar
wrightpc
The Big Cheese
The Big Cheese
 
Posts: 736
Joined: Thu Jul 28, 2005 7:56 pm
Location: Christchurch, New Zealand

Postby lovell on Thu Feb 09, 2006 12:57 pm

Minor observation

pin_check::
mov A, reg[PRT2DR] ; read port2
and A, 0x01 ; mask out unwanted pins
jz pin_low ; if pin low then jump to pin_low
; else fall through to pin_high

pin high:
;DO STUFF HERE IF PIN HIGH
ret

pin_low:
;DO STUFF HERE IF PIN LOW
ret



On a jump there is no return. On a Call there is.
Bill Lovell
User avatar
lovell
The Big Cheese
The Big Cheese
 
Posts: 665
Joined: Sat Dec 20, 2003 6:15 am
Location: Maine, USA

Postby wes on Thu Feb 09, 2006 1:04 pm

The pullup and pulldown drive modes are very useful for inputs from switches. If you use the pullup or pulldown mode on an input, be sure to set the port pin to drive in the correct direction. If the port is set as pullup, then the port must be high to be an input. If the port is set as pulldown, then the port must be low to be an input.
For the P2[0] example wth pullup:
Code: Select all
or  reg[PRT2DR], 0x01  ; set P2[0] high to enable pullup

For the P2[0] example with pulldown:
Code: Select all
and  reg[PRT2DR], 0xfe ; set P2[0] low to enable pulldown

The knowledge base article "Basic fundamentals of GPIO" by mrzee is a great resource. Using the search function on this site will also find many discussions.

Wes
wes
The Big Cheese
The Big Cheese
 
Posts: 248
Joined: Sun Dec 14, 2003 1:37 am
Location: Washington

Postby wrightpc on Thu Feb 09, 2006 7:46 pm

lovell wrote:Minor observation

pin_check::
mov A, reg[PRT2DR] ; read port2
and A, 0x01 ; mask out unwanted pins
jz pin_low ; if pin low then jump to pin_low
; else fall through to pin_high

pin high:
;DO STUFF HERE IF PIN HIGH
ret

pin_low:
;DO STUFF HERE IF PIN LOW
ret



On a jump there is no return. On a Call there is.


Sorry, I wasn't clear. I was creating a function as an example that could be called that would process the pin based on input and then return.

Sorry for the confusion.

Paul. :)
User avatar
wrightpc
The Big Cheese
The Big Cheese
 
Posts: 736
Joined: Thu Jul 28, 2005 7:56 pm
Location: Christchurch, New Zealand

Postby johnjcl on Mon Feb 13, 2006 11:58 am

Thank´s all. The information is huge.
johnjcl
User avatar
johnjcl
Newbie
Newbie
 
Posts: 9
Joined: Fri Nov 11, 2005 11:57 am
Location: Colombia


Return to PSoC1 General

Who is online

Users browsing this forum: Bing [Bot] and 0 guests

cron