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

📄 ledstatus.c

📁 制袋机程序.rar
💻 C
字号:
/***************************************
* 文件名:LEDSTATUS.c
* 描述:
* 最后修改时间:2010.4.7
****************************************/

#include "INCLUDES.H"

//LED的状态(共13个LED)
//LED1:led_status[0]
//LED2:led_status[1]
//LED3:led_status[2]
//LED4:led_status[3]
//LED5:led_status[4]
//LED6:led_status[5]
//LED7:led_status[6]
//LED8:led_status[7]
//LED9:led_status[8]
//LED10:led_status[9]
//LED11:led_status[10]
//LED12:led_status[11]
//LED13:led_status[12]
static uchar xdata led_status[13] = {0};
static bool xdata led_status_bChanged[13] = {false};
//static uchar xdata led_status_decode[13] = {0};

//LED13状态,0:灯亮 1:灯暗
//  [7]    [6]    [5]    [4]    [3]    [2]    [1]    [0]
//  L4/L5  L6/L7         L9     L3     L8     L2     L1
//  极选   色选         停止   测试    运行  手动    设定

//LED状态解码查询表
static uchar code tab_led_status[10] = {0xFA,0x90,0x73,0xD3,0x99,0xCB,0xEB,0xD0,0xFB,0xDB};


//====================================================================================
//函数名称:void LEDSTATUS_INIT()
//函数功能:底板电路状态读取初始化
//入口参数:无
//出口参数:无
//====================================================================================
void LEDSTATUS_INIT()
{
  INT1=1;//INT1输出高电平
  IE1=0;//中断标志位清零
  IT1=1;//下降沿触发
  EX1=1;//INT1打开
}

//====================================================================================
//函数名称:void LEDSTATUS_ISR() interrupt 2
//函数功能:底板电路状态读取中断函数
//入口参数:无
//出口参数:无
//====================================================================================
void LEDSTATUS_ISR() interrupt 2
{
    uchar addr = 0;
    uchar temp;
    EA = 0;//关中断
    //编码地址输出  A3    A2    A1    A0
    //对应引脚      p1.5  p1.4  p1.1  p1.0
    P1 |= 0x33;
    temp = P1;
    addr = ((temp & 0x30) >> 2) + (temp & 0x3);//CSn片选信号编码地址
    //LED1: addr = F
    //LED2: addr = E
    //LED3: addr = D
    //LED4: addr = C
    //LED5: addr = B
    //LED6: addr = 9
    //LED7: addr = 8
    //LED8: addr = 7
    //LED9: addr = 6
    //LED10: addr = 5
    //LED11: addr = 4
    //LED12: addr = 3
    //LED13: addr = A
    if(addr <= 9)
    {
      led_status[14 - addr] = LEDSTATUS_IN_ADDR;
      led_status_bChanged[14 - addr] = true;
    }
    else if(addr <= 10)
    {
      led_status[12] = LEDSTATUS_IN_ADDR;
      led_status_bChanged[12] = true;
    }
    else if(addr <= 15)
    {
      led_status[15 - addr] = LEDSTATUS_IN_ADDR;
      led_status_bChanged[15 - addr] = true;
    }
    else
    {
      //do nothing
    }
    EA = 1;//开中断
}

