• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem With PIC16F886 Port Read[URGENT]

Thread starter #1
Hi Guys.I need help with this Program I'm using PIC16f886 controller
when I press a push Button a LED should blink , the program works fine
the button is connected to pin RB3 and LED to pin RA2.
Problem arises when i set Analog pin
when i enable analog pin AN11 which is in RB4, RB3 is not sensing Button Press.
i have attached the program can someone help me.. thank you

#include <xc.h>
#define BUTTON RB3
#define LED RA2
void main(void)
{
PORTA=0x00;
PORTB=0x00;
TRISA=0x00;
TRISB=0x18; //setting RB4(AN11),RB3 as inputs
ANSEL=0X00;
ANSELH=0X08; // enabling Analog pin AN11 pin
// ANSELH=0X00;
// RB3 senses button when analog pin is disabled which is in RB4
while(1)
{
if(BUTTON==0)
{
LED=1;
}
else
{
LED=0;
}
}

}
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#7
Okay!!! I think this is a "Protues" issue... ANSELH bit 4 is selecting RB3 instead of RB4..

I have posted a note on Labcenter, Ettore will answer soon... As a quick fix use ANSELH = 0x10; as they seem to match the port bit by mistake.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#9
Thanks Ian . I got the Correct output , I did in actual Hardware and it was working fine . the problem was with PROTEUS
Yes! I used MPLAB sim and its working fine in that!
 

Latest threads

EE World Online Articles

Loading

 
Top