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

sirc ir receiver

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



Joined: 05 Jun 2013
Posts: 3
Location: pakistan

View user's profile Send private message

sirc ir receiver
PostPosted: Wed Jun 05, 2013 3:41 am     Reply with quote

hi
m building a multi channal remote control using sirc 12 bit protocol.... doing every thing right but m not able to get the result :/
m posting my code below plz give it a look

Code:
#include <16f877A.h>
#fuses HS,NOWDT,NOCPD,NOPROTECT,PUT,NOBROWNOUT
#use delay(clock=4M)

//------------------------------------------------------------------------------
#use fast_io(A)                           
#use fast_io(B)                           
#zero_ram

//-----------------------------------------------------------------------------------
#define one_min 1450               //no of counts to safely detect bit1
#define one_max 2200               //optimal @4 MHz is 1800
#define zero_min 600               //no of counts to safely detect bit0
#define zero_max 1440               //optimal @4 MHz is 1200






#byte portb=0x06
#byte portc=0x07
#byte portd=0x08
#bit led_4=portb.4
#bit led_5=portb.5
#byte PIR1=0x0c
#bit  ccp1f=PIR1.2


int16 fall;            // variable to save the period of space

int16 rec[12]={0,0,0,0,0,0,0,0,0,0,0,0};   // array to save the received code

int16 code1[12]={0,0,0,0,0,0,0,1,0,0,0,0};
int16 code2[12]={1,0,0,0,0,0,0,1,0,0,0,0};
int16 code3[12]={0,1,0,0,0,0,0,1,0,0,0,0};
int16 code4[12]={1,1,0,0,0,0,0,1,0,0,0,0};
int16 code5[12]={0,0,1,0,0,0,0,1,0,0,0,0};

int one=0,zero=0,start=0;
int ledz,ledo;
int i=0,n;


int8 but1=0;
int8 but2=0;
int8 but3=0;
int8 but4=0;
int8 but5=0;



#int_ccp1            // interrept of falling edge
void ccp1_int()         // start the interrept rountain
{
   fall=ccp_1;   
   setup_timer_1(t1_disabled);

      
//   if ((start_max>fall)&&(fall<start_min))
//   {
//      start+=1;
//   }
    if((fall<zero_max)&&(fall>zero_min))     
      {
         zero+=1;
         ledz=1;
      }
   
     if((one_max>fall)&&(fall>one_min))
      {
         one+=1;
         ledo=1;
      }
///////////////////////////////////////////recording values/////////////////////////////////////////////////   
      if((zero==1)||(one==1))      // if one or zero received, save it in rec array
      {
            if(zero==1)
            {
                rec[i]=0;
                  i++;
                  zero=0;
            }

            if(one==1)
         {
               rec[i]=1;
               i++;
               one=0;
         }
      
      }
///////////////////////////////////////////checking of codes///////////////////////////////////////////////   
if (i==12)
{
   start=0;
   i=0;
            for(n=0;n<=11;n++)
           {   
                  if (code1[n]== rec[n])
                  {
                     but1++;
                  }
                   if (code2[n]== rec[n])
                  {
                     but2++;
                  }
                  if (code3[n]== rec[n])
                  {
                     but3++;
                  }
                  if (code4[n]== rec[n])
                  {
                     but4++;
                  }
                  if (code5[n]== rec[n])
                  {
                     but5++;
                  }       
       }
}
   
/////////////////////////////////////making corrosponding outputs//////////////////////////////
//   
//
//////////////////////////////////////// button 1 conditions///////////////////////////////////
   if (but1==12)
   {
            output_high(PIN_D0);
   }
//////////////////////////////////////// button 2 conditions///////////////////////////////////
   if (but2==12)
   {
            output_high(PIN_D1);
         
   }
//////////////////////////////////////// button 3 conditions///////////////////////////////////
   if (but3==12)
   {
            output_high(PIN_D2);
   }
//////////////////////////////////////// button 4 conditions///////////////////////////////////
   if (but4==12)
   {
         if (led_4==1)
            output_low(PIN_B0);
            else
            output_high(PIN_B0);
         

   }
//////////////////////////////////////// button 5 conditions///////////////////////////////////
   if (but5==12)
   {
         if(led_5==1)
         output_low(PIN_B1);
         else
         output_high(PIN_B1);
               
   }
but1=0;
but2=0;
but3=0;
but4=0;
but5=0;   
goto again;

again:
      ccp1f=0;
      set_timer1(0);
      fall=0;
}   

 
void main()
{
   set_tris_b(0x00);   //set portb as output   
   set_tris_d(0x00);   //set portb as output
   set_tris_c(0x0f);   // set 4-portc as input
   portb=0x00;
   portd=0x00;
   portc=0x00;


   ledz=0;
   ledo=0;
   set_timer1(0);

   while(1)
   {
      setup_ccp1(ccp_capture_fe);   // capture the Rising edge
      ext_int_edge( H_TO_L );
      setup_timer_1(t1_div_by_1); // start timer1
     clear_interrupt(int_ccp1);
      enable_interrupts(int_ccp1);
      enable_interrupts(global);     
   }
}


   
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Jun 05, 2013 7:07 am     Reply with quote

