合泰项目

项目简介

  基于合泰芯片BS84B08A-3触摸芯片设计T10机种泡沫盾板原理图PCB,并编写其对应触摸功能程序。

项目实现

  通过合泰芯片BS84B08A-3触摸芯片,结合AD实现触摸板PCB绘制,结合外设空气泵,实现喷泡沫功能。

具体步骤

  通过IC规格书,以及PCB触摸覆铜注意事项,设计对应IO控制对应功能,以 原理图 为例:

BS84B08A-3触摸原理图

  以 控制空气泵 为例:

  1#include "USER_PROGRAM.H"  
  2#include "BaseRef.H"
  3//#define LPump_2ndOpen      120-30 //药泵第二次加药时间
  4//#define LPump_3rdOpen      120-60 //药泵第三次加药时间
  5//#define LPump_4thOpen      120-90 //药泵第四次加药时间
  6//#define LPump_5Open      (15000-12000)/2 //药泵第五次加药时间
  7#define LPump_1stOpen     7//80/10          //药泵第一次加药时间
  8#define LPumpOpenTime     9//100/10          //药泵每次加药时间
  9#define LPumpTimes        1              //药泵第每次加药次数
 10#define LPumpColseTime    1//2/2            //药泵两次小加药时间间隔
 11#define AirTime           50//500/10          //结束时吹气时间
 12#define IntervalTime      250//2500/10         //吸药间隔时间
 13#define FoamTimesLeft     210//70*3            //吸药次数剩余
 14
 15u8   FoamTime;                 //泡沫盾总时间
 16//u16 CNT_LedFlicker;  
 17void FOAMCONTROL()
 18{
 19/* 
 20if(Flag_FoamFirstOn==0)
 21{
 22Flag_FoamFirstOn=1;    //只进一次
 23CNT_LPumpOpenTime=15;  //赋予吸药时间
 24CNT_LPumpTimes=1;      //赋予吸药次数
 25}
 26*/
 27   if(FoamTime>0&&FoamTime<250)
 28   {  
 29    CNT_1S=0; 
 30    APump=1;
 31    if(CNT_FoamTime==0)
 32    {
 33       CNT_LPumpOpenTime=LPump_1stOpen+CPS_LpumpTime;         //赋予吸药时间
 34       CNT_LPumpTimes=LPumpTimes;              //赋予吸药次数
 35       CPS_LpumpTime=0;
 36       CNT_FoamTime=IntervalTime;
 37        
 38      }
 39      if(CNT_FoamTime>0) 
 40       CNT_FoamTime--;
 41      if(CNT_FoamTime==0)
 42      {
 43       CNT_LPumpOpenTime=LPumpOpenTime;         //赋予吸药时间
 44       CNT_LPumpTimes=LPumpTimes;              //赋予吸药次数
 45       CNT_FoamTime=IntervalTime;
 46      }
 47 //     if(FoamTime==1)   CNT_APumpTime=AirTime;        //赋予空气泵开启时间,用于吹出管中残余水
 48   }
 49   else
 50   {
 51 /*   
 52      if(CNT_APumpTime>0)
 53      {
 54        CNT_APumpTime--;
 55        APump=1;
 56      } 
 57      else
 58 */          
 59 //     {
 60        APump=0;
 61        CNT_FoamTime=0;
 62 //     }   
 63   }
 64   LPumpControl();  
 65}
 66
 67//液泵控制
 68void LPumpControl()
 69{
 70 if(CNT_LPumpTimes>0)
 71 {
 72  /*
 73     if(CNT_LPumpOpenTime>LPumpColseTime)  
 74  else    
 75  {
 76    LPump=0; 
 77    Flag_ADService=0;
 78  }
 79  */
 80  LPump=1; 
 81  if(CNT_LPumpOpenTime==LPumpOpenTime-2)          //开启AD,检测电流
 82  {
 83   Flag_ADService=1;
 84   AD_COUNT=0;
 85   AD_SUM=0;
 86  } 
 87  CNT_LPumpOpenTime--;
 88  if(CNT_LPumpOpenTime==0)  
 89        {
 90   if(CNT_LPumpTimes>1)   CNT_LPumpOpenTime=LPumpOpenTime;
 91   CNT_LPumpTimes--;
 92   if(Flag_FloatKeyDown) 
 93   { 
 94    if(CNT_FoamTimesLeft<FoamTimesLeft)  
 95     CNT_FoamTimesLeft++;
 96    else     
 97     Flag_LiquidLow=1;   
 98   }
 99   else
100   {
101    CNT_FoamTimesLeft=0;
102    Flag_LiquidLow=0;
103   }    
104        }
105    }
106 else
107 {
108  LPump=0;
109  CNT_LPumpOpenTime=0;
110  CNT_LPumpTimes=0;
111    }
112}

  以 触摸控制 为例:

  1#include    "USER_PROGRAM.H"  
  2#include  "BaseRef.H"
  3
  4u8 Touch_ok;                               //按键输出值
  5 
  6union Fbit  KeyFlag;                         //按键程序相关标志位
  7#define  Flag_First_Check       KeyFlag.Flag.b0  
  8#define  Flag_Get_Baseline      KeyFlag.Flag.b1  
  9//-------------------------------------------------------------------------------------
 10u16    BaseLine;                              //基线值
 11u16   Value_Touch_Key_Old,Value_Touch_Key_New,Temp_Value_Touch_Key;
 12u16  TimesCNT_Baseline;//,Times_Leg_In;
 13
 14Longword  Temp_Count_Touch_Key; 
 15
 16#define Para_Baseline_Tolerance  2   //公差
 17#define   Gap_Leg_In     4
 18
 19#define   Times_Gap_Leg_In_Short  5
 20#define Times_Gap_Leg_In_Long  200
 21#define   Times_Gap_Leg_Out   3
 22
 23#define Para_TimesCNT_Baseline_First_ON  256  
 24#define Para_TimesCNT_Baseline    1000
 25
 26Byte  Key_Value,Key_Old,Key_Ok,Key_Status,Key_Mid;
 27Word Key_CNT;
 28Word Key_CNT_Pressed;
 29Byte  Key_CNT_Off;
 30#define     Key_Handled                                Key_Status,B(0)
 31
 32u8 n;
 33//-------------------------------------------------------------------------------------
 34void TOUCH_KEY()
 35{
 36Word   j;
 37Longword  i;
 38  //---------Baseline_L------------------------------
 39  Value_Touch_Key_Old=Value_Touch_Key_New;
 40  Value_Touch_Key_New=TOUCH_VALUE_H;
 41  Value_Touch_Key_New=(Value_Touch_Key_New<<8)+TOUCH_VALUE;
 42  
 43  //------The first check for Touch Key, find out the Baseline_L--------------------------------------------
 44  if(Flag_First_Check==0) 
 45   {
 46   if(Value_Touch_Key_New>=Value_Touch_Key_Old) j=Value_Touch_Key_New-Value_Touch_Key_Old;
 47   else           j=Value_Touch_Key_Old-Value_Touch_Key_New;
 48   
 49   if(j<=Para_Baseline_Tolerance) 
 50    {
 51    TimesCNT_Baseline++;
 52    Temp_Count_Touch_Key+=Value_Touch_Key_New;
 53    if(TimesCNT_Baseline>=Para_TimesCNT_Baseline_First_ON) 
 54     {  
 55     i=Temp_Count_Touch_Key/Para_TimesCNT_Baseline_First_ON;
 56     BaseLine=(u16)i;
 57     TimesCNT_Baseline=0;
 58     Temp_Count_Touch_Key=0;
 59     Flag_First_Check=1;
 60     
 61     Key_Status=1;
 62     }
 63    }
 64   else 
 65    {
 66    TimesCNT_Baseline=0;
 67    Temp_Count_Touch_Key=0;
 68    }
 69   }
 70  //----------After the first check the touch key--------------------------
 71  else  
 72   {
 73   if(Flag_Get_Baseline==0)
 74    {
 75    if(n<20)
 76     {
 77     n++;
 78     Temp_Count_Touch_Key+=Value_Touch_Key_New;
 79     }
 80    else
 81     {
 82     n=0;   
 83     Temp_Value_Touch_Key=(Word)(Temp_Count_Touch_Key/20);
 84     Temp_Count_Touch_Key=0;
 85     Flag_Get_Baseline=1;
 86     }
 87    }
 88   if(Flag_Get_Baseline)
 89    {
 90    if((Value_Touch_Key_New<=Temp_Value_Touch_Key+Para_Baseline_Tolerance)&&(Value_Touch_Key_New>=Temp_Value_Touch_Key-Para_Baseline_Tolerance))
 91     {
 92     TimesCNT_Baseline++;
 93     if(TimesCNT_Baseline>=Para_TimesCNT_Baseline) 
 94      {  
 95      TimesCNT_Baseline=0;
 96      BaseLine=Temp_Value_Touch_Key;
 97      Flag_First_Check=1;
 98      Flag_Get_Baseline=0;
 99      }
100     }
101    else  
102     {
103     Flag_Get_Baseline=0;
104     TimesCNT_Baseline=0;
105     Temp_Value_Touch_Key=0;
106     }
107    }
108   }     
109
110  //--------------------------------------------------------------------------  
111  if(BaseLine>0)
112   {
113   //-----------Key_Scan--------------------------
114   if(Value_Touch_Key_New>=BaseLine+Gap_Leg_In)     {Key_Value=1;Key_Mid=0;}
115   else if(Value_Touch_Key_New<BaseLine+Para_Baseline_Tolerance)  {Key_Value=0;Key_Mid=0;}
116   else  Key_Mid=1;
117
118   if(Key_Mid==0)
119    {     
120    if(Key_Value==1)    
121     {
122     if(Key_CNT_Pressed<600) Key_CNT_Pressed++; 
123
124     if(Key_CNT_Pressed==500)
125      {
126      Touch_ok=2;
127      SET(Key_Handled);
128      }    
129     Key_CNT_Off=0;
130     }
131    else
132     {     
133     if(Key_CNT_Off<2) Key_CNT_Off++;
134     else
135      {
136      if(Key_CNT_Pressed>=10&&Key_CNT_Pressed<150)
137       {
138       Touch_ok=1;
139       SET(Key_Handled);
140       }
141      Key_CNT_Pressed=0;
142      }
143     }
144    }
145   }
146  
147}

  本文完整源码已上传本人gitee,点击查看

版权