2021年5月4日星期二

Why led is on as default although I set it off

Why the led in that case is on as default although I have set it off:

#include <avr/io.h>  #include <avr/interrupt.h>    // ISR which will take action once the interrupt happens  ISR(INT0_vect)  {      PORTC ^= 1<<PC0; // toggel the led when the IST happen  }    // configure the interrupt  void INT0_Init(void)  {        GICR |= 1<<INT0;    // can be written as : 1<<PD2, 1<<6, enable external interrupt 0  in General Interrupt Control Register      MCUCR |= (1 << ISC01) | (1<<ISC00); // configure MCU Control Register enable the flag once you received a rising edge  SREG |= 1<<7; // enable the i bit: Global Interrupt bit in Statues REGister  }    int main(void)  {      SREG  &= ~(1<<7);  // disable the global inerrubt         DDRD &= ~(1<<PD2);  // make it input pin        DDRC |= (1<<PC0);   // make it output pin      PORTC |= (1<<PC0);  // turn off the led at the first        INT0_Init();      while(1)      {      }  }  

and if I just put the calling of function INT0_Int first thing in the main, the led is off as supposed

https://stackoverflow.com/questions/67392645/why-led-is-on-as-default-although-i-set-it-off May 05, 2021 at 05:51AM

没有评论:

发表评论