Attiny13 mixed interrupts, doing it the right way?


i have used attiny13 lot on different small projects have never tried mix , activate/deactivate interrupts way before question missing here or there mess things long time use?? code working more of final check.

maybe explanation part off?
this remote media control attiny13a, nrf24l01 transmitter, , 3 ttp223 capacitive touch buttons , 2aaa batteries of mounted inside small plastic box touch buttons mounted on top of inside of box can press keys touching part of outside of box.

the attiny sleeping time , wake pcint0_vect after uses wdt_vect count how long pause key pressed (to change mode) , handle long presses on , down key(send message every 4th wdt int)...ok that's think.

 here main part of code, skipped nrf part of code since part have no interrupts in it.

to make code fit on attiny13 , run faster have skipped digitalread() mm , using direct port instead. , few more space saving tricks...

code: [select]

isr(wdt_vect) {}
isr(pcint0_vect) {} 
       
int main(void){
init();
{
 sbi (spi_ddr, spi_sck);     //set outputs         
 sbi (spi_ddr, ce); 
 sbi (spi_ddr, spi_mosi); 

  adcsra &= ~(1<<aden);//adc off
  sbi(gimsk,pcie); // turn on pin change interrupt
  sbi(pcmsk,pcint3); // pins affected interrupt
  sbi(pcmsk,pcint4); // pins affected interrupt
  sbi(pcmsk,pcint5); // pins affected interrupt
  sei(); // enable global interrupts
  set_sleep_mode(sleep_mode_pwr_down);
  csnhi(); //init csn
  tx_mode();                       // set tx mode
 
}



while(1) {

  cli(); // disable gobal interrupts
  wdtcr |= (1<<wdtie);  // enable watchdog timer interrupts
  // wdtcr |= (1<<wdp1);
   sei(); // enable global interrupts

   while(((pinb>>pause_key)&1)==1)  //count number of wdt ints pause key pressed
   {
   counter++;
   sleep_mode();

   }
  if(counter>30) sett=1;  //toggle volume mode
 
  if(counter>0&&counter<30&&sett==0)  sendd('p'); //send pause

  if(counter>1&&counter<30)   sett=0; //clear volume mode

 
    while(( ((pinb>>upp_key)&1)!=((pinb>>down_key)&1))&&(((pinb>>pause_key)&1)==0))
  //while upp or down key pressed , pause key not send message every 4th wdt interupt
  {
 
 if(((pinb>>upp_key)&1)==1)
{
if(sett==0) sendd('>'); else sendd('u');
}
  if(((pinb>>down_key)&1)==1)
{
if(sett==0) sendd('<'); else sendd('d');
}

sleep_mode(); //sleep 4 wdt between transmissions
sleep_mode();
sleep_mode();
sleep_mode();
  }
 
  cli(); // disable gobal interrupts
  wdt_disable();

   sei(); // enable global interrupts

counter=0;//clear counter next
 sleep_mode();
}
}

 



Arduino Forum > Using Arduino > Programming Questions > Attiny13 mixed interrupts, doing it the right way?


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'