Reduce your code to something like 10 lines which illustrate the problem.
Also tell what is wrong, and you may get some help.
I can't even start.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Jun 05, 2013 7:18 am     Reply with quote

Obvious comment, without looking very far, you don't want to be doing almost (if any) of the instructions you have in your 'main' loop, in a loop. Most have side effects (for instance setting up the timer1 prescaler clears it at the same time), so they will prevent the interrupt code for having any hope of working.
ext_int_edge, does nothing since you are not using int_ext.
Once the ccp edge is set, it remains set.
You don't want to be clearing the interrupt in the loop.
etc. etc...
moneeb



Joined: 05 Jun 2013
Posts: 3
Location: pakistan

View user's profile Send private message

PostPosted: Thu Jun 06, 2013 5:59 am     Reply with quote

ok..
i think i am getting some trouble in defining the time periods or calling of the interrupt and also in the main program..
Code:
#include <16f877A.h>
#fuses HS,NOWDT,NOCPD,NOPROTECT,PUT,NOBROWNOUT
#use delay(clock=4M)

//------------------------------------------------------------------------------
#use fast_io(A)                           
#use fast_io(B)                           
#zero_ram

//-----------------------------------------------------------------------------------
#define one_min 1450               //no of counts to safely detect bit1
#define one_max 2200               //optimal @4 MHz is 1800
#define zero_min 600               //no of counts to safely detect bit0
#define zero_max 1440               //optimal @4 MHz is 1200

and in this isr routine
Code:
#int_ccp1            // interrept of falling edge
void ccp1_int()         // start the interrept rountain
{
   fall=ccp_1;   
   setup_timer_1(t1_disabled);

      
   if ((start_max>fall)&&(fall<start_min))
   {
      start+=1;
   }
    if((fall<zero_max)&&(fall>zero_min))     
      {
         zero+=1;
         ledz=1;
      }
   
     if((one_max>fall)&&(fall>one_min))
      {
         one+=1;
         ledo=1;
      }
///////////////////////////////////////////recording values/////////////////////////////////////////////////   
      if(((zero==1)||(one==1))&&(start=1))      // if one or zero received, save it in rec array
      {
            if(zero==1)
            {
                rec[i]=0;
                  i++;
                  zero=0;
            }

            if(one==1)
         {
               rec[i]=1;
               i++;
               one=0;
         }

temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 06, 2013 6:05 am     Reply with quote

I googled 'sirc 12 bit protocol' and the 4th hit is right here in this forum !
Working code,so author says,
I'd looked at it, see how close it is to what you require.There may be some timing issues, but should really help you with your project.

hth
jay
moneeb



Joined: 05 Jun 2013
Posts: 3
Location: pakistan

View user's profile Send private message

PostPosted: Thu Jun 06, 2013 7:06 am     Reply with quote

i also think that the problem lies with in the timing issue :/
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