LPC1114 红外遥控解码程序(RC5 )
时间:11-11
来源:互联网
点击:
- /********************************************************************
- ;
- ;modified LPC1114 sample code
- ;
- ; RC5 format:
- ; | S | F | C | 5 sytem bits | 6 command bits |
- ; | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
- ;
- ; -----+ +-+ +-+ +-+ +-+ +-+ +---+ +-+ +---+ +-+ +-+ +-+ +----
- ; | | | | | | | | | | | | | | | | | | | | | | | |
- ; +-+ +---+ +-+ +-+ +-+ +-+ +-+ +---+ +-+ +-+ +-+ +-+
- ;
- ********************************************************************/
- #include "LPC11xx.h" /* LPC11xx Peripheral Registers */
- #define RC5_INPUT_PIN (1< 0x01)
- #define MIN_HALF_BIT 640 // 640 us
- #define HALF_BIT_TIME 889 // 889 us
- #define MAX_HALF_BIT 1140 // 1140 us
- #define MIN_FULL_BIT 1340 // 1340 us
- #define FULL_BIT_TIME 1778 // 1778 us
- #define MAX_FULL_BIT 2220 // 2220 us
- unsigned char RC5_System; // Format 1 E/N ts4 s3 s3 s1 s0
- unsigned char RC5_Command; // Format 00c5 c4 c3 c2 c1 c0
- unsigned char RC5_flag;
- static signed int low_time;
- static signed int high_time;
- static unsigned char half_bit;
- static unsigned char sys; // system byte
- static unsigned char cmd; // Command byte
- void RC5_Init(void)
- {
- //GPIO setup
- //assign input for IR sensor
- LPC_GPIO0->DIR &= ~(RC5_INPUT_PIN);
- LPC_IOCON->PIO0_1 |= (1<5); //turn on hysteresis
- LPC_SYSCON->SYSAHBCLKCTRL |= (1<6);//enable GPIO clock
- NVIC_EnableIRQ(EINT0_IRQn);
- //timer16 0 setup
- LPC_SYSCON->SYSAHBCLKCTRL |= (1<7);
- LPC_TMR16B0->PR= 48; // prescaler 48, timer runs at 48 MHz / 48 = 1 MHz
- LPC_TMR16B0->MR0 = 12000; //load match register 0
- LPC_TMR16B0->MCR = 3; // Interrupt and Reset on MR0
- NVIC_EnableIRQ(TIMER_16_0_IRQn);
- LPC_GPIO0->IS &= ~(0x1<0x01);//interrupt sense - 0 = edge sensitive
- LPC_GPIO0->IBE |= 0x1<0x01; //interrupt both edges - 1 = both edges
- LPC_GPIO0->IE |= ( 0x1 < 0x01); //interrupt enable
- LPC_TMR16B0->TCR = 1; //Start timer
- }
- static void RC5_Shift_Bit(char val)
- {
- if (sys & 0x80)
- {
- if (cmd & 0x80) // command full ?
- {
- sys = 0; // yes, ERROR
- cmd = 0;
- }
- else
- cmd = (cmd < 1) | val; // shift command
- }
- else
- sys = (sys < 1) | val; // shift system
- }
- /************************************************************************
- ; RC5_Decode (we only take action at a rising edge)
- ;
- ; Half(prev) Bit Low Time High Time Action New Half Bit
- ; -------------------------------------------------------------------
- ; 0 0 0 Shift 0 0
- ; 0 0 1 Shift 1 1
- ; 0 1 0 -ERROR- *
- ; 0 1 1 Shift 1,0 0
- ; 1 0 0 Shift 1 1
- ; 1 0 1 -ERROR- *
- ; 1 1 0 Shift 1,0 0
- ; 1 1 1 -ERROR- *
- ;
- ***********************************************************************/
- static void RC5_Decode(void)
- {
- unsigned char action;
- action = half_bit < 2;
- // Check High Time
- if ((high_time > MIN_FULL_BIT) && (high_time < MAX_FULL_BIT))
- action = action | 1; // high_time = long
- else if (!((high_time > MIN_HALF_BIT) && (high_time < MAX_HALF_BIT)))
- {
- sys = 0; // RC5 ERROR
- cmd = 0;
- return;
- }
- // Check Low Time
- if ((low_time > MIN_FULL_BIT) && (low_time < MAX_FULL_BIT))
- action = action | 2; // low_time = long
- else if (!((low_time > MIN_HALF_BIT) && (low_time < MAX_HALF_BIT)))
- {
- sys = 0; // RC5 ERROR
- cmd = 0;
- return;
- }
- switch (action)
- {
- case 0:RC5_Shift_Bit(0); // short low, short high, shift 0
- break;
- case 1:RC5_Shift_Bit(1); // short low, long high, shift 1
- half_bit = 1; // new half bit is true
- break;
- case 2:sys = 0; // long low, short high, ERROR
- cmd = 0;
- case 3:RC5_Shift_Bit(1); // long low, long high, shift 1,0
- RC5_Shift_Bit(0);
- break;
- case 4:RC5_Shift_Bit(1); // short low, short high, shift 1
- break;
- case 5:sys =
LPC1114红外遥控解码程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)