Input button test 18F4520

Status
Not open for further replies.

prasad70

Member level 3
Joined
Mar 24, 2011
Messages
67
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Visit site
Activity points
1,690
Can someone please explain a code testing input button of Pic184520. I used below codes but it didnt work

#define Sw1 LA7
#define Sw2 LA6
TRISA = 0b11111111 ;
while(!Sw1)
{
Do sth
}
thks
 

What compiler you are using?

You code is incomplete. That's why it won't compile and it is not working.
 

I am sorry for not mentioning compiler. It's HITEC C PRO PIC18.

I just mentioned only the part of the code I used for the project. Code was compiled and worked well except function I used for input button test. What I could notice was that Input button was not detected. Circuit works well with 16F887 MC.
What I want is to get an idea on checking input button.

thks
 
Last edited:

First, You have to configure the pin as digital input.
Then check the pin in the while loop as LOW or HIGH. Depends on your hardware connection.
If LOW , do something there.
Else not pressed, do some other thing.

Only problem could be, i think you didn't configure the pin as digital input. Try it.

Best wishes
 

I cinfigured port as inputs

CMCON =0b000001 ; // comparator off
ADCON0 = 0b00000001 ;
ADCON1 = 0b00001010 ;
TRISA = 0b11111111 ;
thk
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…