Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need Help Regarding Rs232?

Status
Not open for further replies.

sarmad_101

Member level 3
Joined
Sep 18, 2008
Messages
56
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
GERMANY
Activity points
1,658
I want to send data to computer to check that remote is sending rite data or not. Need Help about RS232 programing.
how can i send data from this program to computer.
The remote is using RC5 protocol.



Please anybody help me out.

:|

Code:
#include <18F252.h>
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_C7)

int1 get_RC5(void);


#define IR_INPUT PIN_B0         // the infrared receiver has to be connected to an
                                // interrupt-pin!

#define IR_STATUS (!input(IR_INPUT))  // invert the signal from the infrared receiver



typedef struct
{
int8 data[2];
int8 state;
} rc5_struct;
rc5_struct rc5;

#int_EXT
EXT_isr()
{
   get_RC5();
}

int1 get_RC5(void)
{
   int16 tmp,t;
   int i;
   int1 inp;

   set_timer1(0);
   while(IR_STATUS==1);
   t=get_timer1();

   if ((t<400) || (t>800)) return 0;   // no RC5 code, abort decoding

   for (i=0;i<13;i++)
   {
      inp=IR_STATUS;
      set_timer1(0);

      while (IR_STATUS==inp)
      {
         t=get_timer1();
         if (t>800) return 0;   // no RC5 code, abort decoding
      }

      tmp<<=1;

      if (inp==0) tmp++;

      set_timer1(0);
      while (get_timer1()<776);  // a simple delay would work here as well
   }

   tmp=tmp | 0x3000;
   tmp=tmp & 0x37ff; // cut off togglebit

   rc5.data[0]=tmp & 0xff;  // device address
   tmp>>=8;
   rc5.data[1]=tmp & 0xff;  // command code

   rc5.state = 1;

   disable_interrupts(INT_EXT);

   return 1;
}




void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   rc5.state = 0;

   while(1)
   {
      if(rc5.state==1)  // did we receive a valid RC5 - command?
      {
         // interprete the command here...

         rc5.state = 0;
         enable_interrupts(INT_EXT);
      }

   }


}
 

What issues you are facing with this program?

Let me know the issues than only we can understand.

Regards
Chanchal
 

I burn that program in the PIC18F252 and by using max232 i send the data to the PC but did not get any output at the hyper terminal. The remote send data to the IR and the IR is connected to the PIC PIN RBO and C6=Tx and C7=Rx.


I made some changes in this code and the new code is given below.


Code:
#include <18F252.h>
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_C7)

int1 get_RC5(void);


#define IR_INPUT PIN_B0            // the IR-Decoder has to be connected to an interrupt pin

#define IR_STATUS (!input(IR_INPUT))   // invert signal from IR-Receiver

typedef struct
{
int8 data[2];
int8 state;
}
rc5_struct;
rc5_struct rc5;


// interrupt function for external interrupt pin

#int_EXT
EXT_isr()
{
   get_RC5();
}



// RC5 decoding

int1 get_RC5(void)
{
   int16 tmp,t;
   int i;
   int1 inp;

   set_timer1(0);                      // reset timer
   while(IR_STATUS==1);            
   t=get_timer1();                  
   if ((t<400) || (t<800)) return 0;   // no RC5 code, cancel decoding


// receive all 13 data bits
   
   for (i=0;i<13;i++)
   {
      inp=IR_STATUS;               
      set_timer1(0);               

      while (IR_STATUS==inp)         
      {
         t=get_timer1();            
         if (t>800) return 0;      // timing wrong -> no RC5
                              
      }

      tmp<<=1;                     

      if (inp==0) tmp++;            

      set_timer1(0);
      while (get_timer1()<776);  
   }

   tmp=tmp | 0x3000;                  // clear Bits 13,14 & 15

   tmp=tmp & 0x37ff;                  // cut off Togglebit 

   rc5.data[0]=tmp & 0xff;            // extract device address

   tmp>>=8;               

   rc5.data[1]=tmp & 0xff;           // extract command code

   rc5.state = 1;                    // set flag for successful IR command decoding

   disable_interrupts(INT_EXT);      // disable Interrupts until received command has been processed

   return 1;
}




void main()
{
   // controller initialisieren
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);   // timer1 is used for RC5-decoding. When the chip runs @ 20MHz, 
                     
   // a prescaler of 8 has to be used
   
   setup_timer_2(T2_DISABLED,0,1);
   //setup_comparator(NC_NC_NC_NC);
   //setup_vref(FALSE);

   // enable interrupts 
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   rc5.state = 0;

   while(1)
   {
      if(rc5.state==1)              
      
      // did we receive a valid command?
      {
      
      printf("Device: %u\n", rc5.data[0]);     // display device address
      printf("Command: %u\n", rc5.data[1]);    // display command code

      rc5.state = 0; 
      enable_interrupts(INT_EXT);   // reenable interrupts
      
      }

   }


}
 

Do you have a MAX232 or sth like that between PIC uC and a PC serial port?
Do you have an oscilloscope to check signals on uC pins, before PC serial port?
 

Hi,
Before using the PIC I advise to work step by step.

1- Prepare you signal converter: Look for some schemtics on the net on how to use a max 232.
**broken link removed**
2- After powering your circuit do a loop at the TTL side of the max232 and use Hyperterminal to read and write characters.
3- If your circuits is ok and you could send and receive data, Swith off power, connect the PIC and switch on the power again.
4- Normally If your code is ok you should be able to communicate with the PIC, else, in you code check the baudrade, IO direction, pull up resistors etc.
 

The Site you have provided is not in English.
I don't understand what is written on that site.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top