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

📄 rec80.c

📁 Yet Another MP3 Player source code. It can be usefull as reference source for any project.
💻 C
字号:
/*
  Copyright (C) 2001 Jesper Hansen <jesperh@telia.com>.

  Rewritten by:	Nikolai Vorontsov <nickviz@mail.be>

  This file is part of the yampp system.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation, 
  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <io.h>
#include <timer.h>
#include <sig-avr.h>
#include <interrupt.h>

#include "rec80.h"
#include "delay.h"
#include "uart.h"					// enable for debug

///static u16 _get_rec80(void);

///u16 IR_Code = 0;

///INTERRUPT(SIG_INTERRUPT0)
///{
///	IR_Code = _get_rec80();
///}



///u16 get_rec80(void)
///{
///	return IR_Code;
///}



bool rec80_active(void)
{
	register u08 i = 50;

	while (i-- != 0)
		if (bit_is_clear(IR_PORT-2, IR_BIT))
			return true;
	return false;

///	return IR_Code != 0;
}


#if defined(REC80) || defined(PANASONIC)
/*
	The REC-80 format used by Panasonic is a space coded 48 bit code consisting 
	of a 32 bit group id, followed by a 16 bit commmand word.
	Leading this is a header consisting of a 10T signal and a 4T pause.
	All bits start with a pulse of length T. The length of the pause following
	indicates the bit value. A T pause for a 0-bit and a 3T pause for a 1-bit.
*/

void init_rec80()
{
	cbi(IR_PORT-1, IR_BIT); 	// PD2 input for RC5
	sbi(IR_PORT,   IR_BIT); 	// activate pullup
///	enable_external_int(0x40);	// enable interrupt0
}

u16 get_rec80(void)
{
	u08 i, tmp;
	u08 time;
	u08 T2,T4;
	u08 cl,ch;

	tmp = 0;
	cl = ch = 0;	// only needed to get rid of compiler warning

	loop_until_bit_is_set(IR_PORT-2, IR_BIT);		// skip leading signal


	timer0_stop();
	timer0_source(CK256);	//update every 32us
	timer0_start();

	while (bit_is_set(IR_PORT-2, IR_BIT))
	{
		T2 = inp(TCNT0);
		if (T2 >= 100)		// max wait time
			return 0;
	}
	
//	loop_until_bit_is_clear(IR_PORT-2, IR_BIT);	    // skip leading space


	// measure time T

	timer0_stop();
	timer0_source(CK256);	//update every 32us
	timer0_start();

	loop_until_bit_is_set(IR_PORT-2, IR_BIT);
	
	T2 = inp(TCNT0);		// T is normally around 0E-10 hex = 15 -> 480 uS
	timer0_stop();

	T2 = T2 * 2;
	// max time is 4T
	T4 = T2 * 2;		

	for (i = 0; i < 48; i++)
	{
		timer0_source(CK256);
		timer0_start();
			
		while(1)
		{
			time = inp(TCNT0);
		
			if (time > T4)
				return 0;
			
			// measure time on the lo flank
			if (bit_is_clear(IR_PORT-2, IR_BIT))
			{
				tmp <<= 1;
				if (time >= T2)
					tmp++;
				break;
			}
		}
		timer0_stop();

		// save command data as we go
		if( i == 39)
			cl = tmp;
		if( i == 47)
			ch = tmp;
		
		// syncronize - wait for next hi flank
		loop_until_bit_is_set(IR_PORT - 2, IR_BIT);
	}

// UART_Puts("IR-CODE: ");UART_Printfu16((ch<<8) + cl); UART_Putsln(" ");  // enable for debuging
	
	return (u16) (ch << 8) + cl;
}
#endif



#if defined(NEC80) || defined(CREATIVE_RM900)
/*
	The NEC format is a space coded 32 bit code consisting 
	of a 16 bit group id, followed by a 16 bit commmand word.
	Leading this is a header consisting of a 16T signal and a 8T pause.
	All bits start with a pulse of length T. The length of the pause following
	indicates the bit value. A T pause for a 0-bit and a 3T pause for a 1-bit.

	Modified REC80 format by Will Jenkins, wdj@cus.org.uk
*/


void init_rec80()
{
	cbi(IR_PORT-1, IR_BIT); 	// PD2 input for RC5
	cbi(IR_PORT,   IR_BIT); 	// no pullup
}

u16 get_rec80(void)
{
	u08 i, tmp;
	u08 time;
	u08 T2,T4;
	u08 cl,ch;

	tmp = 0;
	cl = ch = 0;	// only needed to get rid of compiler warning

	loop_until_bit_is_set  (IR_PORT-2, IR_BIT);		// skip leading signal


	timer0_stop();
	timer0_source(CK256);	//update every 32us
	timer0_start();

	while (bit_is_set(IR_PORT-2, IR_BIT))
	{
		T2 = inp(TCNT0);
		if (T2 >= 140)	// max wait time was 100
			return 0;
	}
	
//	loop_until_bit_is_clear(IR_PORT-2, IR_BIT);	    // skip leading space


	// measure time T

	timer0_stop();
	timer0_source(CK256);	//update every 32us
	timer0_start();

	loop_until_bit_is_set(IR_PORT-2, IR_BIT);
	
	T2 = inp(TCNT0);		// T is normally around 0E-10 hex = 15 -> 480 uS
	timer0_stop();

	T2 = T2 * 2;
	// max time is 4T
	T4 = T2 * 2;		

	for (i = 0; i < 32; i++)
	{
		timer0_source(CK256);
		timer0_start();
			
		while(1)
		{
			time = inp(TCNT0);
		
			if (time > T4)
				return 0;
			
			// measure time on the lo flank
			if (bit_is_clear(IR_PORT-2, IR_BIT))
			{
				tmp <<= 1;
				if (time >= T2)
					tmp += 1;
				break;
			}
		}
		timer0_stop();

		// save command data as we go
		if( i == 15)
			cl = tmp;  	// the device code 
					//(which is 35 in the case of the infra CDROM)
		 if( i == 31)
			ch = tmp;	//command
		
		// syncronize - wait for next hi flank
		loop_until_bit_is_set(IR_PORT - 2, IR_BIT);
	 }

    UART_Puts("IR-CODE: ");UART_Printfu16((cl<<8) + ch); UART_Putsln(" ");  // enable for debuging

	return (u16) (cl << 8) + ch;
 }
#endif

⌨️ 快捷键说明

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