• 模拟红外协议C程序——接收模块


    目的:方便程序的调试,提供效率,减少工作累,可以不在线调试编程时显示实时数据,特别产品不带显示的或者MCU是OPT的,有很大的帮助。

    过程:将要看的数据发送出来,另一个板(一个带有显示的就OK了,显示就看个人的了,我之前用12864显示,后面坏了,就用4位数码管了)接收显示出来。

    资源:通讯口只要2个IO(接收一个,发送一个),定时器2个(接收一个,发送一个)。

    此篇是本人的接收模块,由于手头没有什么显示板,只有一个中颖的,带有4为数码管,就用此板作模拟接收。

    此接收发送模块已经使用3年,一点问题都没有的哦!!!

    如要沟通,请联系QQ:448704229

    以下是接收模块:

    //REMOTE 为接收IO ,设置为输入
    
    static uint8 rx_ram0=0;
    static uint8 rx_ram1=0;
    static  uint8 rx_ram2=0;
    static  uint8	bits_count=0;
    
    static  uint8	tx_ram0=0;
    static  uint8	tx_ram1=0;
    static  uint8	tx_ram2=0;
    static  uint8	temp2=0;
    static  uint8	us100_timer=0;
    
    bit	f_endcode=0;
    bit	B_nextbit=0;
    bit	send_enable_flag=0;
     uint8	temp1=0;
      uint8	temp=0;
    void recievr_ird(void)
    {
    
    
       	static uint8 TN=0;
    		static uint8 REMOTE_NUM=0;
      if(TN<=200)
    	  {
    	  	  TN++;
    	   }
    		  if(!F_REMOTE)
    		  {
    		  	if(REMOTE)
    			{
    				if(!F_RISE_YK)
    				{
    					 F_RISE_YK=1;
    					 if(F_YK_FIRST)
    					 {
    					 	 if(TN>=5)
    						 {
    						 //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    						 	
    						 }
    						 else
    						 {
    						 	 TN=0;
    						 }
    					 }
    					 else
    					 {
    					 	if(TN>=40)
    						{
    						 //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    						}
    						else
    						{
    						   	if(TN>=20)
    							{
    								F_YK_FIRST=1;
    								TN=0;
    								REMOTE_NUM=0;
    								tx_ram0=0;
    							
    							}
    							else
    							{ //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    							}
    
    						}
    					 }
    				}
    			
    			}
    			else
    			{
    					if(F_RISE_YK)
    					{
    						 F_RISE_YK=0;
    						 if(F_YK_FIRST)
    						 {
    						 	 if(!F_YK_SECOND)
    							 {
    							  	if(TN>=18)
    								{
    								  //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    								}
    						
    								else
    								{
    								   	if(TN>=12)
    									{
    										F_YK_SECOND=1;
    										TN=0;
    										REMOTE_NUM=0;
    										tx_ram0=0;
    									
    									}
    									else
    									{
    									   //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    									}
    
    								}
    							 }
    							 else
    							 {
    				   
    								 tx_ram2=tx_ram2>>1;
    
    								if(tx_ram1&0x01)
    								{
    									 tx_ram2=tx_ram2|0x80;
    								}
    								else
    								{
    									 tx_ram2=tx_ram2&0x7f;
    								}
    
    								  tx_ram1=tx_ram1>>1;
    
    								if(tx_ram0&0x01)
    								{
    									 tx_ram1=tx_ram1|0x80;
    								}
    								else
    								{
    									 tx_ram1=tx_ram1&0x7f;
    								}
    								 tx_ram0=tx_ram0>>1;
    
    
    								 	if(TN>=12)
    								{
    								  //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    	
    								}
    						
    								else
    								{
    								   	if(TN>=6)
    									{
    									
    									  tx_ram0|=0x80;	  ///
    									  B_nextbit=1;
    									}
    									else
    									{
    											if(TN<2)
    										{
    									 //EER
    								   	 		 //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    	
    										}
    										else
    										{
    											tx_ram0&=0x7f;	  ///
    											B_nextbit=1;
    										}
    									 
    									}
    								}
    							 }
    						 }
    						 else
    						 {
    						  //EER
    						    TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    						 }
    					 }
    			}
    		  
    		  }
    if(B_nextbit)//移位操作//<intrins.h> temp = _cror_(temp,1);_rcl
    {
    	B_nextbit=0;
      TN=0;
    	REMOTE_NUM++;
    	
    	if(REMOTE_NUM>=24)
    	{
    		rx_ram0=tx_ram2;
    	   F_REMOTE=1;
        	rx_ram1=tx_ram1;
    		rx_ram2=tx_ram0;
    	F_REMOTE=0;
    
    	 TN=0;
    	  						tx_ram0=0;
    						    REMOTE_NUM=0;
    							F_YK_FIRST=0;
    							F_YK_SECOND=0;
    	}
    }
    }


     

  • 相关阅读:
    RHEL7: How to configure a rc-local service
    安装 jemalloc for mysql
    aws rhel 7 安装GUI ,配置VNC
    官方推荐的MySQL参数设置值
    Linux HugePages及MySQL 大页配置
    Linux Transparent Huge Pages 对 Oracle 的影响
    Linux的Transparent Hugepage与关闭方法
    Linux HugePages 配置与 Oracle 性能关系说明
    How To Change Log Rate Limiting In Linux
    MySQL 8.0窗口函数
  • 原文地址:https://www.cnblogs.com/riskyer/p/3263243.html
Copyright © 2020-2023  润新知