Пример #1
0
void main(void)
{
	init();
	while (1) {
		while (usiTwiDataInReceiveBuffer())	{ // process I2C command
			processTWI();
			process_keyrepeat();
		}
	}
}
Пример #2
0
int main()
{
  // set digits as output and disable them all
  DIG1_DDR |= _BV(DIG1_PIN);
  DIG2_DDR |= _BV(DIG2_PIN);
  DIG3_DDR |= _BV(DIG3_PIN);
  DIG4_DDR |= _BV(DIG4_PIN);
  light_digit(0);

  // setup all segments as inputs and low
  SEG_A_DDR &= ~_BV(SEG_A_PIN);
  SEG_B_DDR &= ~_BV(SEG_B_PIN);
  SEG_C_DDR &= ~_BV(SEG_C_PIN);
  SEG_D_DDR &= ~_BV(SEG_D_PIN);
  SEG_E_DDR &= ~_BV(SEG_E_PIN);
  SEG_F_DDR &= ~_BV(SEG_F_PIN);
  SEG_G_DDR &= ~_BV(SEG_G_PIN);
  
  SEG_A_PORT &= ~_BV(SEG_A_PIN);
  SEG_B_PORT &= ~_BV(SEG_B_PIN);
  SEG_C_PORT &= ~_BV(SEG_C_PIN);
  SEG_D_PORT &= ~_BV(SEG_D_PIN);
  SEG_E_PORT &= ~_BV(SEG_E_PIN);
  SEG_F_PORT &= ~_BV(SEG_F_PIN);
  SEG_G_PORT &= ~_BV(SEG_G_PIN);

  // set DP as output and to ground
  SEG_DP_DDR |= _BV(SEG_DP_PIN);
  SEG_DP_PORT &= ~_BV(SEG_DP_PIN);

  // set up timer 1 as system clock
  TIMSK = (1 << TOIE0);         // overflow interrupts
  TCCR0B = TIMER0_CLKDIV_488Hz; // default blink rate at 488Hz

  
  // init the TWI slave
  usiTwiSlaveInit(SLAVE_ADDRESS);

  // enable interrupts
  sei();

  // The infinite loop
  while (1)
  {
    // process Twi commands
    while (usiTwiDataInReceiveBuffer())
    {
      processTWI();
    }
  }

}