|
#define F_CPU 1000000UL
#include
#include
#include
#define INT8U unsigned char
#define INT16U unsigned int
#define DoorBell() (PORTD ^= 0x01) /
#define Key_DOWN() ((PINB & 0x80) == 0x00)
volatile INT16U soundDelay; //两个不同取值分别对应于"叮","咚"
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;
}
|
|