All pastes #1439352 Raw Edit

Untitled

public text v1 · immutable
#1439352 ·published 2009-05-29 10:56 UTC
rendered paste body
#include <avr/io.h>
#include <avr/interrupt.h>

#define portio      PIND
#define portiow     PORTD
#define statled     PD6
#define btnsw       PD5

short int btnsw_right = 0;
int main (void)
{
  TIMSK |= (1 << TOIE0);
  DDRD = (1 << PD7 | 1 << PD6 | 0<<PD5);
  PORTD |= (1 << PD5);
  sei();

  while(1)
  {
    if((btnsw_right == 0) && ((portio & 0x20)))
    {
      btnsw_right = 1;
      TCNT0 = 0xff;
      TCCR0 = (1<<CS02 | 0<<CS01 | 0<<CS00); 
      //portiow = (1<<PD7);
    }
  }
}

ISR(TIMER0_OVF_vect)
{

  if((btnsw_right == 1) && (!(portio & 0x20)))
  {
    portiow ^= (1 << statled);
    btnsw_right = 0;
    TCCR0 = (0<<CS02 | 0<<CS01 | 0<<CS00); 
  }
  //portiow ^= (1<<PD7);
}