打印

有20路传感器读传感器值的问题

[复制链接]
1407|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
badbird1234|  楼主 | 2009-3-3 16:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我现在用PIC普通口分别扫描20路传感器的值(传感器有行程开关和光电传感器)
现在有这样一个问题由于我想到抗干扰的问题
人为设为传感器有变化就读进来而其延时100MS抗感扰
我把他们分为4个字节存放
部分代码如下
//函数名:shaomiao()
//功能:扫描传感器 
//输入参数:无
//输出参数:无
//__________________________________________________________________________________________________

void shaomiao(void)
{

shao_b0=PORTB&0x3F;
shao_f0=PORTF&0x0F;

                     if(shao_b1!=shao_b0){
            
                                          shao_b1=shao_b0;
                                           bian1=1;
                                          delaycount1=6;//延时100MS

                                                                                           


                                          }
                       if(shao_f1!=shao_f0){
            
                                          shao_f1=shao_f0;
                                           bian2=1;
                                          delaycount2=6;

                                                                                           


                                          }
                                                             


if(bian1){if(delaycount1==0)
                                  {
                                  
                                      bian1=0;

                                          
                                    PORTB_TMP=shao_b1;    
                                      

                                  }


                }


if(bian2){if(delaycount2==0)
                                  {
                                  
                                      bian2=0;

                                          
                                    PORTF_TMP=shao_f1;    
                                      

                                  }


             }





}
我现在有这样的问题
如果有传感器不正长一值跳变
那我岂不一直读不进来了那
请问有没有更好的办法
或帮我改改
谢谢了

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

38

主题

254

帖子

0

粉丝