⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ir.c

📁 Mp3 Player using ATmega128, VS1003B, Character LCD. Test OK.Good Sound.
💻 C
字号:
#include <avr/io.h>
#include <avr/interrupt.h>
#include "../global.h"
#include "ir.h"

U8 ir_rx_data[4];				// 4byte狼 荐脚 单捞磐甫 历厘窍扁 困茄 函荐

U8 ir_state;					// 府葛能 荐脚 单捞磐俊 蝶弗 泅犁狼 惑怕 钎矫

static U8 ir_timer_cnt;			// 府葛能 荐脚 单捞磐狼 辨捞甫 困茄 墨款磐 函荐

U8 ir_bit_cnt;					// 荐脚等 厚飘狼 肮荐甫 历厘窍扁 困茄 函荐

U8 ir_rx_flag;					// 府葛能 单捞磐 荐脚 惑怕甫 钎矫, 1: 单捞磐 荐脚
U8 ir_rx_temp;					// 1byte狼 单捞磐甫 历厘窍扁 困茄 烙矫 单捞磐 函荐



/*
// 府葛能 脚龋狼 窍碍俊瘤肺 牢茄 牢磐反 惯积
// 寇何牢磐反飘啊 惯积登绰 矫埃 埃拜阑 烹窍咯
// 荐脚等 单捞磐啊 绢恫巴牢瘤 舅 荐 乐促.
SIGNAL(SIG_INTERRUPT3)
{

	switch(ir_state)
	{
        case IR_Ready :		// 捞惑怕绰 牢磐反飘 吧府扁 傈 惑怕
            	ir_state = IR_Lead; // 措扁惑怕俊辑 Lead code狼 falling edge 八免惑怕肺 函版
            	break;

        case IR_Lead :		// Lead code 狼 贸澜 falling edge 八免 惑怕            
	            if((ir_timer_cnt >= 80) && (ir_timer_cnt < 100))			// falling edge埃狼 矫埃 埃拜捞 8.5msec~9.5msec 荤捞扼搁
		            ir_state = IR_Data;		// Lead code肺 牢侥窍咯 单捞磐 历厘惑怕肺 函版
	            else
					ir_state = IR_Lead;		// 酒聪搁 促矫 Lead code 贸澜 窍碍 俊瘤 八免 惑怕肺 函版

				ir_bit_cnt = 0;				// 荐脚等 厚飘荐甫 檬扁拳
				ir_rx_temp = 0;
	            break;

        case IR_Data :		// 厚飘甫 盒籍窍咯 32俺 厚飘(4官捞飘)甫 历厘窍绰 惑怕

	            if((ir_timer_cnt >= 8) && (ir_timer_cnt < 13))	        // 0.9msec~1.3msec 荤捞狼 裹困扼搁 荐脚 厚飘狼 蔼 0
					ir_rx_temp = ir_rx_temp | 0x00;
	            
	            else if((ir_timer_cnt >= 17) && (ir_timer_cnt < 25))	// 1.9msec~2.5msec 荤捞狼 裹困扼搁 荐脚 厚飘狼 蔼 1 				
	                ir_rx_temp = ir_rx_temp | 0x80;
				
	            
	            else	 //荐脚等 脚龋啊 单捞磐啊 酒聪扼搁
				{
					ir_state = IR_Ready;					
					break;
	            }
            
				ir_bit_cnt++;

	            if ((ir_bit_cnt%8)==0)
				{
					ir_rx_data[(ir_bit_cnt/8)-1] = ir_rx_temp;			// 8俺狼 单捞磐啊 荐脚登搁 蔼阑 历厘茄促.
	                ir_rx_temp = 0;
					if(ir_bit_cnt >= 32)			// 葛电 单捞鸥狼 荐脚捞 肯丰登搁
					{
						ir_state = IR_Ready;		// 府葛能 脚龋 荐脚 措扁 惑怕肺 函版
						ir_bit_cnt = 0;
						ir_rx_flag = 1;

	                } // end if
	            } // end if

	            ir_rx_temp = ir_rx_temp>>1;

	            break;
      	default: break;
	}	// end switch

    ir_timer_cnt = 0;


// chung pung remocon
/*
    switch(ir_state)
	{
        case IR_Ready :		// 捞惑怕绰 牢磐反飘 吧府扁 傈 惑怕
            	ir_state = IR_Lead; // 措扁惑怕俊辑 Lead code狼 falling edge 八免惑怕肺 函版
            	break;

        case IR_Lead :		// Lead code 狼 贸澜 falling edge 八免 惑怕            
//	            if((ir_timer_cnt >= 130) && (ir_timer_cnt < 140))			// falling edge埃狼 矫埃 埃拜捞 12.5msec~13.5msec 荤捞扼搁
	            if((ir_timer_cnt >= 85) && (ir_timer_cnt < 140))			// falling edge埃狼 矫埃 埃拜捞 12.5msec~13.5msec 荤捞扼搁
		            ir_state = IR_Data;		// Lead code肺 牢侥窍咯 单捞磐 历厘惑怕肺 函版
	            else
					ir_state = IR_Lead;		// 酒聪搁 促矫 Lead code 贸澜 窍碍 俊瘤 八免 惑怕肺 函版

				ir_bit_cnt = 0;				// 荐脚等 厚飘荐甫 檬扁拳
				ir_rx_temp = 0;
	            break;

        case IR_Data :		// 厚飘甫 盒籍窍咯 32俺 厚飘(4官捞飘)甫 历厘窍绰 惑怕

	            if((ir_timer_cnt >= 9) && (ir_timer_cnt < 13))	        // 0.9msec~1.3msec 荤捞狼 裹困扼搁 荐脚 厚飘狼 蔼 0
					ir_rx_temp = ir_rx_temp | 0x00;
	            
	            else if((ir_timer_cnt >= 18) && (ir_timer_cnt < 25))	// 1.9msec~2.5msec 荤捞狼 裹困扼搁 荐脚 厚飘狼 蔼 1 				
	                ir_rx_temp = ir_rx_temp | 0x80;
				
	            
	            else	 //荐脚等 脚龋啊 单捞磐啊 酒聪扼搁
				{
					ir_state = IR_Ready;					
					break;
	            }
            
				ir_bit_cnt++;

	            if ((ir_bit_cnt%8)==0)
				{
					ir_rx_data[(ir_bit_cnt/8)-1] = ir_rx_temp;			// 8俺狼 单捞磐啊 荐脚登搁 蔼阑 历厘茄促.
	                ir_rx_temp = 0;
					if(ir_bit_cnt >= 32)			// 葛电 单捞鸥狼 荐脚捞 肯丰登搁
					{
						ir_state = IR_Ready;		// 府葛能 脚龋 荐脚 措扁 惑怕肺 函版
						ir_bit_cnt = 0;
						ir_rx_flag = 1;
	                } // end if
	            } // end if

	            ir_rx_temp = ir_rx_temp>>1;

	            break;
      	default: break;
	}	// end switch

    ir_timer_cnt = 0;


}

void Init_ExtINT3(void)
{

	// INT3 Falling Edge 八免
	EICRA=0x80;

	// enable INT3
	sbi(EIMSK,3);

	EIFR=0x00;
}


void Init_Timer0(void)
{

    TCCR0 = 0x03;	// 32 橇府胶纳老矾

    TCNT0 = (256-25);

    sbi(TIMSK, TOIE0);	//鸥捞赣0 牢磐反飘 牢俊捞喉

    TIFR = 0x00;

	sei();
}



// 100us(0.1ms)付促 牢磐反 惯积
SIGNAL(SIG_OVERFLOW0)
{	
	ir_timer_cnt++;   
	TCNT0 = (256-25);
}

*/

void Init_IR(void)
{

	ir_rx_flag = 0;

	// 季辑 荐脚阑 困茄 函荐 檬扁拳
	ir_state = IR_Ready;
	ir_timer_cnt = 0;
	ir_bit_cnt = 0;

//	Init_ExtINT3();

//	Init_Timer0();
}

⌨️ 快捷键说明

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