problem with inputs on the 16F876A

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Raven
Posts: 1
Joined: Thu Jul 06, 2006 7:38 pm
Contact:

problem with inputs on the 16F876A

Post by Raven »

Hi, my name is Steve... I had been running an LCD program with the 16F84A, but eventually my program was too long and I needed to upgrade to a larger chip. I've been trying to use the 16F876A, but it seems the inputs do not work. The LCD routines work fine though. I ditched that program for a while and tried a very simple program just to get the inputs working. It worked fine with the other chip but not with this one. Here is the program...

#include <system.h>
void main (void)
{
set_tris_a (0xff);
set_tris_b (0x00);
while (1)
{
if (input_pin_port_a(0))
{
output_high_port_b(0);
}
else
{
output_low_port_b(0);
}
if (input_pin_port_a(1))
{
output_high_port_b(1);
}
else
{
output_low_port_b(1);
}
if (input_pin_port_a(2))
{
output_high_port_b(2);
}
else
{
output_low_port_b(2);
}
if (input_pin_port_a(3))
{
output_high_port_b(3);
}
else
{
output_low_port_b(3);
}
if (input_pin_port_a(4))
{
output_high_port_b(4);
}
else
{output_low_port_b(4);
}
if (input_pin_port_a(5))
{
output_high_port_b(5);
}
else
{output_low_port_b(5);
}
if (input_pin_port_a(6))
{
output_high_port_b(6);
}
else
{output_low_port_b(6);
}
if (input_pin_port_a(7))
{
output_high_port_b(7);
}
else
{output_low_port_b(7);
}
}
}


For some reason, pin #4 works, but none of the others do. When I push the inputs on port A(except for 4), none of the port B outputs light up. What could be causing these inputs to not be read?
Thanks

Ian
Posts: 110
Joined: Thu Sep 29, 2005 10:53 am
Location: Matrix Multimedia
Been thanked: 1 time
Contact:

Post by Ian »

Have you turned the analogue ports off?

the 16F87X devices have analogue inputs on Port A which are on by default and need turning off for digital input.

Try adding an ADCON line to the start of your program to turn the ADC lines off e.g.:

adcon1 = 0x07;

Post Reply