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

📄 rm_all.c

📁 用51单片机对Philips的RC5遥控编码进行解码,得到遥控器的键值
💻 C
字号:
/******************************************************************************
#ifdef DOC
File Name	:remocon.c
Description	:Remocon code recieve
Remark		:
Date		:04/03/01
Copyright	:Matsushita Electric Industrial Co.,ltd.
#endif
******************************************************************************/
/************************************
   	include files					
*************************************/
#include "reg52.h"
#include "struct.h"
#include "macrodef.h" 
#include "remocon.h"   

/***********************************
	Macro define					
***********************************/
#define REMO_SYSCODE 0x00			
/***********************************
	variable declaration			
***********************************/ 


unsigned char rem_code;   /* remote code receive */
REMO_FRAME	remodata;

/*Flags		remo_flags;
#define Frem_ok 	remo_flags.b_flag.f0
#define Fremin  	remo_flags.b_flag.f1
#define Fre_lead  	remo_flags.b_flag.f2
*/
bit Frem_ok ;
bit Fremin ;
bit Fre_lead;

//unsigned long int rem_data_tmp; /*			*/
unsigned char re_modc;				/*  		*/
unsigned char re_lead_width;		/*			*/
unsigned char re_with;				/* 			*/
unsigned char re_blnk;				/* 			*/
unsigned char re_loc;				/* 			*/
unsigned char re_data;				/* 			*/
unsigned char re_err;				/* 			*/ 
/*********************************************
	prototype declarations
*********************************************/
void vRMC_remocon(void);
void rm_blk(void);

void irq0(void);
void getrem(void);
extern unsigned char ucIIC_EEP_read(unsigned int addr);
extern void vIIC_EEP_write(unsigned int addr, unsigned char regdata);


