⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 备份.txt

📁 时间触发式单片机最小系统
💻 TXT
字号:
*----------------------------------------------*-
 Mytask.c
 create my own task
-*----------------------------------------------*/
#include"main.h"
#include"mytask.h"

#define state1 0x01
#define state2 0x02
#define state3 0x03
#define state4 0x04
uchar state;   
void Mytask_Init(void)   
{   
 P3=0xff;                      
 state=state1;   
}                                    
void key_scan(void)                          //利用 state machine 进行键盘扫描
{    
  static uchar erect_measure_count=0;        //垂直分辨率计数器
  switch(state)
     {
     case state1:
        if(!(key0&&key1&&key2&&key3))        //低电平时表示被按下   
          state=state2;  
        else      
          state=state1; 
         break;

     case state2:
        if(!key0)
          state=state3;
        else if(!key1)
          state=state3;
        else if(!key2)
          state=state3;
        else if(!key3)
          state=state3;
        else
           state=state1;
         break;

     case state3:
        if(key0)
          {
           measure_modify=0;
           delay4us();
           measure_modify=1;
           delay4us();
           state=state1;
           break;       
          }
        else if(key1)
          { 
           erect_measure_count++;        //通过变量的自加来达到模拟开关计数的目的
           if(erect_measure_count==4)    
              erect_measure_count=0;
            switch(erect_measure_count)
               {
                 case 0:
                   switch_modify0=0;
                   switch_modify1=0;
                   break;
                 case 1:
                   switch_modify0=0;
                   switch_modify1=1;
                   break;
                 case 2:
                   switch_modify0=1;
                   switch_modify1=0;
                   break;
                 case 3:
                   switch_modify0=1;
                   switch_modify1=1;
                   break;
               }
            state=state1;
           }
        else
            state=state3;

         break;
      }   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -