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

📄 keyboard.c

📁 基于HMS7202的波形发生器源程序
💻 C
字号:
#include "reg7202.h"
#include "hms7202lib.h"

static unsigned char  key_CodeRead(void);

volatile unsigned char *MyKBCr  =(volatile unsigned char*)KBCr;
volatile unsigned  *MyKBVr0   =  (volatile unsigned *)KBVr0;
volatile unsigned  *MyKBVr1   =  (volatile unsigned *)KBVr1;
volatile unsigned char *MyKBSr = (volatile unsigned char*)KBSr;

/* code value read from keyboard interface */
unsigned KeyBuff0; 
unsigned KeyBuff1;

unsigned NewKeyBuff0;
unsigned NewKeyBuff1;
char key_buf[8];


unsigned char Get_Key()
{
	unsigned char Key;
	while(1)
	{
		
		if((KeyBuff0=*MyKBVr0)==0)
		{
		 if((KeyBuff1=*MyKBVr1)==0)
		 continue;
		}

		
		delay(1000);
		
		NewKeyBuff0 = *MyKBVr0;
		NewKeyBuff1 = *MyKBVr1;
		if(NewKeyBuff0==KeyBuff0 && NewKeyBuff1==KeyBuff1)
		{
		Key = key_CodeRead();
		return  Key;
		}
		
	}
}


unsigned char key_map[8][8][10]= {  
               {"Recall","Store","Arb  ","Squa  ","Sin  ","ArbMnu","Remote","Utillty"},
               {"     ","     ","     ","     ","     ","     ","     ","     "},
               {"     ","     ","     ","     ","Tria ","Pulse","zaosh","DC   "},
               {"Up   ","Down ","Left ","Right","8    ","9    ",".    ","+/-  "},
               {"7    ","6    ","5    ","4    ","0    ","1    ","2    ","3    "},
               {"     ","     ","     ","     ","     ","     ","     ","     "},
               {"     ","     ","     ","     ","     ","     ","     ","     "},
               {"     ","     ","     ","     ","     ","     ","     ","     "},
                        };//键名


//		Matrix俊 KeyIn蔼捞 乐绰 瘤  check窍扁 困茄 巴烙.
//unsigned char KeyMask[8] = { 0x7f,0x03,0x3f, 0x75,0x77,0x7f,0x7f,0x7f};//那根线扫描有效
unsigned char KeyMask[8] = { 0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff};


/*unsigned char ScanTable[8][8] = 
                {
                        0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
                        0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
                        0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
                        0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
                        0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,
                        0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,
                        0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,
                        0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,
                };//键值*/
unsigned char ScanTable[8][8] = 
                {
                        0x25,0x24,0x23,0x22,0x1e,0x1f,0x20,0x21,
                        0xff,0xff,0x14,0x15,0x1d,0x18,0x17,0x16,
                        0x1c,0x1b,0x1a,0x19,0x26,0x27,0x28,0x29,
                        0x0f,0x10,0x11,0x12,0x08,0x09,0x0a,0x0b,
                        0x07,0x06,0x05,0x04,0x00,0x01,0x02,0x03,
                        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
                        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
                        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
                };//键值

unsigned char AsciiTable[8][8] =
                {
                        0x1b,0x53,0x71,0x00,0x73,0x63,0x33,0x00,
                        0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
                        0x60,0x5c,0x09,0x7a,0x61,0x78,0x00,0x00,
                        0x31,0x00,0x77,0x00,0x64,0x76,0x34,0x00,
                        0x32,0x74,0x65,0x00,0x66,0x62,0x35,0x00,
                        0x39,0x79,0x72,0x6b,0x67,0x6e,0x36,0x00,
                        0x30,0x75,0x6f,0x6c,0x68,0x6d,0x37,0x00,
                        0x2d,0x69,0xff,0xff,0xff,0xff,0xff,0x00,
                };



static unsigned char  key_CodeRead(void)
{

    unsigned char tempcol;
    unsigned char i,k;
    int  key_code=0;
    key_buf[7]  = (unsigned char)((KeyBuff0 >>  24) & 0xff);//第1列
	key_buf[6]  = (unsigned char)((KeyBuff0 >> 16) & 0xff);
	key_buf[5]  = (unsigned char)((KeyBuff0 >> 8) & 0xff);
   	key_buf[4]  = (unsigned char)(KeyBuff0 & 0xff);
	key_buf[3]  = (unsigned char)((KeyBuff1 >>  24) & 0xff);
	key_buf[2]  = (unsigned char)((KeyBuff1 >> 16) & 0xff);
	key_buf[1]  = (unsigned char)((KeyBuff1 >> 8) & 0xff);//第7列
	key_buf[0]  = (unsigned char)(KeyBuff1 & 0xff);//第8列

    //Key_Press = 0;    
    for(i = 0; i < 8; i++)
    {
        if ( key_buf[i] & KeyMask[i])        // Row喊  角力 硅沥等 虐俊 措秦
                                                //  涝仿 咯何 炼荤  
        {
            tempcol = 0x01;                    // 1俺狼 key 牢 版快档 器窃. 
                for(k = 0; k < 8; k++)
                {
                    if (key_buf[i] & tempcol)
                    {
                     // ser_printf("  scancode %x  asciicode %x char %s \n\n",ScanTable[i][k], AsciiTable[i][k],key_map[i][k]);
                      key_code=ScanTable[i][k];
                      return key_code;
                    }
                    tempcol <<= 1;
               }
        }
   }
   
   

}


unsigned int readfreq(void)
 {
	char newkey,oldkey[10];
	int i=0,num=0;
	unsigned int freq=0;
	while((newkey=Get_Key()) != 20 && newkey!=21 && newkey!=22)
	{
		if(newkey==17) //退格
		{
			i--;
			num--;
			if(i<0)
			{
			  i=0;
			  num=0;
			  continue;
			}   
			ser_printf("\b \b");
		}
/*		else if(newch=='l')//左移
		{
			i--;
			if(i<0)
			{
				i=0;
				continue;
			}
			ser_printf("\b");
		}
		else if(newch=='r')//右移
		{
			i++;
			if(i>num)
			{
				i=num;
				continue;
			}
			ser_putchar(oldch[i]);
		} */
    	else if(newkey == 23)//按了取消键
    	{
    	    
    	    return (0);
    	}
		else if(newkey<10)//输入数字键
		{
			oldkey[i++] = newkey;
			num++;
			ser_printf("%d",newkey);
		}
		else
			continue;
		
	}
	for(i=0;i<num;i++)
	{
		freq = freq*10 + oldkey[i];
	}
	
	//判断单位
	switch(newkey)
	{
	case 20:
		ser_printf("Hz.\n");
		break;
	case 21:
		freq *= 1000;
		ser_printf("KHz.\n");
		break;
	case 22:
		freq *= 1000000;
		ser_printf("MHz.\n");
		break;
	}
	return freq;
 }
 
 unsigned int readamp(void)
 {
	char newkey,oldkey[10];
	int i=0,num=0;
	unsigned int ampl=0;
	while((newkey=Get_Key()) !=20 && newkey !=21 && newkey !=22)
	{
		if(newkey==17) //退格
		{
			i--;
			num--;
			if(i<0)
			{
			  i=0;
			  num=0;
			  continue;
			}   
			ser_printf("\b \b");
		}
		else if(newkey==23) //取消
		{
			return (0);
		}
		else if(newkey<10)
		{
			oldkey[i++] = newkey;
			num++;
			ser_printf("%d",newkey);
		}
		else
			 continue;
		
	}
	for(i=0;i<num;i++)
	{
		ampl = ampl*10 + oldkey[i];
	}
	switch(newkey)
	{
	case 20: 
		
		ser_printf("mVpp.\n");
		break;
	case 21:
		ampl *= 1000;
		ser_printf("Vpp.\n");
		break;
	case 22:
		ampl *= 2828;
		ser_printf("Vrms.\n");
		break;
	default :
		break;
	}
	return ampl;
 }
 
 unsigned char readratio()
 {
 	unsigned char ratio;
 	char newkey,oldkey[3];
 	int i=0,num;
 	while((newkey=Get_Key())!=20 && num<4)//最多接收三位数,以20键作结束键
 	{
 		if(newkey==17) //退格
		{
			i--;
			num--;
			if(i<0)
			{
			  i=0;
			  num=0;
			  continue;
			}   
			ser_printf("\b \b");
		}
 		else if(newkey == 23)//按了取消键
 		    return (0);
 		
 		else if(newkey<10)
 		{
 			oldkey[i++] = newkey;
			num++;
			ser_printf("%d",newkey);
 		}
 		else  //可添加其他判断
			continue;
 	}//while end
 	for(i=0;i<num;i++)
	{
		ratio = ratio*10 + oldkey[i];
	}
	//用来限制占空比范围
	if(ratio>100) ratio =100;
	return ratio;
 }

⌨️ 快捷键说明

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