Page 1 of 1

how to read the input ports

Posted: Fri Apr 25, 2008 1:54 pm
by saravana_3
Hi all
I am using the 16f877a, I set the port A as the input and PortB as the output,
in "c" 'how to scan when any of the portA buttons are pressed
please give some Idea, I want to control the PortB by the portA
thanks
Saran

Re: how to read the input ports

Posted: Fri Apr 25, 2008 3:42 pm
by Benj
hello Saran

Essentially you can just read porta into a variable by doing the following.

Code: Select all

char input;
input = porta;
Then you can create a loop like this to detect when porta changes its value.

Code: Select all

char oldinput;
oldinput = input
while (oldinput == input)
{
    input = porta;
}
Testing a single bit or switch can can be done as follows.

Code: Select all

if (test_bit(porta, 0))
{
//RA0 Set
}
else
{
//RA0 Clear
}