Continue to Site

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.

  • 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]

Status
Not open for further replies.

Naren Rover

New Member
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;
}
}

}
 
yes i used a pull up.. i have attached schematic please see it
 

Attachments

  • Capture.PNG
    Capture.PNG
    59.5 KB · Views: 269
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.
 
Thanks Ian . I got the Correct output , I did in actual Hardware and it was working fine . the problem was with PROTEUS
 
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!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top