![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
conoral11
Joined: 05 Jun 2010 Posts: 5
|
PIC16F628a Reading from Port B ok, but port A doesn't work |
Posted: Wed Oct 20, 2010 3:05 pm |
|
|
Hi There, I've got a PIC16f628a connected to a LCD with flex_lcd, and it works well (its also very useful in debugging). This is connected to pin b0-b3 and a2-4.
I've got a pin, (B4) monitoring when a switch closes which works using
input(PIN_B4)
However, pins A0,A1,A6 and A7 are each individually connected to a switch that connects to +5v. When no switch is connected the output fluctuates between high and low, even thought the voltage across said pin is never more than 0.03v
What am I doing wrong? Pin B4 circuit connects via a switch to PIN B5 for its voltage source with pin_B5 being driven high by code.
Below is my code:
Code: | #include "16F628a.h"
#fuses NOWDT, NOPROTECT, NOBROWNOUT, INTRC_IO
#use delay(clock=4000000)
#include "flex_lcd.c"
void main()
{
setup_comparator(NC_NC_NC_NC);
delay_ms(200);
lcd_init();
output_high(PIN_B5);
for(;;)
{
//printf(lcd_putc, "\f%d", input(PIN_A1));
if(input(PIN_B4))
{
printf(lcd_putc, "\fInput LID");
}
delay_ms(100);
}
} |
This works when I operate the switch attached to PIN B4 and B5
But when I use
Code: | #include "16F628a.h"
#fuses NOWDT, NOPROTECT, NOBROWNOUT, INTRC_IO
#use delay(clock=4000000)
#include "flex_lcd.c"
void main()
{
setup_comparator(NC_NC_NC_NC);
delay_ms(200);
lcd_init();
output_high(PIN_B5);
for(;;)
{
printf(lcd_putc, "\f%d", input(PIN_B4));
delay_ms(100);
}
} |
It fluctuates between 1 and 0 when the switch isn't closed. Even when I remove the switch altogether the same problem arises. Using the switch with the working b4 and B5 pins shows that the switch is in full working order.
I've replaced the PIC to make sure no ports have been damaged.
Have I missed something in the implementation of my hardware?
Conoral11 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 20, 2010 3:17 pm |
|
|
The standard method of connecting switches is shown below.
The pull-up resistor creates an idle state which is a logic high level.
When the switch is pressed, it creates a logic low level.
The PIC pin can read these states and tell whether the switch
is released or pressed.
Code: | +5v
|
<
> 4.7K
< ___ Switch
To | _|_|_
PIC -----------------o o------
pin |
--- GND
-
|
I suggest that you re-wire your external switch circuits so they look like
this. Change your code to look for a low level, to detect a pressed switch. |
|
![](templates/subSilver/images/spacer.gif) |
conoral11
Joined: 05 Jun 2010 Posts: 5
|
|
Posted: Wed Oct 20, 2010 3:20 pm |
|
|
I had a feeling that was my problem.
Thank you for taking your time to answer my question.
All the best
Conoral11 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|