ATMega_2560_Embedded_THT/Input_Capture_Unit/main.c

23 lines
652 B
C
Raw Normal View History

2022-10-04 18:52:43 +05:30
#include <avr/io.h>
#define F_CPU 16000000//16MHz
int main(void)
{
DDRA=0xFF;//Port A Output
2022-10-05 20:05:08 +05:30
DDRC=0xFF;//Port C Output
PORTD=0xFF;//activate pull-up//ICP1 in pin PD4= grey 47
2022-10-04 18:52:43 +05:30
while(1)
{
TCCR1A=0x00;//Normal mode
2022-10-05 20:05:08 +05:30
//TCCR1B=0x41;//rising edge, no pre-scaler, no noise canceller
TCCR1B=0x45;//rising edge, pre-scaler is max=1024, no noise canceller
2022-10-04 18:52:43 +05:30
//while(TIFR1 && (1<<ICF1)==0);//
//TIFR1=(1<<ICF1);//clear ICF1
while(TIFR1 && 0x20 == 0x00);//waiting for ICF1 Flag to be set
//ICF1=0;//why not this command?
TIFR1=(1<<ICF1);
2022-10-05 20:05:08 +05:30
PORTA=ICR1L;//check output in pins 22-29(A7=29)
PORTC=ICR1H;//check output in pins 37-30(C0=30)
2022-10-04 18:52:43 +05:30
}
}