Esempio n. 1
0
// 2.1 - sets the state of the SDI-12 object. 
void SDI12::setState(uint8_t state){
  if(state == HOLDING){
    pinMode(_dataPin,OUTPUT);
    digitalWrite(_dataPin,LOW);
    *digitalPinToPCMSK(_dataPin) &= ~(1<<digitalPinToPCMSKbit(_dataPin));
    return; 
  }
  if(state == TRANSMITTING){
    pinMode(_dataPin,OUTPUT);
    noInterrupts(); 			// supplied by Arduino.h, same as cli()
    return; 
  }
  if(state == LISTENING) {
    digitalWrite(_dataPin,LOW);
    pinMode(_dataPin,INPUT); 
    interrupts();				// supplied by Arduino.h, same as sei()
	*digitalPinToPCICR(_dataPin) |= (1<<digitalPinToPCICRbit(_dataPin));
    *digitalPinToPCMSK(_dataPin) |= (1<<digitalPinToPCMSKbit(_dataPin));
  } else { 						// implies state==DISABLED 
  	digitalWrite(_dataPin,LOW); 
  	pinMode(_dataPin,INPUT);
  	*digitalPinToPCMSK(_dataPin) &= ~(1<<digitalPinToPCMSKbit(_dataPin));
  	if(!*digitalPinToPCMSK(_dataPin)){
  		*digitalPinToPCICR(_dataPin) &= ~(1<<digitalPinToPCICRbit(_dataPin));
  	}
  }
}
void TinyPinChange_DisablePin(uint8_t Pin)
{
    if(digitalPinToPCICR(Pin))
    {
	  *digitalPinToPCMSK(Pin) &= (_BV(digitalPinToPCMSKbit(Pin)) ^ 0xFF);
    }
}
void TinyPinChange_EnablePin(uint8_t Pin)
{
    if(digitalPinToPCICR(Pin))
    {
      *digitalPinToPCICR(Pin) |= _BV(digitalPinToPCICRbit(Pin));
	  *digitalPinToPCMSK(Pin) |= _BV(digitalPinToPCMSKbit(Pin));
    }
}
Esempio n. 4
0
 void PCdetachInterrupt(uint8_t pin) {
   volatile uint8_t *pcmask=digitalPinToPCMSK(pin);
   if (!pcmask) return;//runtime checking if pin has PCINT, i would prefer a compile time check
   // disable the mask.
   *pcmask &= ~(1<<digitalPinToPCMSKbit(pin));
   // if that's the last one, disable the interrupt.
   if (*pcmask == 0)
     PCICR &= ~(1<<digitalPinToPCICRbit(pin));
 }
Esempio n. 5
0
// ------------------------------------------------------------------------------
// Enable soft serial RX.
// ------------------------------------------------------------------------------
void gSoftSerial::listen()
{
  rxState = 0xFF;		// no start bit detected yet
  rxHead = rxTail = 0;		// no characters in buffer

  uint8_t prevSREG = SREG;
  cli();
  *digitalPinToPCMSK(rxPin) |= _BV(digitalPinToPCMSKbit(rxPin));
  *digitalPinToPCICR(rxPin) |= _BV(digitalPinToPCICRbit(rxPin));
  SREG = prevSREG;
}
Esempio n. 6
0
 void PCattachInterrupt(uint8_t pin,HANDLER_TYPE userFunc, uint8_t mode) {
   volatile uint8_t *pcmask=digitalPinToPCMSK(pin);
   if (!pcmask) return;//runtime checking if pin has PCINT, i would prefer a compile time check
   uint8_t bit = digitalPinToPCMSKbit(pin);
   uint8_t mask = 1<<bit;
   uint8_t pcicrBit=digitalPinToPCICRbit(pin);
   PCintMode[pcicrBit][bit] = mode;
   PCintFunc[pcicrBit][bit] = userFunc;
   //initialize last status flags
   PCintLast[pcicrBit][bit]=(*portInputRegister(digitalPinToPort(pin)))&digitalPinToBitMask(pin);
   // set the mask
   *pcmask |= mask;
   // enable the interrupt
   PCICR |= (1<<pcicrBit);
 }
Esempio n. 7
0
// initialization
void IRrecv::enableIRIn() {
  cli();
  if (digitalPinToPCICR(irparams.recvpin))
  {
      *digitalPinToPCICR(irparams.recvpin) |= _BV(digitalPinToPCICRbit(irparams.recvpin));
      *digitalPinToPCMSK(irparams.recvpin) |= _BV(digitalPinToPCMSKbit(irparams.recvpin));
  }

  // initialize state machine variables
  irparams.rcvstate 	= STATE_IDLE;
  irparams.rawlen 		= 0;
  irparams.startTime	= micros();
  sei();  // enable interrupts

  // set pin modes
  pinMode(irparams.recvpin, INPUT);
}
Esempio n. 8
0
void setupPinChangeInterrupt(byte pin) {
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
}
Esempio n. 9
0
// ------------------------------------------------------------------------------
// Shut down RX interrupts.
// ------------------------------------------------------------------------------
void gSoftSerial::ignore()
{
  *digitalPinToPCMSK(rxPin) &= ~_BV(digitalPinToPCMSKbit(rxPin));
}