//#define USE_PANAX_REMOCON
#ifdef  USE_PANAX_REMOCON
/*------------------------------------------------------------------*/
/*	Remocon KEY Table	 											*/
/*------------------------------------------------------------------*/
const unsigned char re_key[ ][3] = {
/*   Code  Code_,	Name					*/
	{0x30, 0xCF, KEY_POWER		},				/* 1	POWER		*/
	{0x10, 0xEF, KEY_DISPLAY	},			/* 2	DISPLAY		*/
	{0x00, 0xFF, KEY_OPENCLS	},			/* 3	OPEN/CLOSE	*/
	{0xB0, 0x4F, KEY_TVSYSTEM	},			/* 4	PAL/NTSC	*/	
	{0x90, 0x6F, KEY_KEY1 		},			/* 5	1			*/
	{0xA0, 0x5F, KEY_KEY2 		},			/* 6	2			*/
	{0x80, 0x7F, KEY_KEY3 		},			/* 7	3			*/
	{0xD2, 0x2D, KEY_KEY4Y 		},			/* 8	4			*/
	{0xE2, 0x1D, KEY_KEY5 		},			/* 9	5			*/
	{0xC2, 0x3D, KEY_KEY6 		},			/* 10	6			*/
	{0x52, 0xAD, KEY_KEY7 		},			/* 11	7			*/
	{0x62, 0x9D, KEY_KEY8 		},			/* 12	8			*/
	{0x42, 0xBD, KEY_KEY9		},			/* 13	9			*/
	{0x92, 0x6D, KEY_KEY11	 	},			/* 14	10+			*/	
	{0xA2, 0x5D, KEY_KEY00		},			/* 15	0			*/
	{0xF2, 0x0D, KEY_ANGLE 		},			/* 16	ANGLE		*/
	{0x72, 0x8D, KEY_SUBTITLE	},			/* 17	SUBTITLE 	*/	
	{0xB2, 0x4D, KEY_PLAYMODE 	},			/* 18	LANGUAGE	*/
	{0x82, 0x7D, KEY_CLEAR		},			/* 19	CLEAR		*/
	{0x32, 0xCD, KEY_MUTE		},			/* 20	MUTE		*/
	{0x12, 0xED, KEY_3D 		},			/* 21	3D			*/
	{0x22, 0xD4, KEY_SEARCH 	},			/* 22	SEARCH		*/	
	{0x02, 0xFD, KEY_ZOOM	 	},			/* 23	ZOOM		*/
	{0xF0, 0x0F, KEY_MENU		},			/* 24	MENU		*/
	{0xC0, 0x3F, KEY_TOPTITIL 	},			/* 25	TITLE		*/
	{0xE0, 0x1F, KEY_UP 		},			/* 26	UP			*/
	{0xD0, 0x2F, KEY_DOWN 		},			/* 27	DOWN		*/
	{0x70, 0x8F, KEY_LEFT 		},			/* 28	LEFT		*/
	{0x50, 0xAF, KEY_RIGHT		},			/* 29	RIGHT		*/
	{0x60, 0x9F, KEY_ENTER		},			/* 30	OK			*/
	{0xF8, 0x07, KEY_SETUP 		},			/* 31	SETUP		*/
	{0xC8, 0x37, KEY_PCB		},			/* 32	PBC			*/
	{0x3A, 0xC5, KEY_SPEAK 		},			/* 33	TSM			*/
	{0x1A, 0xE5, KEY_INTERLACE	},			/* 34	INTERLACE	*/
	{0x2A, 0xD5, KEY_VOLUMEMNS 	},			/* 35	VOLUME -	*/
	{0x0A, 0xF5, KEY_VOLUMEPLS 	},			/* 36	VOLUME +	*/
	{0xBA, 0x45, KEY_DIGEST 	},			/* 37	DIGEST		*/
	{0x9A, 0x65, KEY_KALAOKE 	},			/* 38	KALAOKE		*/
	{0xAA, 0x55, KEY_AUDIO 		},			/* 39	AUDIO		*/
	{0x8A, 0x75, KEY_RETURN 	},			/* 40	RETURN		*/
	{0x7A, 0x85, KEY_ABREP 		},			/* 41	A-B			*/
	{0x5A, 0xA5, KEY_REPEAT 	},			/* 42	REPEAT		*/
	{0x6A, 0x95, KEY_MARK 		},			/* 43	MARK		*/
	{0x4A, 0xB5, KEY_IMAGE 		},			/* 44	VIDEO ADJUST*/
	{0xFA, 0x05, KEY_BWDSKIP 	},			/* 45	PREVIOUS	*/
	{0xFA, 0x35, KEY_FWDSKIP 	},			/* 46	NEXT		*/
	{0xEA, 0x15, KEY_BWDSEARCH 	},			/* 47	B.WD		*/
	{0xCA, 0x35, KEY_FWDSEARCH 	},			/* 48	F.WD		*/
	{0x38, 0xC7, KEY_STOP 		},			/* 49	STOP		*/
	{0x18, 0xE7, NO_KEY 		},			/* 50	X			*/
	{0x28, 0xD7, KEY_PAUSE 		},			/* 51	PAUSE/STEP	*/
	{0x08, 0xF7, KEY_PLAY 		}			/* 52	PLAY		*/
};

#endif

void dummy(void)
	{}

void vRMC_remocon(void)
{
	/*REM_FRAME  now_remodata=remodata;*/
	unsigned char tmp1,tmp2,tmp3,tmp4;
	if (!Frem_ok) 
		{
			goto ERR;  /* receive not finish ,then return*/
		}
	/*receive 1 frame ok , process and reset the flag*/ 
		Frem_ok = 0;	
		tmp1=remodata.rem_format.verify.low;
		tmp2=remodata.rem_format.verify.high;
		tmp3=remodata.rem_format.data_pos;
		tmp4=~remodata.rem_format.data_neg;
	if((tmp3==tmp4)&&(tmp1==tmp2))		/*	check the recieved data is correct or not */
		{ 
		   {rem_code=remodata.rem_format.data_pos;}  /* get the remocon code in the frame */
		}

ERR:
	/*rm_err();*/
	dummy();
}








