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.

reading output of IR receiver with pic16f690 micrcontroller

Status
Not open for further replies.
reading output of IR receiver with pic16f690 micrcontroller

im designing an infrared proximity detector for my project. I am a new user to the pic microcontroller.

I am programming in C.

i have an infrared receiver IC TSOP48.
the output of the infrared ic is active low. and can be directly demodulated by a microcontroller.

the output is on the 1st pin of the receiver module.


hardware connections:

1)pin 1 of receiver IC connected to RC2
2)in RC3 has a LED connected to it going to ground.

1)i want to feed this active low signal from the receiver IC to pin RC2 of the microcontroller when

detection occurs.

2)only when the receiver IC detects an object is near, then it will be active low.
So i want to read this pin RC2 to check if it is low.

3)now only when it is active low i want a LED connected to RC3 to light up.

4)if the module does not detect any object then i want the led to be off.




here is my code:
#include <pic.h>
#include "pic.h"
#include "delay.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>

void main(void)
{

TRISC=0X04; //making pin RC2 input

if(RC2==0) //if receiver detects something then output is active low
{PORTC=0x08;} //light up led connected to RC3 if detect object else
{PORTC=0x00;} //dont light led if no detection
}


please assist me. i dont know why the led is always on after i program the chip and put it into the

proximity circuit.

i want it to go on when an object is near the proximity circuit.

i want it to go off when there is no object near.
 
If that is the exact program you wrote, it only works once. You have to write it inside a loop for continuous checking..


void main(void)
{

TRISC=0X04;
while(1){
if(RC2==0)
{PORTC=0x08;}
else
{PORTC=0x00;}
}
}
 
here is my code:
#include <pic.h>
#include "pic.h"
#include "delay.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>

void main(void)
{

TRISC=0X04; //making pin RC2 input

if(RC2==0) //if receiver detects something then output is active low
{PORTC=0x08;} //light up led connected to RC3 if detect object else
{PORTC=0x00;} //dont light led if no detection
}
1. You need to clear the ANSEL register to make the PORTC pins digital as opposed to analog inputs.

2. You need an "else" in your if statement, otherwise the LED will be modulated on and off.

3. You need a loop so the uC will poll continuously.

So...

Code:
void main(void)
{
ANSEL=0;        // Set inputs to digital
TRISC=0x04;				//making pin RC2 input

while(1)                        //  Loop forever
  {
  if(RC2==0)          		//if receiver detects something then output is active low
       {PORTC=0x08;}	//light up led connected to RC3 if detect object
  else 
       {PORTC=0x00;}	//dont light led if no detection
  } 
}

(Actually, maybe you did have the "else" in there but it was at the end of the previous line when you posted the code...)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top