problem reading from a pin

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
edg962
Posts: 27
Joined: 06 Dec 2008 04:46

problem reading from a pin

#1 Post by edg962 » 28 Feb 2011 22:57

Gentlemen,

Not sure why the following occurs. When I check with my meter, I get 5V (switch open) and 0V (switch closed), which is the way it should be. However, when I attempt to test the pin for a high or a low, it does not work for me. For example, having a switch connected to PortB.2 and ground, I tried the following simple code:

Code: Select all

main:

DDRB = 0x00  'inputs
PORTB = 0XFF 'all highs

If PortB.2 = 0 then
    'Display B2 is low  (some statements here)
endif
If PortB.2 = 1 then
    'Display B2 is high  (some statements here)
endif

end.
I get PORTB.2 as high all the time in the program. Shouldn't it automatically go to low when the switch is pressed and back to a high when it is released? Again, when I check with the meter, I correctly get 5V when switch is not pressed, and 0V when switch is pressed.

I need your help, please. Anything will be greatly appreciated. Thanks in advance.

foravr
Posts: 130
Joined: 11 May 2009 19:34

Re: problem reading from a pin

#2 Post by foravr » 09 Mar 2011 09:08

It has been answered about 10000 times!
change:
if pinB.2 then....

edg962
Posts: 27
Joined: 06 Dec 2008 04:46

Re: problem reading from a pin

#3 Post by edg962 » 11 Mar 2011 18:57

Thanks for the reply. I had already found out the solution.

Post Reply

Return to “mikroBasic PRO for AVR General”