key.c

来自「包括DSP实验测试程序、实验示例、应用程序以及经典的DSP的C程序和汇编程序库」· C语言 代码 · 共 92 行

C
92
字号
#include	"cpu_reg.h"
extern	int	f,ms;

Uint16	ScanKey(void)
		{
			Uint16	temp,temp1;
			Uint16  flag = 0;
			while(flag==0)
				{
					temp = KeyReg;
					temp = temp & 0xff;
					while(temp==0xff)
						{
							temp = KeyReg;			
							temp = temp & 0xff;
		       			 }
		    		delay(5000);
					temp = KeyReg;			
					temp = temp & 0xff;
					temp1 = temp;
					if (temp == 0xff) flag = 0;
					else  flag = 1;		    
		        }
			temp = KeyReg;
			temp = temp & 0xff;
		    while( temp != 0xff)
		    	{
					temp = KeyReg;
					temp = temp & 0xff;
		    	}
		    return(temp1);		    			
		}


void	delay(Uint32  num)
		{
			volatile  Uint32  i;
			for (i=0;i<num;i++) { ; }				
		}	

void	KeyFunction(Uint16	Temp)
		{
			switch(Temp)
				{
					case  K1: {
								KeyPress();
							  }
							  break;
					case  K2: {
								KeyPress();
							  }
							  break;
					case  K3: {
								KeyPress();
							  }
							  break;
					case  K4: {
								KeyPress();
							  }
							  break;
					case  K5: {
								KeyPress();
							  }
							  break;
					case  K6: {
								KeyPress();	
							  }
							  break;
					case  K7: {
								KeyPress();
							  }
							  break;
					case  K8: {
								KeyPress();	
							  }
					default:  
							  break;
			}				  				  			  				   			  			  			   		
		}

void	KeyPress(void)
		{
		    ms=0;	
       		while(ms<500/f);     //LED_flash
       		ms=0;
       		asm("  RSBX  XF ");       
       		while(ms<500/f);
       		ms=0;
       		asm("  SSBX  XF ");       
		}

⌨️ 快捷键说明

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