#include"lpc11xx.h"#include"ct.h"#include"ili9325.h"#include"w25q16.h"uint8_tpulse_start=0;//脈沖開始標志uint8_tpulse_bnum=0;//脈沖計數(shù)器uint8_tpulse_ok=0;//發(fā)現(xiàn)前導碼uint8_tkey_repeat=0;//持續(xù)按鍵uint16_ttc_buf=0;uint16_tir_buf[64];//裝載用戶碼和數(shù)據(jù)碼uint8_tuser_code_hi;uint8_tuser_code_lo;uint16_tuser_code;uint8_tkey_code;uint8_tkey_code_lo;uint8_tir_sign;//接收到按鍵標志uint8_tir_process(void){uint8_ti;uint16_tbuf;for(i=0;i<16;i++){user_code_hi<<=1;buf=ir_buf[i]+ir_buf[++i];if((buf>2100)&&(buf<2450)){user_code_hi+=1;}}for(i=16;i<32;i++){user_code_lo<<=1;buf=ir_buf[i]+ir_buf[++i];if((buf>2100)&&(buf<2450)){user_code_lo+=1;}}for(i=32;i<48;i++){key_code<<=1;buf=ir_buf[i]+ir_buf[++i];if((buf>2100)&&(buf<2450)){key_code+=1;}}for(i=48;i<64;i++){key_code_lo<<=1;buf=ir_buf[i]+ir_buf[++i];if((buf>2100)&&(buf<2450)){key_code_lo+=1;}}if(key_code==(uint8_t)~key_code_lo){user_code=(user_code_hi<<8)+user_code_lo;return1;//正確接收}elsereturn0;}voidTIMER16_1_IRQHandler(void){if((LPC_TMR16B1->IR&0x10)==0x10){tc_buf=LPC_TMR16B1->TC;LPC_TMR16B1->TC=0;if((tc_buf>8500)&&(tc_buf<9500))//如果發(fā)現(xiàn)9ms{pulse_start=1;LPC_TMR16B1->IR=0X10;//清CAP0中斷位return;}if(pulse_start==1){if((tc_buf>4000)&&(tc_buf<5000))//如果發(fā)現(xiàn)4.5ms{pulse_ok=1;LPC_TMR16B1->IR=0X10;//清CAP0中斷位pulse_start=0;key_repeat=1;return;}elseif((tc_buf>2000)&&(tc_buf<3000))//如果發(fā)現(xiàn)2.5ms{key_repeat++;LPC_TMR16B1->IR=0X10;//清CAP0中斷位pulse_start=0;ir_sign=1;return;}}if(pulse_ok==1){ir_buf[pulse_bnum]=tc_buf;pulse_bnum++;if(pulse_bnum==64){pulse_ok=0;pulse_bnum=0;ir_sign=1;}}}LPC_TMR16B1->IR=0X10;//清CAP0中斷位}intmain(void){LCD_Init();LCD_Clear(BLUE);W25Q16_Init();IR_Init();POINT_COLOR=WHITE;BACK_COLOR=BLUE;LCD_ShowString(12,12,"紅外遙控檢測機");LCD_ShowString(12,50,"您拿的紅外遙控器用戶碼是:");LCD_ShowString(12,90,"您剛才按下的鍵碼是:");LCD_ShowString(12,130,"您已經(jīng)連續(xù)按下此鍵的次數(shù)是:");while(1){if((ir_sign==1)&&(ir_process()==1))//接收到一個按鍵{LCD_ShowNum(50,70,user_code,5);LCD_ShowNum(50,110,key_code,3);LCD_ShowNum(50,150,key_repeat,3);ir_sign=0;}}}