//====================================================================================
//函数名称:void Update_LEDSTATUS()
//函数功能:底板电路状态解码并更新到全局变量g_Status
//入口参数:无
//出口参数:无
//====================================================================================
void Update_LEDSTATUS()
{
  uchar i,j;
  uchar decode;

  //12个数码管状态的解码
  for(i = 0; i < 12; i++)
  {
    if(led_status_bChanged[i])
    {
      led_status_bChanged[i] = false;

      decode = 0xff;
      for(j = 0; j < 10; j++)
      {
        if((led_status[i]&0xfb) == tab_led_status[j])
        {
          decode = j;
          break;
        }
      }
      switch(i)
      {
        case 0:
        {
          //g_Status.LENGTH_4 = decode;
          //g_Status.bUpdated_LENGTH_4 = true;
          g_Status.ItemState[5] = decode;
          g_Status.bUpdated_ItemState[5] = true;
          break;
        }
        case 1:
        {
          //g_Status.LENGTH_3 = decode;
          //g_Status.bUpdated_LENGTH_3 = true;
          g_Status.ItemState[6] = decode;
          g_Status.bUpdated_ItemState[6] = true;
          break;
        }
        case 2:
        {
          //g_Status.LENGTH_2 = decode;
          //g_Status.bUpdated_LENGTH_2 = true;
          g_Status.ItemState[7] = decode;
          g_Status.bUpdated_ItemState[7] = true;
          break;
        }
        case 3:
        {
          //g_Status.LENGTH_1 = decode;
          //g_Status.bUpdated_LENGTH_1 = true;
          g_Status.ItemState[8] = decode;
          g_Status.bUpdated_ItemState[8] = true;
          break;
        }
        case 4:
        {
          //g_Status.SPEED = decode;
          //g_Status.bUpdated_SPEED = true;
          g_Status.ItemState[10] = decode;
          g_Status.bUpdated_ItemState[10] = true;
          break;
        }
        case 5:
        {
          //g_Status.GEPI_2 = decode;
          //g_Status.bUpdated_GEPI_2 = true;
          g_Status.ItemState[15] = decode;
          g_Status.bUpdated_ItemState[15] = true;
          break;
        }
        case 6:
        {
          //g_Status.GEPI_1 = decode;
          //g_Status.bUpdated_GEPI_1 = true;
          g_Status.ItemState[16] = decode;
          g_Status.bUpdated_ItemState[16] = true;
          break;
        }
        case 7:
        {
          //g_Status.COUNT_5 = decode;
          //g_Status.bUpdated_COUNT_5 = true;
          g_Status.ItemState[0] = decode;
          g_Status.bUpdated_ItemState[0] = true;
          break;
        }
        case 8:
        {
          //g_Status.COUNT_4 = decode;
          //g_Status.bUpdated_COUNT_4 = true;
          g_Status.ItemState[1] = decode;
          g_Status.bUpdated_ItemState[1] = true;
          break;
        }
        case 9:
        {
          //g_Status.COUNT_3 = decode;
          //g_Status.bUpdated_COUNT_3 = true;
          g_Status.ItemState[2] = decode;
          g_Status.bUpdated_ItemState[2] = true;
          break;
        }
        case 10:
        {
          //g_Status.COUNT_2 = decode;
          //g_Status.bUpdated_COUNT_2 = true;
          g_Status.ItemState[3] = decode;
          g_Status.bUpdated_ItemState[3] = true;
          break;
        }
        case 11:
        {
          //g_Status.COUNT_1 = decode;
          //g_Status.bUpdated_COUNT_1 = true;
          g_Status.ItemState[4] = decode;
          g_Status.bUpdated_ItemState[4] = true;
          break;
        }
        default:
        {
          break;
        }
      }
    }
  }//12个数码管状态的解码 End

  //LED灯的状态
  if(led_status_bChanged[12])
  {
    led_status_bChanged[12] = false;
    g_Status.LED_Status = led_status[12];
    g_Status.bUpdated_LED_Status = true;
  }//LED灯的状态 End

  //数码管编辑位置
  g_Status.LED_Modify_Position = 0xff;
  for(i = 0; i < 7; i++)
  {
    if((led_status[i] & 0x4) > 0)
    {
      g_Status.LED_Modify_Position = i + 1;
    }
  }//数码管编辑位置 End
}

void Update_LEDPosition()
{
	uchar i;
  //数码管编辑位置
  g_Status.LED_Modify_Position = 0xff;
  for(i = 0; i < 7; i++)
  {
    if((led_status[i] & 0x4) > 0)
    {
      g_Status.LED_Modify_Position = i + 1;
    }
  }//数码管编辑位置 End	
}

void Update_led_status()
{
	//LED灯的状态
  if(led_status_bChanged[12])
  {
    led_status_bChanged[12] = false;
    g_Status.LED_Status = led_status[12];
    g_Status.bUpdated_LED_Status = true;
  }//LED灯的状态 End
}

⌨️ 快捷键说明

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