1、bit Hbit;Hbit=HandSignal;/*采样信号线*/if (NewKey=FALSE)/*如果上一次按键事件已经北处理*/switch (ib_HandState) /*根据接收状态散转*/case LEAD:/*引导头接收情况*/if (Hbit) /*如果信号线是高电平*/if (ib_LowTimeMIN_LeadTime)&(ib_LowTimeMAX_LeadTime)/*判断低电平时间是否超时*/ib_HandState=RESTART; /*是的话复位接收程序*/break; case START:/*同步头接收情况*/if(Hbit)/*如果信号线是高电平*/i
2、b_HighTime+;/*高电平时间计数器加一*/if (ib_HighTimeMAX_SynTime)/*如果高电平时间超长,复位接收程序*/ /*如果信号线是低电平*/if (ib_HighTimeMIN_SynTime)&(ib_HighTime=1;/*接收数据字节右移一位*/MIN_B1TIME)&MAX_B1TIME) /*如果高电平宽度符合逻辑1标准,接收字节高位置一*/ib_KeyCodeib_KeyPoint+=0x80; ib_BitCount+;/*接收数据位计数器加一*/if (ib_BitCount7) /*如果接收满一个字节*/ib_BitCount=0; /*清
3、空位计数器*/ib_KeyPoint+;/*指向下一个字节*/if (ib_KeyPoint3)/*如果接收完整个数据*/unsigned char i;NewKey=TRUE;/*置有新键按下标志*/for (i=0;i4;i+) /TI=0; /SBUF=ib_KeyCode; /while(!TI);/ /ib_HandState=RESTART; ib_HighTime=0; /*将高电平时间计数器清零*/*设定系统为等待上升沿状态*/default:if (ib_HandState=RESTART)/*如果程序处于复位状态*/ /*复位各项参数*/ib_HandState=LEAD;
4、ib_KeyCode0=0; ib_KeyCode1=0;ib_KeyCode2=0; ib_KeyCode3=0;ib_KeyPoint=0;NewKey=FALSE;好多遥控器(无线,红外)发射数据都是PPM调制的,以上程序稍微改动后可以应用于各种PPM调制信号的场合。44矩阵式键盘识别技术#include unsigned char ID;void delay10ms(void) unsigned char i,j;for(i=20;i0;i-)for(j=248;jj-); void delay02s(void) unsigned char i;delay10ms();void mai
5、n(void) while(1) if(P3_7=0) if(P3_7=0) ID+;if(ID=4) ID=0;while(P3_7=0);switch(ID) case 0:P1_0=P1_0;delay02s();case1:P1_1=P1_1;case 2:P1_2=P1_2;case 3:P1_3=P1_3;支持键盘双击事件的C程序设计!/*KeyBoard Encode ProgramThis Program can encode press_key up to 128 and it can deal KB_DBClick MessageThis is just a test pr
6、oram and only use 2 key.If More Key need to Encode ,please modify the function:KBKeyPress() This Porgram use Message_Driver method,the KB_Msg is used to record what KB_Msg has occured.The meaning of SysKBMsg is list as following. Program Design:LiBaizhanVer:1.10Date:2003-3-16*/reg51.hintrins.hsbitKe
7、y1 =P10;Key2P11; Some System Var Pre_Definition Crystal Frequence is 11.0592MHz#defineTIME_2MS 0X74TIME_20MS0X043BKB_INTERNAL 3/*Key DBClk Detection Internal */SysKBMsg define Keyboard Message,it include Single_Click or Double_ClickIts bit6bit0 record key_encode and bit 7 record DBClk(1) or SglClk(0
8、)It can record and encode up to 127(27-1) keysNo key is press when it is 0This method did not deal key such as Ctrl_Key or Alt_Key or Shift_Key.etc./*_*/data unsigned char SysKBMsg=0;/*|7|6543210|*/*| D/S | KB6 | KB5 | KB4 | KB3 | KB2 | KB1 | KB0 |*/data unsigned char KBCounter=0;bitKBCounterStart=0
9、;KBCounterStop=0;/*if KeyBoard counter stop then this bit is 1*/KBCounterFlag=0;/*Current Counter is used by KeyBoard*/void TimerInt0(void) interrupt 1 /*timer 0 interrupt use to record how long key is press*/TR0=0;if(KBCounterFlag) /*Current Counter is used by KeyBoard*/if(KBCounterKB_INTERNAL)/*if
10、 DBClk Detection is not finish then detect continue*/KBCounter+;TR0=1;elseKBCounter=0;/*DBClk Detection is finish*/KBCounterStop=1;void DelayMS(unsigned int dltime);void Init51(void);unsigned char KBKeyPress(void);/*only return what key is press*/void KBKeyEncode(void); /*encode which key is pressed
11、 and DBClk or SglClk*/void KBStartTimer(unsigned char CntH,unsigned char CntL);/*load counter initial value and start timer*/void KBStopTimer(void);void KBDealPressKey(void); /*deal key_press message*/Init51();while(1)KBKeyEncode(); /*recored what KeyBoard Msg occure:which key is press and single cl
12、k or db clk*/KBDealPressKey();Delay Time is :(20+17*dl_time)*12/CrystalFrequence(us)void DelayMS(unsigned int dltime)unsigned int i;for(i=0;dltime;i+);void Init51(void)SCON= 0x50; /* mode 1: 8-bit UART, enable receiverTMOD= 0x21; /* timer 1 mode 2: 8-Bit reload/* timer 0 mode 1: 16-bit TimerTH1= BAUD_4800;/* reload value 9600 baudTR1= 1; /* timer 1 runIE = 0X12; /* enable Serial INT,Timer0 INTES = 0; /* disable Serial INT*/EA = 1;
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2