main.c

来自「atmega16L输入捕获经典试验已经通过验证」· C语言 代码 · 共 55 行

C
55
字号
#include <avr/io.h> 
#include <avr/signal.h>
#include <avr/delay.h>
#include <stdio.h>
#include <math.h>
#include <LCD1602.h>

int once_time; 

void init_timer1_icp(void)
{
	TCCR1B|=(1<<CS11)|(1<<CS10)|(1<<ICNC1);	//分频比64,可调
	TIFR=1<<ICF1;	//清除没有执行的中断
	TIMSK=1<<TICIE1;
	DDRB=0xFF;
	DDRD&=~(1<<PD6);
	PORTD|=1<<PD6;
}
SIGNAL(SIG_INPUT_CAPTURE1)
{
	once_time=ICR1/16;
	TCNT1=0;
	printf("\n\v\v%5d\n",once_time*8); 	
}
int main(void)
{
	char i; 
	fdevopen(LCD_putc,0,0);//将printf()输出函数重定向于LCD_putc()
	LCD_POWER_PORT|=(LCD_VCC);
	LCD_POWER_PORT&=(~LCD_GND);
	LCD_POWER_DDR|=(LCD_VCC|LCD_GND);
	_delay_ms(15);
	LCD_DATA_DDR|=LCD_DATA;   
	LCD_CROL_DDR|=LCD_RS|LCD_EN|LCD_RW;  
    LCD_init();
	LCD_write_char(0x01,0);
	_delay_ms(2);
    printf("Wellcome\n");
    printf("www.OURAVR.com!\n");
	for(i=0;i<50;i++)
    _delay_ms(100);
    printf("Happy every day!\n");
    printf("Forever friend! \n");
	for(i=0;i<50;i++)
    _delay_ms(100);
    printf("Redstone:Support\n");
    printf("OURAVR Forever! \n");
	for(i=0;i<50;i++)
    _delay_ms(100);
    printf("The Cycle Is:   \n");
    printf("T=     us       \n");
	SREG|=1<<SREG_I;
	init_timer1_icp();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?