Advertisement
Guest User

rf_decode_intr_based_v3

a guest
Dec 19th, 2011
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. volatile byte isrFlag;
  2. byte loopFlag;
  3.  
  4. // and many other variables
  5.  
  6. void setup()
  7. {
  8.   pinModeFast(2, INPUT);    // LA.ch#0
  9.   pinModeFast(12, OUTPUT);  // LA.ch#1
  10.   pinModeFast(13, OUTPUT);  // LA.ch#2
  11.  
  12.   lastTrig = micros();
  13.  
  14.   isrFlag = LOW;
  15.   loopFlag = LOW;
  16.  
  17.   digitalWriteFast(12, isrFlag);
  18.   digitalWriteFast (13, loopFlag);
  19.  
  20.   noInterrupts();
  21.   lastState = digitalReadFast(2);
  22.   attachInterrupt(0, myISR, CHANGE);
  23.   interrupts();
  24. }
  25.  
  26. void loop()
  27. {
  28.   loopFlag = ~loopFlag;
  29.   digitalWriteFast(13, loopFlag);
  30.  
  31. }
  32.  
  33. void myISR()
  34. {
  35.   thisTrig = micros();
  36.   slab = thisTrig - lastTrig;
  37.  
  38.   isrFlag = ~isrFlag;
  39.   digitalWriteFast(12, isrFlag);
  40.  
  41.   // code that checks lastState (HIGH/LOW) and slab (duration of lastState)
  42.   // to identify SHORT-LOW, SHORT-HIGH, LONG-LOW, LONG-HIGH, VERYLONG-LOW and INVALID
  43.   // sequence. INVALID sequence is ignored and decoder FSM is reset, others are
  44.   // accumulated via a circular-queue until codeword-length is reached, at which point
  45.   // codeword is processed i.e. matched with previous codeword to compare address bits
  46.   // and if matched, data bits returned
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement