?? inv_keydisplay.c
字號:
//
// Copyright (c) 2007, 北京動力源科技股份有限公司
// All rights reserved.
//
// 項目名稱:
// 文件名稱: INV_KeyDisplay.c
//
// 版 本: Ver 1.00
//
// 完成日期: 2010年10月
// 作 者: Liu yaqiong
//
// 修訂日期:
// 修 訂 者:
//
// 編輯工具:UEStudio(TAB should be set to 4)
//
// 編譯工具:Code Composer Studio V3.3
//
#include "Drv_dsp280x_GPIO.h"
#include "DSP280x_Device.h"
#include "DSP280x_Examples.h"
#include "Global.h"
#define RUN_KEY 1
#define STOP_KEY 2
#define MODE_KEY 3
#define SAVE_READ_KEY 4
#define ADD_KEY 5
#define SUB_KEY 6
#define STANDBY 0 // 待機狀態
#define FUNC_CODE 1 // 功能碼狀態
#define FUNC_CONTENT 2 // 功能碼內容狀態
#define DIS_FREQ 3 //運行狀態下默認顯示頻率
#define DIS_VOLT 4 // 運行狀態下按存儲讀出鍵顯示電壓
#define DIS_CURR 5 //運行狀態下按存儲讀出鍵顯示電流
#define OK_1S 1
extern void spi_xmit(Uint16 a);
// 0 1 2 3 4 5 6 7 8 9
const Uint16 uiCodeTab[10] = {0X5F,0X06,0X3B,0X2F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
const Uint16 uiCodeHTab[31] = {1,5200,5000,380,130,1,16,100,1,100,1,3,30,300,10,500,50,1,150,80,
9,100,100,100,100,1,1,2,200,0,0};
const Uint16 uiCodeLTab[31] = {0,5000,4800,220,50,0,6,0,0,0,0,0,0,0,0,1,0,0,100,50,1,0,0,0,0,0,0,0,0,0,0};
//---------------------------------------------------
// Name:
// Function: 顯示4位數到數碼管上
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
void vDisplay(Uint32 x)
{
Uint16 uiThousandCode; // 千位編碼值
Uint16 uiHundredCode; // 百位編碼值
Uint16 uiTenbitCode; // 十位編碼值
Uint16 uiIndivbitCode; // 個位編碼值
Uint16 uiThousand = 0;
Uint16 uiHundred = 0;
Uint16 uiTenbit = 0;
Uint16 uiIndivbit = 0;
uiThousand = x / 1000;
uiHundred = (x - uiThousand * 1000) / 100;
uiTenbit = (x - uiHundred * 100 - uiThousand * 1000) / 10;
uiIndivbit = x - uiHundred * 100 - uiTenbit * 10 - uiThousand * 1000;
if(uiThousand == 0)
{
uiThousandCode = 0x00;
if(uiHundred == 0)
{
uiHundredCode = 0x00;
if(uiTenbit == 0)
{
uiTenbitCode = 0x00;
}
else
{
uiTenbitCode = uiCodeTab[uiTenbit];
}
}
else
{
uiHundredCode = uiCodeTab[uiHundred];
uiTenbitCode = uiCodeTab[uiTenbit];
}// 十位數對應的編碼值
}
else
{
uiThousandCode = uiCodeTab[uiThousand]; // 千位數對應的編碼值
uiTenbitCode = uiCodeTab[uiTenbit]; // 十位數對應的編碼值
uiHundredCode = uiCodeTab[uiHundred] | (0x80); // 百位數對應的編碼值
}
uiIndivbitCode = uiCodeTab[uiIndivbit]; // 個位數對應的編碼值
// 發送百位十位個位到數碼管上
spi_xmit((uiIndivbitCode << 8) + uiTenbitCode);
spi_xmit((uiHundredCode << 8) + uiThousandCode);
}
//---------------------------------------------------
// Name:
// Function: 顯示4位功能碼到數碼管上
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
void vDispalyCode(Uint16 y)
{
Uint16 uiTenbitCode; //十位編碼值
Uint16 uiIndivbitCode; //個位編碼值
Uint16 uiTenbit = 0;
Uint16 uiIndivbit = 0;
uiTenbit = y / 10;
uiIndivbit = y - uiTenbit * 10;
uiTenbitCode = uiCodeTab[uiTenbit];
uiIndivbitCode = uiCodeTab[uiIndivbit];
if(uiTenbit != 0)
{
spi_xmit((uiIndivbitCode << 8) + uiTenbitCode);
spi_xmit(0x2071);
}
else
{
spi_xmit((uiIndivbitCode << 8) + 0x20);
spi_xmit(0x2071);
}
}
//---------------------------------------------------
// Name:
// Function: 顯示
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
void vDisplayFVI(Uint16 x)
{
static Uint16 uiFVItemp = 0;
Uint16 uiThousandCode; // 千位編碼值
Uint16 uiHundredCode; // 百位編碼值
Uint16 uiTenbitCode; // 十位編碼值
Uint16 uiIndivbitCode; // 個位編碼值
Uint16 uiThousand = 0;
Uint16 uiHundred = 0;
Uint16 uiTenbit = 0;
Uint16 uiIndivbit = 0;
if (uiFVItemp != x)
{
uiThousand = x / 1000;
uiHundred = (x - uiThousand * 1000) / 100;
uiTenbit = (x - uiHundred * 100 - uiThousand * 1000) / 10;
uiIndivbit = x - uiHundred * 100 - uiTenbit * 10 - uiThousand * 1000;
if(uiThousand == 0)
{
uiThousandCode = 0x00;
if(uiHundred == 0)
{
uiHundredCode = 0x00;
if(uiTenbit == 0)
{
uiTenbitCode = 0x00;
}
else
{
uiTenbitCode = uiCodeTab[uiTenbit];
}
}
else
{
uiHundredCode = uiCodeTab[uiHundred];
uiTenbitCode = uiCodeTab[uiTenbit];
}// 十位數對應的編碼值
}
else
{
uiThousandCode = uiCodeTab[uiThousand]; // 千位數對應的編碼值
uiTenbitCode = uiCodeTab[uiTenbit]; // 十位數對應的編碼值
uiHundredCode = uiCodeTab[uiHundred] | (0x80); // 百位數對應的編碼值
}
uiIndivbitCode = uiCodeTab[uiIndivbit]; // 個位數對應的編碼值
// 發送百位十位個位到數碼管上
spi_xmit((uiIndivbitCode << 8) + uiTenbitCode);
spi_xmit((uiHundredCode << 8) + uiThousandCode);
uiFVItemp = x;
}
}
//---------------------------------------------------
// Name:
// Function: 顯示
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
//---------------------------------------------------
// Name:
// Function: 采樣值濾波后,再判斷鍵值大小
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
Uint16 uiSampleKey()
{
if(uiKeyOk == 1)
{
uiKeyOk = 0;
if((uiSampleTrue > 1500) && (uiSampleTrue < 1800)) // 當采樣值大于1300小于1600, 表示按鍵4按下
{
uiTest = STOP_KEY;
}
else if((uiSampleTrue > 2300) && (uiSampleTrue < 2600))
{
uiTest = RUN_KEY;
}
else
{
uiTest = STANDBY;
}
}
return (uiTest);
}
//---------------------------------------------------
// Name:
// Function: 濾波防抖后的按鍵值大小確定
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
Uint16 uiTrueKey()
{
static Uint16 uiTemp; // 濾波后的鍵值臨時變量
static Uint16 uiTempCnt; // 計數器
Uint16 uiKeyTrue = 0;
Uint16 uiTemp1;
uiTemp1 = uiSampleKey();
if (uiTemp == uiTemp1)
{
uiTempCnt++;
}
else
{
uiTempCnt = 0;
uiTemp = uiTemp1;
}
if((uiTemp > 0) && (uiTempCnt > 15)) // 如果兩次鍵值相等,則返回鍵值,否則返回0。
{
uiKeyTrue = uiTemp;
}
else
{
uiKeyTrue = 0;
}
return (uiKeyTrue);
}
//---------------------------------------------------
// Name:
// Function: 顯示功能碼
// Input:
// Output:
// Called by:
// Call: void vDispalyCode(Uint16 y)
//---------------------------------------------------
//---------------------------------------------------
// Name:
// Function: 顯示功能碼內容,并且限定在上線限范圍之內
// Input:
// Output:
// Called by:
// Call: void vDispalyCode(Uint16 y)
//---------------------------------------------------
//---------------------------------------------------
// Name:
// Function: 待機以50.00閃爍,每1S閃爍一次
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
void vBlink()
{
static Uint16 uiBlinkTmp1;
static Uint16 uiBlinkTmp2;
if (uiCnt1S == 1)
{
if (uiBlinkTmp1 == 0x5f5f)
{
uiBlinkTmp1 = 0;
uiBlinkTmp2 = 0;
}
else
{
uiBlinkTmp1 = 0X5F5F; //00的編碼值
uiBlinkTmp2 = 0XDF6D; //50.的編碼值
}
spi_xmit(uiBlinkTmp1);
spi_xmit(uiBlinkTmp2);
uiCnt1S = 0;
}
}
//---------------------------------------------------
// Name:
// Function:
// Input:
// Output:
// Called by:
// Call:
//---------------------------------------------------
void vKeyProcess()
{
if (uiTime1ms== 1) //1ms
{
uiTime1ms = 0;
uiKeyTrueValue = uiTrueKey();
if(uiKeyTrueValue == 0)
{
uiFlag = 1; //標志鍵值為0
if (uiPage == STANDBY)
{
vBlink();
}
else if (uiPage == DIS_FREQ)
{
// vDisplayFVI(6666);
//vDisplayFVI(uiRmsNBAvg);
// vDisplayFVI(OutputVar.uiCurrFreq);
//vDisplayFVI(OutputVar.uiTargetFreq);
vDisplayFVI(uiRmsNBU);
}
}
else if((uiPage == STANDBY) && (uiKeyTrueValue == RUN_KEY))
{
RunState.uiRun = RUN;
uiFlag = 0;
uiPage = DIS_FREQ;
}
else if(uiKeyTrueValue == STOP_KEY)
{
RunState.uiRun = STOP;
uiFlag = 0;
uiPage = STANDBY;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -