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.

Sony Protocol C Code Help

Status
Not open for further replies.

Suraj143

Active Member
I wrote a code to decode sony remotes 7 bit command code & display the code in PORTB LEDs.But the below code won't work.

Code:
while(1){
             capture_data();
             PORTB = cmd_byte;
             }




//PORTC.B2 = IR Input
void capture_data(){
unsigned short bit_counter, mask_byte;
unsigned int settle_time;

wait_Loop:
   if(PORTC.B2>0){
             settle_time++;
             delay_uS(1);
             delay_uS(1);
             if(settle_time==0)
             IR_Flag_Register = 0b10000000;  //new key flag
             return;
              }

Read_IR();
    if (((IR_Flag_Register & 0b01111111) & 0b00001000) ==0)        //start bit detect??
         goto  wait_Loop;                          //not recieved start bit
        cmd_Byte = 0x00;
        mask_byte = 0b00000001;
        bit_counter = 1;
Next_Rcvbit:
        Read_IR();
        if((IR_Flag_Register & 0b00001001) > 0)goto wait_Loop; //re-capture if error
        if((IR_Flag_Register & 0b01111111)== 0b00000100)
           cmd_Byte = cmd_byte | mask_byte;
        mask_byte = mask_byte<<1;
        bit_counter++;
        if(bit_counter!=8)goto Next_Rcvbit;
        }
//==================================================
void Read_IR(){
unsigned int deltime = 0;
width = 0;

still_High:  if(PORTC.B2>0){
             deltime++;
             //if(deltime!=0)goto still_High;
             //{
              //IR_Flag_Register = IR_Flag_Register | 0b00000001;  //error flag
              //return;}
              }
measure: delay_uS(1);   //high pulse detected
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         delay_uS(1);
         width++;
         if(PORTC.B2==0) goto measure;
         check_pulse();
         }
         
void check_pulse(){
 IR_Flag_Register = IR_Flag_Register & 0b10000000;
 
 if ((width>20) && (width<45) ){   //320-720
 IR_Flag_Register = IR_Flag_Register | 0b00000010;   //zero flag  }
 return;}
 if ((width>45) && (width<90) ) {  //720-1440
 IR_Flag_Register = IR_Flag_Register | 0b00000100;   //ones flag
 return;}
 if ((width>140) && (width<160) ) {  //2240-2560
 IR_Flag_Register = IR_Flag_Register | 0b00001000;   //start flag
 return;}
 if (width<20) {                   //<320
 IR_Flag_Register = IR_Flag_Register | 0b00000001;   //error flag
 return;}
 if (width>200){                   //>3200
 IR_Flag_Register = IR_Flag_Register | 0b00000001;   //error flag
 return;}
 }
 
Hi nigel I earlier used your asm codes & it worked well.

The same principal I converted to C but the above didn't work.I think I have a C code problem.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top