久久人妻精品人妻视频五月天一区二区三区,,自慰午夜喷水久久久av国产成人a视频高在线,,欧美日韩免费专区在线97精品国产手机

  • <cite id="cwywg"></cite>
    <button id="cwywg"></button>
  • <button id="cwywg"><source id="cwywg"></source></button>
    <button id="cwywg"><tbody id="cwywg"></tbody></button>
  • <button id="cwywg"></button>
  • 
    
  • logo logo
    • BANNER
    • BANNER
    • BANNER
    您的位置 : 首頁 > 新聞資訊 > 技術(shù)支持
    AVR外部中斷INT1檢測按鍵,使用LED作指示
    發(fā)布者:江蘇瑞易通電子科技有限公司 人氣:639 發(fā)布日期:2021-04-23 10:10:40

    實(shí)驗(yàn)內(nèi)容: 
    使用AVR的外部中斷INT1檢測PD3Key,如果有按鍵按下,則喚醒休眠的MCU,并使它的PB口的LED做加1指示。

    #include


    #define DISP_DDR DDRB

    #define DISP_PORT   PORTB

    #define IN_PD3  cbi(DDRD,3)  //PD3

    #define SET_PD3  sbi(PORTD,3)

    #define GET_PD3  gbi(PIND,3)

    //PORTA|=BIT(5);    就是把把第6位置1;

    //PORTA=~BIT(5);   就是把第6位置零

    //DDRB |=  0x80;  //等于“sbi(DDRB,7);” 置1位

    //DDRB &= ~0x80;  //等于“cbi(DDRB,7);”清零


    /*--------------------------------------------------------

    程序名稱:外部中斷服務(wù)程序

    -------------------------------------------------------*/

    #pragma interrupt_handler int1_isr:3

    //是一個編譯器的關(guān)鍵字聲明,聲明這個函數(shù)是一個中斷服務(wù)函數(shù),后面跟的數(shù)字是中斷向量號。

    void int1_isr(void)

    {

     GICR &= 0b01111111;  // disable int1 interrupt   通用中斷控制寄存器 GICR

     DISP_PORT++;   // 顯示口指示加1,指示被按次數(shù)

     delay50ms(4);

     GICR |= 0b10000000;   // enable int1 interrupt

    }

    /*--------------------------------------------------------

    程序名稱:外部中斷初始化程序

    --------------------------------------------------------*/

    void int1_init()

    {

     IN_PD3;    // set PD3/INT1 as input

     SET_PD3;   // set PD3/INT1 as output,high level,avoid triggering

     MCUCR |= 0b11110011;  // set PD3/INT1 as low level active

     GICR  |= 0b10000000;  // enable global interrupt

     SEI();       // enable external interrupt

    }

    void main(void)

    {

     DISP_DDR  = 0xFF;

     DISP_PORT = 0x00;

     int1_init();

     asm("sleep");   // set mcu as sleep modle

     //開機(jī)后MCU處于SLEEP狀態(tài),之后按按鍵,LED作出了簡單指示。


     while(1);

    }



    返回新聞列表