欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: AVR單片機(jī)定時器做的門鈴程序+電路 [打印本頁]

作者: jinsheng7533967    時間: 2018-12-22 12:11
標(biāo)題: AVR單片機(jī)定時器做的門鈴程序+電路




#define F_CPU  1000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define INT8U   unsigned char
#define INT16U  unsigned int

#define DoorBell() (PORTD ^= 0x01)          /

#define Key_DOWN() ((PINB & 0x80) == 0x00)

volatile INT16U soundDelay;                 //兩個不同取值分別對應(yīng)于"叮","咚"

int main()
{
        DDRB = 0;      PORTB = 0xff;
        
        DDRD = 0xff;  
        
        TCCR1B = 0x01;

        TCNT1 = -700;
        
        sei();
        
        while(1)
        {
                if( Key_DOWN() )
                {
                        TIMSK = _BV(TOIE1);
                        
                        soundDelay = -700;
                        
                        _delay_ms(400);
                        
                        soundDelay = -1000;
                        
                        _delay_ms(600);
                        
                        TIMSK = 0x00;
                }
               
        }
        
}


ISR ( TIMER1_OVF_vect )
{
        
        DoorBell();
               
                TCNT1 = soundDelay;
               
}







歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1