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

📄 menu.c

📁 dspic开发控制程序,有助开发pic单片机程序
💻 C
字号:
#include <p30f6014.h>
#include <spi.h>
#include <dsp.h>
#include "common.h"
#include "timers.h"
#include "lcd.h"
#include "atod.h"
#include "generators.h"
#include "codec.h"
#include "procdsp.h"
#include "menu.h"

#define M1ITEM1 0
#define M1ITEM2 1
#define M1ITEM3 2
#define M1ITEM4 3

char InputSrc;
char DspProc;
char CurrentMenu;
int CurrentInScale;
//LCD显示的常数
static const char Splash1[] = "DSPic Demo Program";
static const char Splash2[] = "By xxxxxx";
static const char Splash3[] = "Written On";
static const char Splash4[] = "Sept 05, 2004";

static const char MENU1TITLE[] = "Input Source";
static const char MENU2TITLE[] = "DSP Processing";
static const char MENU3TITLE[] = "CODEC Adjust";

static const char MENU1ITEMS[4][11] = {	"Codec     ",
									 	"Sine      ",
										"Noise     ",
										"Sine+Noise"};

static const char MENU2ITEMS[7][7] = {	"None  ",
									 	"LP FIR",
										"HP FIR",
										"BP FIR",
										"BS FIR",
										"FShift",
										"LMS   "};

static const char FREQDISP[] = "Frequency = ";
static const char INSCALEDISP[] = "In Scale = ";
static const char VOLUMEDISP[] = "Out Volume = ";
static const char SHIFTPDISP[] = "Shift = +";
static const char SHIFTMDISP[] = "Shift = -";

static unsigned int CurrentPot1;
static unsigned int CurrentPot2;
static unsigned int CurrentPot3;

static unsigned int CurrentSineFreq;
static unsigned int CurrentOutVolume;
static unsigned char LEDcounter;
//函数原型
void InitMenu(void);
void ServiceMenu(void);

static void MenuScroll(void);
static void ItemScroll(void);

//初始化菜单系统子程序
void InitMenu(void)
{
unsigned int tmp;
	SetLcdPos(1,0);
	WriteCStr(Splash1);
	SetLcdPos(5,1);
	WriteCStr(Splash2);
	TimeDelay(2);
	SetLcdPos(1,2);
	WriteCStr(Splash3);
	SetLcdPos(3,3);
	WriteCStr(Splash4);
	TimeDelay(50);
	ClearLcd();	
	CurrentMenu = (unsigned char)ReadEEData( EE_MENU);//读EEPROM中的数值
	CurrentMenu--;
	if(CurrentMenu > MENU_FREQ)
		CurrentMenu = MENU_FREQ;
	if(CurrentMenu < MENU_INPUT)
		CurrentMenu = MENU_FREQ;
	InputSrc = (char)ReadEEData( EE_INPUT);
	if(InputSrc>SRC_SINENOISE)
		InputSrc = SRC_SINENOISE;
	if(InputSrc<SRC_CODEC)
		InputSrc = SRC_CODEC;
	DspProc = DSP_NONE;
	DspProc = (char)ReadEEData( EE_DSP);
	if(DspProc>DSP_LMS)
		DspProc = DSP_LMS;
	if(DspProc<DSP_NONE)
		DspProc = DSP_NONE;
	CurrentPot1 = 0;
	CurrentPot2 = 0;
	CurrentPot3 = 0;
	CurrentInScale = 0;
	LEDcounter = 0;
	KeyNum = KEY1;
	Sem.KeySwitch = TRUE;	//假定有键按下使菜单初始到 menu1
	InitProcDSP(DspProc);
}



