Exemplo n.º 1
0
void NgatNgoai(){
    CLEAR_INTERRUPT(INT_EXT); //Xoa co ngat
    DISABLE_INTERRUPTS(GLOBAL); //vo hieu hoa ngat toan cuc

    //Xu ly chuong trinh ngat
    delay_ms(20);
    if (INPUT(PIN_B0) == 0){ 
        PORTE = ~PORTE; //Dao trang thai PORT E
    }
    ENABLE_INTERRUPTS(GLOBAL); //Cho phep ngat toan cuc
}
Exemplo n.º 2
0
void Ngat_Timer0(){
   SET_TIMER0(100);

   //Xu ly chuong trinh ngat
   ++count; //Tang gia tri bien dem
   if (count == 1000){
      CLEAR_INTERRUPT(INT_TIMER0); //Xoa co ngat
      DISABLE_INTERRUPTS(GLOBAL); //vo hieu hoa ngat toan cuc
      count = 0;
      PORTE = ~PORTE;
      ENABLE_INTERRUPTS(GLOBAL); //Cho phep ngat toan cuc
   }
}
Exemplo n.º 3
0
void Ngat_Timer0(){
	SET_TIMER0(100);

	//Xu ly chuong trinh ngat
	count++; //Tang gia tri bien dem
	if (count == sleep){
		CLEAR_INTERRUPT(INT_TIMER0); //Xoa co ngat
		DISABLE_INTERRUPTS(GLOBAL); //vo hieu hoa ngat toan cuc
		count = 0; 
		dem++; //Tang gia tri cua bien dem len
		ENABLE_INTERRUPTS(GLOBAL); //Cho phep ngat toan cuc
	}
}
Exemplo n.º 4
0
extern "C" void __ISR(_TIMER_2_VECTOR, ipl7) handlesTimer2Ints(void)
#endif
{
  TIMER_RESET;

  uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin);

  irparams.timer++; // One more 50us tick
  if (irparams.rawlen >= RAWBUF) {
    // Buffer overflow
    irparams.rcvstate = STATE_STOP;
  }
  switch(irparams.rcvstate) {
  case STATE_IDLE: // In the middle of a gap
    if (irdata == MARK) {
      if (irparams.timer < GAP_TICKS) {
        // Not big enough to be a gap.
        irparams.timer = 0;
      } 
      else {
        // gap just ended, record duration and start recording transmission
        irparams.rawlen = 0;
        irparams.rawbuf[irparams.rawlen++] = irparams.timer;
        irparams.timer = 0;
        irparams.rcvstate = STATE_MARK;
      }
    }
    break;
  case STATE_MARK: // timing MARK
    if (irdata == SPACE) {   // MARK ended, record time
      irparams.rawbuf[irparams.rawlen++] = irparams.timer;
      irparams.timer = 0;
      irparams.rcvstate = STATE_SPACE;
    }
    break;
  case STATE_SPACE: // timing SPACE
    if (irdata == MARK) { // SPACE just ended, record it
      irparams.rawbuf[irparams.rawlen++] = irparams.timer;
      irparams.timer = 0;
      irparams.rcvstate = STATE_MARK;
    } 
    else { // SPACE
      if (irparams.timer > GAP_TICKS) {
        // big SPACE, indicates gap between codes
        // Mark current code as ready for processing
        // Switch to STOP
        // Don't reset timer; keep counting space width
        irparams.rcvstate = STATE_STOP;
      } 
    }
    break;
  case STATE_STOP: // waiting, measuring gap
    if (irdata == MARK) { // reset gap timer
      irparams.timer = 0;
    }
    break;
  }

  if (irparams.blinkflag) {
    if (irdata == MARK) {
      BLINKLED_ON();  // turn pin 13 LED on
    } 
    else {
      BLINKLED_OFF();  // turn pin 13 LED off
    }
  }
  CLEAR_INTERRUPT();
} // end ISR