|
QQ截圖20181222121005.jpg (128.84 KB, 下載次數(shù): 74)
下載附件
2018-12-22 12:10 上傳
#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; //兩個(gè)不同取值分別對應(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;
}
|
評分
-
查看全部評分
|