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

📄 main.c

📁 arm的键盘程序 基本的知识 包含ARM和Thumb指令
💻 C
字号:
//****************www.arm88.com*********************//

#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "stdlib.h" 
void __irq Key_Int(void);
volatile char which_int=0;
const char keyval[4][4]={
	 {'1','2','3','-'},
	 {'4','5','6','*'},
  	 {'7','8','9','/'}, 
     {'$','0','#','='}
};

//****************www.arm88.com*********************//

void Key_Init(void)
{
	rPDATC=0xfff0;	
    rPCONC=0x0f055555;	
    rPUPC=0x30f0;	
	rPCONG=0xffff;	
    rPUPG=0x0;		//pull up enable
	rINTCON=0x5;
	rINTMOD=0x0;    //All=IRQ mode
	rEXTINT=0x22222222; //Falling edge mode 
			
   
    pISR_EINT4567=(unsigned)Key_Int;
    rINTMSK=~(BIT_GLOBAL|BIT_EINT4567);	//start INT
}

//****************www.arm88.com*********************//

void __irq Key_Int(void)
{	
	char keyv,keytemp=0;
	char nn=4;
	 switch(rEXTINTPND)
     {
       case 1:
       		which_int=0;
       		break;
       case 2:
      		which_int=1;
       		break;
	   case 4:
       		which_int=2;
      		break;
       case 8:
      		which_int=3;
      		break;
	   default :
	   		which_int=4;
        	break;
	}
    rINTMSK = ~(BIT_GLOBAL);     
     rPCONG = 0x5555;	
     rPDATG &= 0x0f ; 
     rPUPC  = 0x30f0;	
     rPDATC |= 0x0f ; 
     rPCONC = 0x0f055000;
      keytemp= rPDATC&0x0f;
   //   Uart_Printf("\nEINT had been occured  %d  %d",rEXTINTPND, keytemp);
    
     switch(keytemp)
     {
       case 7:
       		nn=3;
       		break;
       case 11:
      		nn=2;
       		break;
	   case 13:
       		nn=1;
      		break;
       case 14:
      		nn=0;
      		break;
	   default :
	        nn=4;
        	break;
	}

    if((nn<4)&&(which_int<4))
    {
     keyv=keyval[which_int][nn];
   	
     Uart_Printf("\n-----你按下了 '%c' 键!-----",keyv);
     }				       
    which_int=4;
    Delay(3500);   
    rPDATC=0xfff0;	
    rPCONC=0x0f055555;	    
	rPCONG=0xffff;	
    rPUPG=0x0;		
    rEXTINTPND=0xf;			
    rI_ISPC=BIT_EINT4567;	
    rINTMSK=~(BIT_GLOBAL|BIT_EINT4567);
}

//****************www.arm88.com*********************//

void Main(void)
{
    rSYSCFG=CACHECFG;   
    Port_Init();
    Uart_Init(0,57600);
    Delay(10);
    Uart_Select(0);
    Uart_Printf("\n按键中断演示程序");
    Uart_Printf("\n请按开发板上的按键 !\n");
    
    Key_Init();
    while(1);
    
}
//****************www.arm88.com*********************//

⌨️ 快捷键说明

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