Source file: /~heha/basteln/Haus/Telefon/CLIP-Anzeige/clip.zip/clip_pin.cpp

// CLIP für digitalen Eingang und Timer1 (original Antonio)
// Projekt Rufnummern-Anzeige

#include "ra.h"

ISR(TIMER1_COMPA_vect) {
 static unsigned int BaudCounter, TimeoutCounter;

 if (++TimeoutCounter==40000) {
  stat=0xFE;
  return;
 }

 BaudCounter++;
	
 if (!stat) {
		//Initialization of static variables - counters etc.
  last=0;
  GPIOR0=GPIOR0&~0x20|PINA&0x20;
  stat=3;
  cnt=0;
  akku=0;
  det=0;
  TimeoutCounter=0;
  return;
 }
	//Sampling
 byte t=(PINA^GPIOR0)&0x20;
 if (t) {
  GPIOR0^=0x20;
  dif1=diff;
  diff=last;
  last=0;
 }else last++;

	//here we have time duration of diff pulse stored in diff
 switch (stat) {
  case 3: if (!last) {	//Measuring, setting trigger time
   add(akku,diff);
   adc0(det);		// release det = median frequency between MARK and SPACE
   add(cnt,1);		// 256 times
   adc0(stat);		// go to state 4 when finished
  }break;
  case 4: if (!last) {
   if (diff>det) {	//zmienic na dynamiczna wartosc!
    add(cnt,16);
    adc0(stat);
   }else cnt=0;
  }break;
  case 5: if (!last) {	// wait for start bit
   if (diff<det) {
    ++stat;
    BaudCounter=diff;
    akku=0;
    cnt=0;
   }
  }break;
  case 6: switch (BaudCounter) {
   case 304: {
    if (cnt<elemof(clip.data))
      clip.data[cnt++]=akku;
    --stat;
   }break;
   case 59:
   case 91:
   case 123:
   case 155:
   case 187:
   case 219:
   case 251:
   case 283: {
    akku>>=1;
    if (diff>det+1 || diff>=det-1 && dif1>det) akku|=0x80;
   }break;
  }break;
 }
}

ISR(TIMER1_OVF_vect) {
 GPIOR0|=4;
}


void CLIP::init() {
 //TCCR1B=
 //OCR1A
 TIFR =0x44;
 TIMSK=0x44;
}

void CLIP::done() {
 TIMSK=0;
 TCCR1B=0x08;
}
Detected encoding: UTF-80