T/C0作为外部事件计数器使用
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.5a Evaluation
Date : 2011/12/15
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 4.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0=0x83;
PORTA.0 = ~PORTA.0;
}
// Declare your global variables here
void main(void)
{
PORTA = 0x01;
DDRA = 0x01;
PORTB =0x01;
DDRB = 0x00;
// Timer/Counter 0 initialization
// Clock source: T0 pin Rising Edge
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x07;
TCNT0=0x83;
OCR0=0x00;
TIMSK = 0x01;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
}
}