void getrem(void)  /*do in every timer0 irq  */
{
	switch(re_modc) 
	{case 0:	
			if (Fremin)  /*  if irq0 occured */
				{                   
					Fremin = 0;                 /*	Clear IRQO Flag */
					if(Fre_lead==0)		/*re_lead_width==0 means is the lead start*/
						{	Fre_lead=1 ; 	 break;} 	
					if(Fre_lead==1)
						{	re_lead_width++;}
									#if 0
										if (re_lead_width <=30 )	/* about	13.4msec=440usec *30 */
												{  /* if lead code width is less then 13.4ms, so the lead is NG*/
													Fre_lead=0 ;
													re_lead_width=0;
													re_loc=0;
													re_with =0;			/* conter for pluse width caculate */
													re_modc=0;
												}
											else 			/* lead code is ok */
												{
													re_loc = 	0;             /*	*/
													re_with = 	0;
													re_lead_width=0;
													Fre_lead=0;
													re_modc = 1;			/* go to bit receive mode */
												}
									#endif			
				                /**/
				}
			else
				{if(Fre_lead==1)
					{
							/*if (re_lead_width <= 32)*/
						 {
						 	re_lead_width++;
						 
						 if(P20&&(re_lead_width>=22)&&re_lead_width<=30) 
						 	{
						 		re_loc = 0;             /**/
								re_with = 0;
								re_lead_width=0;
								/*Fre_lead=0;*/
								re_modc = 1;
							}
						 }
					}
				}	
			break;
		case 1:								/* */
			if (Fremin) 					/* check the IRQ input 				*/
			{								/* The 2th fall edge of the frame	*/
				Fremin 	= 0;				/* clear the IRQ flag				*/
				re_with = 0;				/* conter for pluse width cacular 	*/
				re_loc 	= 0;	 			/* clear bit location */

				re_modc = 2;		/*next active set */
				remodata.remo = 0; 	/*clear the recive memory*/
			}
			break;
		case 2:     
			if (Fremin)
				{Fremin = 0;                 /**/
					if (re_with <= 6 )/*3.5msec=440usec*8*/
					{		
						remodata.remo <<= 1;
						/* re_blnk = re_with;	*/
						if( re_with >= 3) /* 32.15us * 50 = 1.6ms */
							{
								remodata.remo |=  0x01;
							}
						re_loc++;
						re_blnk = RE_BLANK1_CONUNT;	/*?*/
						
						/**/
						if (re_loc >= REMOCON_CODE_BITE)   /**/
						{
							re_loc = 0;         /**/
						/*	rem_data_tmp=remodata.remo;*/
							re_modc = 3;		/**/
						}
					}
					else 			/* re_with>6  not good data ,start again */
						{
						re_loc = 0;             /**/
						re_modc = 0;		/**/
						}
					re_with = 0;                /**/
				}
			else 							/* IRQ O not occur*/
				{if (re_with <= 6)	/**/
					{re_with++;}
				 if (re_with>6)
				    {
				    re_loc = 0;             /**/
					re_modc = 0;
				    }

				}
			break;
	
		case 3:  /* Fremin==Flag remocon in */
			if (Fremin) 
				{			
					/*Fremin = 0;				*/
					re_with = 0;			/**/
					re_modc = 0;			/**/
					remodata.remo = 0;
				}
			else{
					re_modc = 0;
					Frem_ok = 1;	/*1 frame receive 	*/
					
				}
			break;
			
			
		case 4:    	 /*reverse for abnormal mode ,eg   when mcu run in sleep mode */
			if (Fremin) {				/*  		*/
				Fremin = 0;				/**/
				re_with = 0;			/**/
				re_blnk = RE_BLANK1_CONUNT;				
			}
			else {						/**/
				if (re_with < 7){		/**/
					re_with++; 			 /*pluse width conter flash */
				}
				else{	 		       					
					re_loc = 0;        	/*Pluse too wide */
					re_modc = 0;		/**/
				}
			}
			break;	
	
		default:
			re_modc = 0;			/*	*/
			break;
	}
}


/***********************************************************************
#ifdef	DOC
TITLE	:	irq0
TITDOC	:	external irq 0 for RM input
INPUT	:	
OUTPUT	:	
DATE	:	
#endif
***********************************************************************/
void irq0 (void) interrupt 0 using 1
{
	
	if (!REMIN_P)
		{				/* IRQ	REMIN_P:p20in=0	*/
		/*{ if cpu run in slow mode , then exit slow mode }*/
		
		Fremin = 1;
		}
}


void tm1irq (void) interrupt 2 using 2  /*Timer 1 work @ 400us overflow mode*/
{
		getrem();
}

⌨️ 快捷键说明

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