本程正常运行红灯闪,当按一下键不喂狗时,黄灯亮。
以下是Proteus运行截图:
以下是Studio6.2编译的结果:
以下是程序清单:
- /*
- * GccApplication16.c
- *
- * Created: 2014-11-13 20:16:31
- * Author: Administrator
- */
- #define F_CPU 1000000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <avr/wdt.h>
- #include <util/delay.h>
- #include <stdint.h>
- #define LED1_ON() (PORTC &=~_BV(PC0))
- #define LED1_OFF() (PORTC |= _BV(PC0))
- #define LED2_BLINK() (PORTC ^= _BV(PC5))
- int main(void)
- {
- DDRC = 0xFF;PORTC = 0xFF;
- DDRD = 0x00;PORTD = 0xFF;
- LED1_ON();
- _delay_ms(1600);
-
- MCUCR = 0x02;
- GICR = _BV(INT0);
- TCCR1B = 0x03;
- TCNT1 = 65536 - F_CPU/64.0 * 1.5;
- TIMSK = 0x04;
- wdt_enable(WDTO_2S);
- LED1_OFF();
- sei();
-
-
- while(1)
- {
- LED2_BLINK();
- _delay_ms(200);
- //TODO:: Please write your application code
- }
- }
- ISR(TIMER1_OVF_vect)
- {
- TCNT1 = 65536 - F_CPU/64 * 1.5;
- wdt_reset();
- }
- ISR(INT0_vect)
- {
- TIMSK = 0x00;
- }
|