ºìÍâÒ£¿ØÊÇÒ»ÖÖÎÞÏß¡¢·Ç½Ó´¥¿ØÖƼ¼Êõ£¬¾ßÓп¹¸ÉÈÅÄÜÁ¦Ç¿£¬ÐÅÏ¢´«Êä¿É¿¿£¬¹¦ºÄµÍ£¬³É±¾µÍ£¬Ò×ʵÏÖµÈÏÔÖøÓŵ㣬±»Öî¶àµç×ÓÉ豸ÌرðÊǼÒÓõçÆ÷¹ã·º²ÉÓ㬲¢Ô½À´Ô½¶àµÄÓ¦Óõ½¼ÆËã»úϵͳÖС£ÓÉÓÚºìÍâÏßÒ£¿Ø²»¾ßÓÐÏñÎÞÏßµçÒ£¿ØÄÇÑù´©¹ýÕÏ°ÎïÈ¥¿ØÖƱ»¿Ø¶ÔÏóµÄÄÜÁ¦£¬ËùÒÔ£¬ÔÚÉè¼ÆºìÍâÏßÒ£¿ØÆ÷ʱ£¬²»±ØÒªÏñÎÞÏßµçÒ£¿ØÆ÷ÄÇÑù£¬Ã¿Ì×(·¢ÉäÆ÷ºÍ½ÓÊÕÆ÷)ÒªÓв»Í¬µÄÒ£¿ØƵÂÊ»ò±àÂë(·ñÔò£¬ ¾Í»á¸ôǽ¿ØÖÆ»ò¸ÉÈÅÁھӵļÒÓõçÆ÷)£¬ ËùÒÔͬÀà²úÆ·µÄºìÍâÏßÒ£¿ØÆ÷£¬ ¿ÉÒÔÓÐÏàͬµÄÒ£¿ØƵÂÊ»ò±àÂ룬 ¶ø²»»á³öÏÖÒ£¿ØÐźš° ´®ÃÅ¡± µÄÇé¿ö¡£ Õâ¶ÔÓÚ´óÅúÁ¿Éú²úÒÔ¼°ÔÚ¼ÒÓõçÆ÷ÉÏÆÕ¼°ºìÍâÏßÒ£¿ØÌṩÁ˼«´óµÄ·½Ãæ¡£ ÓÉÓÚºìÍâÏßΪ²»¿É¼û¹â£¬ Òò´Ë¶Ô»·¾³Ó°ÏìºÜС£¬ ÔÙÓɺìÍâ¹â²¨¶¯²¨³¤Ô¶Ð¡ÓÚÎÞÏߵ粨µÄ²¨³¤£¬ ËùÒÔºìÍâÏßÒ£¿Ø²»»áÓ°ÏìÆäËû¼ÒÓõçÆ÷£¬ Ò²²»»áÓ°ÏìÁÙ½üµÄÎÞÏßµçÉ豸¡£
ºìÍâÒ£¿ØµÄ±àÂ뷽ʽĿǰ¹ã·ºÊ¹ÓõÄÊÇ£º PWM(Âö³å¿í¶Èµ÷ÖÆ)µÄ NEC ÐÒéºÍ Philips PPM(Âö³åλÖõ÷ÖÆ)µÄ RC-5 ÐÒéµÄ¡£ Ä¿Ç°´ó²¿·ÖÒ£¿ØÆ÷ʹÓõÄÊÇ NEC ÐÒ飬 ÆäÌØÕ÷ÈçÏ£º
8 λµØÖ·ºÍ 8 λָÁ¶È£»
µØÖ·ºÍÃüÁî 2 ´Î´«Ê䣨 È·±£¿É¿¿ÐÔ£©
PWM Âö³å¿í¶Èµ÷ÖÆ£¬ ÒÔ·¢ÉäºìÍâÔز¨µÄÕ¼¿Õ±È´ú±í¡° 0¡± ºÍ¡° 1¡± £»
Ôز¨ÆµÂÊΪ 38Khz£»
λʱ¼äΪ 1.125ms »ò 2.25ms£»
Ò»¸öÂö³å¶ÔÓ¦ 560us µÄÁ¬ÐøÔز¨£¬ Ò»¸öÂß¼ 1 ´«ÊäÐèÒª 2.25ms£¨ 560us µÍ+1680us ¸ß£© £¬ Ò»¸öÂß¼ 0 µÄ´«ÊäÐèÒª 1.125ms£¨ 560us µÍ+560us ¸ß£© ¡£
NEC Ò£¿ØÖ¸ÁîµÄÊý¾Ý¸ñʽΪ£º ͬ²½ÂëÍ·¡¢ µØÖ·Âë¡¢ µØÖ··´Âë¡¢ ¿ØÖÆÂë¡¢ ¿ØÖÆ·´Âë¡£
ͬ²½ÂëÓÉÒ»¸ö 9msµÄµÍµçƽºÍÒ»¸ö 4.5ms µÄ¸ßµçƽ×é³É£»
µØÖ·Âë¡¢µØÖ··´Âë¡¢¿ØÖÆÂë¡¢¿ØÖÆ·´Âë¾ùÊÇ 8 λÊý¾Ý¸ñʽ¡£ °´ÕÕµÍλÔÚÇ°£¬ ¸ßλÔÚºóµÄ˳Ðò·¢ËÍ¡£
Á¬·¢Â룺ÓÉ 97.94ms µÄ¸ßµçƽ×é³É¡¢9ms µÄµÍµçƽ¡¢ 2.5ms µÄ¸ßµçƽ¡¢ 0.56ms µÄµÍµçƽ£»
ÏÂÃæÊÇÒ»¸öºìÍâÐźŵIJ¨ÐÎͼ
´ÓÉÏͼÖпÉÒÔ¿´µ½£¬ ÆäµØÖ·ÂëΪ 0£¬ ¿ØÖÆÂëΪ 96¡£ ¿ÉÒÔ¿´µ½ÔÚ 100ms Ö®ºó£¬ ÎÒÃÇ»¹ÊÕµ½Á˼¸¸öÂö³å£¬ ÕâÊÇNEC Âë¹æ¶¨µÄÁ¬·¢Âë(ÓÉ 9ms µÄµÍµçƽ¡¢ 2.5ms µÄ¸ßµçƽ¡¢ 0.56ms µÄµÍµçƽ¡¢ 97.94ms µÄ¸ßµçƽ×é³É)£¬ Èç¹ûÔÚÒ»Ö¡Êý¾Ý·¢ËÍÍê±ÏÖ®ºó£¬ °´¼üÈÔȻûÓзſª£¬ Ôò·¢ÉäÖظ´Â룬 ¼´Á¬·¢Â룬 ¿ÉÒÔͨ¹ýͳ¼ÆÁ¬·¢ÂëµÄ´ÎÊýÀ´±ê¼Ç°´¼ü°´Ïµij¤¶Ì/´ÎÊý¡£
½ÓÊÕ²¿·Öµç·Á¬½Ó£º
µ±ºìÍâ½ÓÊÕ¶þ¼«¹ÜÊÕµ½Á¬ÐøµÄ38KHzµÄºìÍâÐźź󣬽«Êä³öÁ¬ÐøµÄµÍµçƽ£¬·ñÔòÊä³ö¸ßµçƽ¡£¼´£º
·¢ËÍ·½£º 38KHzPWM²¨ÐźÅÇý¶¯ºìÍâ·¢Éä¶þ¼«¹Ü Êä³öµÍµçƽ£¬¸ö¡¢·¢Éä¶þ¼«¹Ü²»¹¤×÷
½ÓÊÕ·½£º ÊÕµ½µÍµçƽ ÊÕµ½¸ßµçƽ
×ÛÉÏ£¬¿ÉÒÔʹÓÃSTM32µÄ¶¨Ê±Æ÷µÄÊäÈ벶»ñ¹¦ÄÜ£¬ÊµÏÖ¶ÔºìÍâÐźŵĽâÂ룬ʹÓÃSTM32µÄ¶¨Ê±Æ÷µÄPWMÊä³öʵÏÖ¶ÔºìÍâÐźŵıàÂ빦ÄÜ¡£
ºìÍâ½âÂ룺
//Ò£¿ØÆ÷½ÓÊÕ״̬ //bit7:ÊÕµ½ÁËÒýµ¼Âë±êÖ¾ //bit6:µÃµ½ÁËÒ»¸ö°´¼üµÄËùÓÐÐÅÏ¢ //bit5:±£Áô //bit4:±ê¼ÇÉÏÉýÑØÊÇ·ñÒѾ±»²¶»ñ //bit[3:0]:Òç³ö¼ÆʱÆ÷ u8 remoteState=0; u16 captureva lue;//ϽµÑØʱ¼ÆÊýÆ÷µÄÖµ u32 remoteCode=0;//ºìÍâ½ÓÊÕµ½µÄÊý¾Ý u8 remoteCnt=0;//°´¼ü°´ÏµĴÎÊý void TIM2_IRQHandler(void) { u16 state; if(TIM_GetITStatus(TIM2,TIM_IT_Update)!=RESET) { if(remoteState&0x80)//ÉÏ´ÎÓÐÊý¾Ý±»½ÓÊÕµ½ÁË { remoteState&=~0X10;//È¡ÏûÉÏÉýÑØÒѾ±»²¶»ñ±ê¼Ç if((remoteState&0X0F)==0X00)remoteState|=1<<6;//±ê¼ÇÒѾÍê³ÉÒ»´Î°´¼üµÄ¼üÖµÐÅÏ¢²É¼¯ if((remoteState&0X0F)<14)remoteState++; else { remoteState&=~(1<<7);//Çå¿ÕÒýµ¼±êʶ remoteState&=0XF0;//Çå¿Õ¼ÆÊýÆ÷ } } } if(TIM_GetITStatus(TIM2,TIM_IT_CC2)!=RESET) { if(RDATA)//ÉÏÉýÑز¶»ñ { TIM_OC2PolarityConfig(TIM2,TIM_ICPolarity_Falling);//CC1P=1 ÉèÖÃΪϽµÑز¶»ñ TIM_SetCounter(TIM2,0); //Çå¿Õ¶¨Ê±Æ÷Öµ remoteState|=0X10;//±ê¼ÇÉÏÉýÑØÒѾ±»²¶»ñ } else //ϽµÑز¶»ñ { captureva lue=TIM_GetCapture2(TIM2);//¶ÁÈ¡CCR2Ò²¿ÉÒÔÇåCC1IF±ê־λ TIM_OC2PolarityConfig(TIM2,TIM_ICPolarity_Rising); //CC4P=0ÉèÖÃΪÉÏÉýÑز¶»ñ if(remoteState&0X10)//Íê³ÉÒ»´Î¸ßµçƽ²¶»ñ { if(remoteState&0X80)//½ÓÊÕµ½ÁËÒýµ¼Âë { if(captureva lue>300&&captureva lue<800)//560Ϊ±ê×¼Öµ,560us { remoteCode<<=1;//×óÒÆһλ. remoteCode|=0;//½ÓÊÕµ½0 } else if(captureva lue>1400&&captureva lue<1800)//1680Ϊ±ê×¼Öµ,1680us { remoteCode<<=1;//×óÒÆһλ. remoteCode|=1;//½ÓÊÕµ½1 } else if(captureva lue>2200&&captureva lue<2600)//µÃµ½°´¼ü¼üÖµÔö¼ÓµÄÐÅÏ¢ 2500Ϊ±ê×¼Öµ2.5ms { remoteCnt++; //°´¼ü´ÎÊýÔö¼Ó1´Î remoteState&=0XF0;//Çå¿Õ¼ÆʱÆ÷ } } else if(captureva lue>4200&&captureva lue<4700)//4500Ϊ±ê×¼Öµ4.5ms { remoteState|=1<<7;//±ê¼Ç³É¹¦½ÓÊÕµ½ÁËÒýµ¼Âë remoteCnt=0;//Çå³ý°´¼ü´ÎÊý¼ÆÊýÆ÷ } } remoteState&=~(1<<4); } } TIM_ClearFlag(TIM2,TIM_IT_Update|TIM_IT_CC2); } |
u8 Remote_Scan(void) { u8 state=0; u8 t1,t2; if(remoteState&(1<<6))//µÃµ½Ò»¸ö°´¼üµÄËùÓÐÐÅÏ¢ÁË { printf("ÊÕµ½µÄÊý¾ÝÊÇ£º0x%X\r\n",remoteCode); t1=remoteCode>>24;//µÃµ½µØÖ·Âë t2=(remoteCode>>16)&0xff;//µÃµ½µØÖ··´Âë if((t1==(u8)~t2)&&t1==REMOTE_ID)//¼ìÑéÒ£¿Øʶ±ðÂë(ID)¼°µØÖ· { t1=remoteCode>>8; t2=remoteCode; if(t1==(u8)~t2)state=t1;//¼üÖµÕýÈ· } if((state==0)||((remoteState&0X80)==0))//°´¼üÊý¾Ý´íÎó/Ò£¿ØÒѾûÓа´ÏÂÁË { remoteState&=~(1<<6);//Çå³ý½ÓÊÕµ½ÓÐЧ°´¼ü±êʶ remoteCnt=0;//Çå³ý°´¼ü´ÎÊý¼ÆÊýÆ÷ } } return state; } |
PWMºìÍâ±àÂ룺
void remote_repeat(u8 cnt) { for(;cnt;cnt--) { Remote_H; Delay_ms(97); Delay_us(940); //97.94ms¸ßµçƽ Remote_L; Delay_ms(9); //9msµÍµçƽ Remote_H; Delay_us(2500); //2.5ms¸ßµçƽ Remote_L; Delay_us(560); //560usµÍµçƽ } } /* u8 addr£ºµØÖ·Âë u8 cmd £º¿ØÖÆÂë u8 cnt £ºÁ¬·¢Âë¸öÊý */ void remote_send(u8 addr,u8 cmd,u8 cnt) { remote_start(); remote_send_byte(addr); remote_send_byte(~addr); remote_send_byte(cmd); remote_send_byte(~cmd); remote_repeat(cnt); remote_end(); } void remote_init(void) { RCC->AHB1ENR |=1<<0; //GPIOAʱÖÓʹÄÜ GPIOA->MODER &=~(0x3<<(1*2)); //GPIOA1ģʽÅäÖà GPIOA->MODER |=1<<(1*2); //Êä³öģʽ GPIOA->OTYPER &=~(1<<1); // GPIOA->OSPEEDR &=~(0x3<<(1*2)); GPIOA->OSPEEDR |=1<<(1*2); //25MHz GPIOA->PUPDR &=~(0x3<<(1*2)); //ÎÞÉÏÏÂÀ GPIOA->ODR &=~(1<<1); } void remote_start(void) //ºìÍâͬ²½ÂëÍ· { Remote_L; Delay_ms(9); //9msµÍµçƽ £¨·¢ËͶËÂö³å £© Remote_H; Delay_ms(4); //4.5ms¸ßµçƽ £¨·¢ËͶ˵͵çƽ£© Delay_us(500); Remote_L; Delay_us(560); //560usÂö³å //ûÓÐÕâ560usÂëÖµ»á´íOK£¿ } void remote_end(void) { Remote_H; } //¸ßλÔÚÇ°Äã¸ÒÐÅ£¿ void remote_send_byte(u8 byte) { u8 i=0; for(i=0;i<8;i++) { Remote_H; if( byte & (0x80>>i) ) Delay_us(1680); //1680usµÍµçƽ else Delay_us(560); //1680usµÍµçƽ Remote_L; Delay_us(560); //560usÂö³å } } |