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.

Programming PICC through MPLAB

Status
Not open for further replies.
Ok..... So... interesting phenomenon (which is only labeled that because I can't explain it)...

My code is as follows
Code:
#include<16f872.h>
#fuses HS,NOWDT,NOPROTECT,PUT
#use DELAY(clock=8000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

void main(){
   //Now I'm gunna clear all ports just to make sure that they're not interfering
   set_tris_a(0x00);
   set_tris_b(0x00);
   set_tris_c(0x00);
   /*Now gunna initialize the ports in the order I actually need them
   /*As a note, I'm going to do this in binary to make sure ONLY the ports
   /*I need are going to operational
   */
   set_tris_a(0b00000001); //Set PIN_A0 input, all else output
   set_tris_b(0x00);       //Set ALL port B output

while (1)
{
  if (input(PIN_A0))
  {
      output_low(PIN_B6);
  }
  else
  {
      output_high(PIN_B6);
  }
}
}

That's all of it, from directives to final curly brace. I have the board wired up and an LED in place. When I remove all stimulus on pin A0, the LED shines bright with no fluctuations, however, when even just a wire is tied to pin A0, it seems to act as a proximity sensor of some sort O.O The LED turns off whenever anything is moved near it, and the radius seems fairly constant once again.

What did I do? Is it the aliens?

Moreover, how can I make it STOP doing this so I can perhaps finish my project? *sigh*

EDIT: I've tried switching what pin I'm using as input, and the same weird effect occurs
 
Last edited:
You appear to have A0 floating, that is, not connected to anything. When you place anything near it, it will pick up stray voltages like the mains hum. This is what would be expected.

What did you expect would happen?

Mike.
 
Pommie said:
You appear to have A0 floating, that is, not connected to anything. When you place anything near it, it will pick up stray voltages like the mains hum. This is what would be expected.

What did you expect would happen?

Mike.

Ok... now I feel like a newbie because, while the words make sense, they don't make sense to me in that order. What would the proper code look like, then? Or is it not a problem with the code and instead a problem with my circuit?
 
Yes, it is
not a problem with the code and instead a problem with my circuit?

What they are telling you to do is connect A0 to +5V with a pull-up resistor ~1k to 10k, then connect your switch between A0 and ground. This way the input will not float, but will be at a logic high when the switch is open, and logic low with the switch closed.
 
Thank you all so much, the circuit is working like a dream now. If I have any more questions (not too likely, 'cause it seems to be all set now) I won't hesitate to ask.

You've all been so helpful, thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top