CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Infrared

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Infrared
PostPosted: Thu Jan 27, 2005 3:58 pm     Reply with quote

I am trying to talk between 2 PIC (PIC16F877) through infrared. Can I use the USART port build-in with the PIC to communicate with IR?

My connection is:

Xmitr-------------Receiver
PIC1 -------------PIC2
TX-RC6-----------RX-RC7


I use the Panasonic PNA4602M as the receiver and use the TSAL6100 IRLED (240 ohm current limit resistor) as the xmitr with 38Khz PWM from RC2.

Anyone has a sample code to send out serial data(ADC in ch0) from the Xmitr and a sample code to receive the data and display it in PORTD (8 LEDs in PORTD).

I got the PWM, Duty Cycle, ADC routing working fine. I can talk it to a PC with a Max232, but can not talk to another PIC.

Please help...

Thanks
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Thu Jan 27, 2005 5:14 pm     Reply with quote

What do you mean by you got the PWM and duty cycle working fine?
Using the PWM in the PIC you have to make a carrier frequency of 38kHz on the LED that can be switched on/off to make 38KHz square wave (with a constant duty cycle of 50%) bursts of various length in time.
What do you mean you can talk to a PC? you mean the PC serial port? a serial port requires no carrier frequency of 38kHz.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Infrared
PostPosted: Thu Jan 27, 2005 5:40 pm     Reply with quote

Anonymous wrote:
I am trying to talk between 2 PIC (PIC16F877) through infrared. Can I use the USART port build-in with the PIC to communicate with IR?

My connection is:

Xmitr-------------Receiver
PIC1 -------------PIC2
TX-RC6-----------RX-RC7


I use the Panasonic PNA4602M as the receiver and use the TSAL6100 IRLED (240 ohm current limit resistor) as the xmitr with 38Khz PWM from RC2.

Anyone has a sample code to send out serial data(ADC in ch0) from the Xmitr and a sample code to receive the data and display it in PORTD (8 LEDs in PORTD).

I got the PWM, Duty Cycle, ADC routing working fine. I can talk it to a PC with a Max232, but can not talk to another PIC.

Please help...

Thanks


Then the problem sounds like it is with the PIC receive routine. Post your code.
Guest








infrared ::: PIC to PIC communication
PostPosted: Thu Jan 27, 2005 8:55 pm     Reply with quote

Here is the code

RECEIVER CODE:

Code:
// This is the receiver code ////
//
//


#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7) 


main()
{
   unsigned c;
   set_tris_d(0x00);
   output_d(0x00);
   while(1)
    {     
                         
        c=getc();
      output_d(c);
      
      
    }

}



Here is the Transmitter code:
Code:
//
//   Use a 20Mhz crystal
//   
//   Connection as follow:
//   Config. TX pin to B1
//   Connected the Anode of IRLED to B1(data pin), Cathode of IRLED connected to a 240 Ohm resistor
//   as current limit resistor, the other end of the resistor connected to C2 which
//   is PWM pin (38Khz PWM).


#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=1200, xmit=PIN_b1) 


main()
{

   unsigned c;
   output_low(pin_a5);         // to turn on LED indicate pwr is applied
   output_low(PIN_B1);         //Reset pin b1
   output_low(PIN_C2);          // Set CCP1 output low

   setup_ccp1(CCP_PWM);         // Configure CCP1 as a PWM
   setup_timer_2(T2_DIV_BY_1, 130, 1);  // setup for 38khz  base on 20 Mhz crystal
   set_pwm1_duty(65);                   // 50% duty cycle  (PR2 = 65 )


   
   
   setup_adc_ports( ALL_ANALOG );   // Setup ADC converstion
   setup_adc( ADC_CLOCK_INTERNAL );
   

   while(1)
   {   
      set_adc_channel( 0 );       // Use channel 0
      delay_ms(20);
      c = read_adc();
      delay_ms(20);
    
      printf("%u",c);         // Send data out

    }
                                   
 

}
Guest








PostPosted: Thu Jan 27, 2005 9:08 pm     Reply with quote

Yes, the transmitter can send data wirelessly and I have the right data display in the hyperterminal.

What I have is a demo 2 plus board which build-in with the max232 converter to PC RS 232.

The Panasonic receiver module pin out as follow

Receiver
Connection as follow:

/---------\
| --------- |
| --------- |
------------
| | |
| | |
/ | \
1 2 3
out Gnd 5V

Connect Output pin to( pin RC6 on demo 2 plus brd) which is Max232 Tin 1. When I open the hyperterminal, I got the right data display. I can't get it to talk to another PIC.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Fri Jan 28, 2005 4:09 am     Reply with quote

Quote:
Connect th Panasonic's Output pin to( pin RC6 on demo 2 plus brd)

I suppose it is just a typo in your post (would be too easy :-): the PICs receive pin is the RC7 rather than the RC6.
Guest








Infrared serial communication.
PostPosted: Fri Jan 28, 2005 7:15 am     Reply with quote

It is right, the RC6 is the input pin to the Max232 (per sch of demo 2 plus
board). So if I connect the output of the infrared receiver to the
RC6, then I have the result display in the hyperterminal.

But if I connect it to RC7 which is input to PIC (RX) and I try to echo what ever
coming on RC7 to PC rs 232, then I got nothing. I've try to display the data
received at pin rc7 to port D, I got nothing either.


What did I do wrong?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 28, 2005 7:29 am     Reply with quote

Get rid of the IR for now until you get the receive working. Connect the other PIC or the PC to the receive PIC and do your testing. You should add the ERRORS parameter to the #use rs232 statement or the receive can stop working since you are not handling the buffer overflow error.
Guest








infrared serial comm
PostPosted: Fri Jan 28, 2005 9:08 am     Reply with quote

Razz Laughing Thanks for everyone support. Laughing Very Happy

Arrow Arrow I got it work fine now.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 28, 2005 9:27 am     Reply with quote

So what was the problem?
Guest








infrared
PostPosted: Fri Jan 28, 2005 10:52 am     Reply with quote

Laughing the variable (unsigned c;) should be ( byte c;)
Very Happy and always use putc() instead of printf().
Arrow For both the receiver and transmitter
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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