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

📄 inv_keydisplay.c

📁 SVPWM算法的DSP源码已通过硬件验证
💻 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 + -