1

Тема: IRemote

bool data[96];
unsigned long cod;
int i,i2;


void setup() {
  Serial.begin(9600);
  DDRB &= ~(1 << 0);
   cli(); 
  TCCR1A = 0;   
  TCCR1B = 0;   
  OCR1A = 9000; // 562.5 mks
  TCCR1B |= (1 << WGM12); 
  TCCR1B &= ~(1 << CS10);  
  TIMSK1 |= (1 << OCIE1A);  
   sei(); 
 
}

void loop() {

  Serial.println(IR(),HEX);
 // delay(100);

  }

uint32_t IR(){
 while(PINB & (1 << 0));
 delay(10);
 while(PINB & (1 << 0));
 
 TCCR1B |= (1 << CS10);  
 delayMicroseconds(100);
 delay(136);
 cod=0;i2=0;
for(int a=0;a<96;a++){
  if(data[a] + data[a+2] == 2){cod += ((uint32_t)0 << 31-i2);i2++;a=a+1;}
  if(data[a] + data[a+2] == 1){cod += ((uint32_t)1 << 31-i2);i2++;a=a+3;}}

 return cod;
  }


ISR(TIMER1_COMPA_vect){

     data[i]=((PINB >> 0) & 1);i++; 
     if(i>96){TCCR1B &= ~(1 << CS10);i=0;}
     }

2

Re: IRemote

bool data[96];
uint32_t cod,h;
int i,i2,s,st,raz;


void setup() {
  Serial.begin(9600);
  DDRB &= ~(1 << 0);
   cli(); 
  TCCR1A = 0;   
  TCCR1B = 0;   
  OCR1A = 9000; // 562.5 mks
  TCCR1B |= (1 << WGM12); 
  TCCR1B |= (1 << CS10);  
  TIMSK1 |= (1 << OCIE1A);  
   sei(); 
 
}

void loop() {

if(raz==1){  Serial.println(IR(),HEX);}
  }

uint32_t IR(){
 delay(75);
 cod=0;i2=0;
 for(int a=0;a<96;a++){
   if(data[a] + data[a+2] == 2){cod += ((uint32_t)0 << 31-i2);i2++;a=a+1;}
   if(data[a] + data[a+2] == 1){cod += ((uint32_t)1 << 31-i2);i2++;a=a+3;}}
 raz=0;
 TCCR1B |= (1 << CS10);OCR1A = 150;
 if(cod==1){cod=0xFFFFFFFF;}
 return cod;}
  


ISR(TIMER1_COMPA_vect){
     if(((PINB >> 0) & 1)==0&&st==0&&raz==0){st=1;OCR1A = 9000;}
     if(st==1){s++;}   
     if(s>24){data[i]=((PINB >> 0) & 1);i++;} 
     if(i>96){i=0;s=0;st=0;raz=1;TCCR1B &= ~(1 << CS10); }
     }

3

Re: IRemote

bool data[96];
uint32_t cod;
int i,i2,s,st,raz;


void setup() {
  Serial.begin(9600);
  DDRB &= ~(1 << 0);
   cli(); 
  TCCR1A = 0;   
  TCCR1B = 0;   
  OCR1A = 9000; // 562.5 mks
  TCCR1B |= (1 << WGM12); 
  TCCR1B |= (1 << CS10);  
  TIMSK1 |= (1 << OCIE1A);  
   sei(); 
 
}

void loop() {

if(raz==1){  Serial.println(IR(),HEX);}
  }

uint32_t IR(){
 delay(110);
 cod=0;i2=0;
 for(int a=0;a<96;a++){
   if(data[a] + data[a+2] == 2){cod += ((uint32_t)0 << 31-i2);i2++;a=a+1;}
   if(data[a] + data[a+2] == 1){cod += ((uint32_t)1 << 31-i2);i2++;a=a+3;}}
 raz=0;
 TCCR1B |= (1 << CS10);OCR1A = 500;//32000 kHz
 if(cod==1){cod=0xFFFFFFFF;}
 return cod;}
  


ISR(TIMER1_COMPA_vect){
     if(((PINB >> 0) & 1)==0&&st==0&&raz==0){st=1;OCR1A = 9000;}
     if(st==1){s++;}   
     if(s>24){data[i]=((PINB >> 0) & 1);i++;} 
     if(i>96){i=0;s=0;st=0;raz=1;TCCR1B &= ~(1 << CS10); }
     }

4

Re: IRemote

bool data[96];
uint32_t cod;
int i,i2,s,st,raz,st1;


void setup() {
  Serial.begin(9600);
  DDRB &= ~(1 << 0);
   cli(); 
  TCCR1A = 0;   
  TCCR1B = 0;   
  OCR1A = 9000; // 562.5 mks
  TCCR1B |= (1 << WGM12); 
  TCCR1B |= (1 << CS10);  
  TIMSK1 |= (1 << OCIE1A);  
   sei(); 
 
}

void loop() {

if(raz==1){  Serial.println(IR(),HEX);}
  }

uint32_t IR(){
 delay(110);
 cod=0;i2=0;
 for(int a=0;a<96;a++){
   if(data[a] + data[a+2] == 2){cod += ((uint32_t)0 << 31-i2);i2++;a=a+1;}
   if(data[a] + data[a+2] == 1){cod += ((uint32_t)1 << 31-i2);i2++;a=a+3;}}
 raz=0;
 TCCR1B |= (1 << CS10);OCR1A = 3200;//5000 kHz
 if(cod==1||cod>0xffffff){cod=0xFFFFFFFF;}
 return cod;}
  


ISR(TIMER1_COMPA_vect){
     if(((PINB >> 0) & 1)==0&&st==0&&raz==0){st=1;OCR1A = 9000;}
     if(st==1){s++;}
     if(s>20&&((PINB >> 0) & 1)==0){st1=1;}   
     if(st1==1){data[i]=((PINB >> 0) & 1);i++;} 
     if(i>96){i=0;s=0;st=0;raz=1;st1=0;TCCR1B &= ~(1 << CS10); }
     }

5

Re: IRemote

bool data[96],st,st1,raz;
uint32_t cod;
byte i1,i2,s;


void setup() {
  Serial.begin(9600);
  DDRB &= ~(1 << 0);
   cli(); 
  TCCR1A = 0;   
  TCCR1B = 0;   
  OCR1A = 9000; // 562.5 mks
  TCCR1B |= (1 << WGM12); 
  TCCR1B |= (1 << CS10);  
  TIMSK1 |= (1 << OCIE1A);  
   sei(); 
 
}

void loop() {

if(raz==1){  Serial.println(IR(),HEX);}
delay(200);
  }

uint32_t IR(){
 delay(110);
 cod=0;i2=0;
 for(int a=0;a<96;a++){
   if(data[a] + data[a+2] == 2){cod += ((uint32_t)0 << 31-i2);i2++;a=a+1;}
   if(data[a] + data[a+2] == 1){cod += ((uint32_t)1 << 31-i2);i2++;a=a+3;}}
 raz=0;
 TCCR1B |= (1 << CS10);OCR1A = 3200;//5000 kHz
 if(cod==1||cod>0xffffff){cod=0xFFFFFFFF;}
 return cod;}
  


ISR(TIMER1_COMPA_vect){
     if(((PINB >> 0) & 1)==0&&st==0&&raz==0){st=1;OCR1A = 9000;}
     if(st==1){s++;}
     if(s>20&&((PINB >> 0) & 1)==0){st1=1;}   
     if(st1==1){data[i1]=((PINB >> 0) & 1);i1++;} 
     if(i1>96){i1=0;s=0;st=0;raz=1;st1=0;TCCR1B &= ~(1 << CS10); }
     }