Пример #1
0
// Fonction d'initialisation
void init(void)
{
	unsigned char i;
	for(i=0;i<=5;i++) Data_Received[i] = 0x00;

	cli();							// Désactiver toutes les interruptions

	DDRD = 0b10000110;				// config pour BP1 2 3 et 4 (BP = bouton poussoir)
	sbiBF (PORTD, PORTD3);			// BP0
	sbiBF (PORTD, PORTD4);			// BP1
	sbiBF (PORTD, PORTD5);			// BP2
	sbiBF (PORTD, PORTD6);			// BP3
	sDDR(DDRD,1);					// mettre port TX en sortie
	sbiBF(PORTD,0); 				// mettre pull-up sur RX
	sbiBF(PORTC,0); 				// mettre pull-up sur RX
	sDDR(DDRC,1); 					// mettre port en sortie
	DDRB = 0b00111111;  			// PORTB.6et7 en entrée (quartz)
	sbiBF (PORTB, PINB0);				// communication usart à 600baud non modulé

	USART0_Init_9600();				// initialise le port série 
	Init_Buffers_USART ();			// initialise les buffers de la communication série

	init_pcint();					// initialise les interruptions externes

	TIMER0_INIT();					// initialise le timer 0
	TIMER1_INIT ();					// initialiser le timer 1
	TIMER2_INIT ();					// initialiser le timer 2

	sei();
}
Пример #2
0
//Put microcontroller in Power Down sleep mode
void sleep_now(void)
{

  cli();
  _delay_ms(500);		//This is a hack, not sure why it's needed
				//  but without it, sleep works unexpectedly
  init_pcint(); 		//setup pin change interrupt
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);	//Power down the chip (sleep)
  sei();

  sleep_mode();

}