//菜单操作子程序
void ServiceMenu( )
{
int tmp;
	if(Sem.KeySwitch && !Sem.PlotActive)	//如果有键按下且没有画图
	{
		Sem.KeySwitch = FALSE;
		switch(KeyNum)
		{
			case KEY1:		//主菜单翻转按键
				MenuScroll();
				break;
			case KEY2:		//子菜单翻转按键
				ItemScroll();
				break;
			case KEY3:
				LMSmu -= 1;
				if(LMSmu>0xFFF)
					LMSmu = 0;	
				SetLcdPos(3,3);
				Write4Hex(LMSmu);
				break;
			case KEY4:
				LMSmu += 1;
				if(LMSmu>100)
					LMSmu = 100;	
				SetLcdPos(3,3);
				Write4Hex(LMSmu);
				break;
		}
	}
	if(Sem.Timer1)	//每100mSec刷新一次值
	{
		Sem.Timer1 = 0;
		LEDcounter++;
		if(LEDcounter&BIT3)		
			LED4_ON
		else
			LED4_OFF
		tmp = GetADValue(POT1)&0xFFFC; //取RB1对应的通道的值
		if(	CurrentPot1 != tmp )
		{
			CurrentPot1 = tmp;
			CurrentInScale = tmp<<3;
			if(CurrentMenu == MENU_INPUT)
			{
				SetLcdPos(3,3);
				WriteCStr(INSCALEDISP);
				WriteDec(CurrentInScale);
			}
		}
		CurrentSineFreq = GetADValue(POT2);//取RB2对应通道的值
		if(	CurrentPot2 != CurrentSineFreq )
		{
			CurrentPot2 = CurrentSineFreq;
			if(CurrentSineFreq>3500)
				CurrentSineFreq = 3500;
			if( DspProc==DSP_SHIFT)
			{
				tmp = CurrentSineFreq-1750;
				SetShiftFreq(tmp);
				if( (CurrentMenu == MENU_INPUT) ||
					(CurrentMenu == MENU_DSP) )
				{
					ClearLcdLine(2);
					SetLcdPos(2,2);
					if(tmp>0)
					{
						WriteCStr(SHIFTPDISP);
					}
					else
					{
						WriteCStr(SHIFTMDISP);
						tmp = -tmp;
					}
					WriteDec(tmp);
				}
			}
			else
			{
				SetSineFreq(CurrentSineFreq);
				if( (CurrentMenu == MENU_INPUT) &&
					( (InputSrc==SRC_SINE) ||
					(InputSrc==SRC_SINENOISE) ) )
				{
					ClearLcdLine(2);
					SetLcdPos(2,2);
					WriteCStr(FREQDISP);
					WriteDec(CurrentSineFreq);
				}
			}
		}
		tmp = GetADValue(POT3)>>5;//取RB3对应通道的值
		if(	CurrentPot3 != tmp )
		{
			CurrentPot3 = tmp;
			if(CurrentMenu== MENU_CODEC)
			{
				SetLcdPos(0,3);
				WriteCStr(VOLUMEDISP);
				Write2Hex((unsigned char)tmp);
			}
			//把新的音量数值设定发送到编码解码器
			WriteCodecCtrl( CODEC_DACVOL, tmp|CODEC_PARM_SLM|CODEC_PARM_SRM );
			WriteCodecCtrl( CODEC_ADCVOL, tmp|CODEC_PARM_LOM ); 
		}
	}
}

//菜单翻转子程序
static void MenuScroll(void)
{
	CurrentMenu++;
	if(CurrentMenu > MENU_FREQ)
		CurrentMenu = MENU_INPUT;
	ClearLcd();
	switch(CurrentMenu)
	{
		case MENU_INPUT:		//Input Source Menu
			SetLcdPos(4,0);
			WriteCStr(MENU1TITLE);
			SetLcdPos(0,1);
			WriteCStr(MENU1ITEMS[InputSrc]);
			if( (InputSrc==SRC_SINE)
				|| (InputSrc==SRC_SINENOISE) )
			{
				SetLcdPos(2,2);
				WriteCStr(FREQDISP);
				WriteDec(CurrentSineFreq);
			}
			SetLcdPos(3,3);
			WriteCStr(INSCALEDISP);
			WriteDec(CurrentInScale);
			break;
		case MENU_DSP:		//DSP Processing Selection Menu
			SetLcdPos(2,0);
			WriteCStr(MENU2TITLE);
			SetLcdPos(0,1);
			WriteCStr(MENU2ITEMS[DspProc]);
			break;
		case MENU_CODEC:		//CODEC volume menu
			SetLcdPos(2,0);
			WriteCStr(MENU3TITLE);
			SetLcdPos(0,3);
			WriteCStr(VOLUMEDISP);
			Write2Hex((unsigned char)CurrentPot3);
			break;
		case MENU_TIME:		//Time plot
		case MENU_FREQ:		//Frequency plot
			break;
	}
	WriteEEData( EE_MENU , (int)CurrentMenu);
}

//子菜单翻转子程序
static void ItemScroll(void)
{
	switch(CurrentMenu)
	{
		case MENU_INPUT:		//输入源子菜单翻转
			InputSrc++;
			if(InputSrc>SRC_SINENOISE)
				InputSrc = SRC_CODEC;
			WriteEEData( EE_INPUT , (int)InputSrc);
			SetLcdPos(0,1);
			WriteCStr(MENU1ITEMS[InputSrc]);
			if( (InputSrc==SRC_CODEC)
				|| (InputSrc==SRC_NOISE) )
			{
				ClearLcdLine(2);
			}
			break;
		case MENU_DSP:	 //DSP处理子菜单翻转
			DspProc++;
			if(DspProc>DSP_LMS)
				DspProc = DSP_NONE;
			WriteEEData( EE_DSP , (int)DspProc);
			InitProcDSP(DspProc);
			ClearLcdLine(2);
			SetLcdPos(0,1);
			WriteCStr(MENU2ITEMS[DspProc]);
			if( DspProc==DSP_SHIFT )
			{
				SetSineFreq(1750);
				SetShiftFreq( CurrentSineFreq-1750);
			}
			else
			{
				SetSineFreq(CurrentSineFreq);
			}
			break;
		case MENU_CODEC:
		case MENU_TIME:
		case MENU_FREQ:
			break;
	}
}

⌨️ 快捷键说明

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