这个程序是利用T0的溢出中断。来定时控制LED的闪亮.
Prouets仿真的截图:
Studio6.2截图:
具体程序:
- /*
- * GccApplication21.c
- *
- * Created: 2014-10-17 21:43:54
- * Author: Administrator
- */
- #define F_CPU 4000000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <stdint.h>
- #define LED_BLINKL()(PORTC ^= 0x01)
- uint16_t T_Count = 0;
- int main(void)
- {
- DDRC = 0x01;
- TCCR0 = 0x05;
- TCNT0 = 256 - F_CPU/1024.0*0.05;
- TIMSK = 0x01;
- sei();
-
-
- while(1)
- {
- //TODO:: Please write your application code
- }
- }
- ISR(TIMER0_OVF_vect)
- {
- TCNT0 = 256 - F_CPU/1024.0 *0.05;
- if(++T_Count != 5) return;
- T_Count = 0;
- LED_BLINKL();
- }
|