|
#include
#include
#include "Key_Board.h"
#include "Nokia5110.h"
#include "SystemInit.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
#include "inc/hw_timer.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
unsigned char num; //ÓÃÀ´ÏÔʾ×Ö·û¼ÆÊý
unsigned char Int_flag=1; //Öжϱê־λ
unsigned char num2=0; //¸ºÔð¶ÔÊäÈëµÄ¼ÆÊý
unsigned char key_val=88; //ÊäÈëµÄÖµ³õʼÉèÖÃ
unsigned char in_put_end_flag=0;//ÊäÈë½áÊø±êÖ¾
unsigned char keyinput_val[]="A321B654C987DE0F";
unsigned char input[32];//ÊäÈëµÄÒªÏÔʾµÄÊý×é
/*********************************************************************************************************
** Function name: GPIO_Port_F_ISR
** Descriptions: GPIOFµÄÖжϷþÎñº¯Êý
** input parameters: ÎÞ
** output parameters: ÎÞ
** Returned value: ÎÞ
*********************************************************************************************************/
void GPIO_Port_F_ISR(void)
{
unsigned long ulStatus;
unsigned char K_In;
K_In=0x80;
SysCtlDelay(5*(TheSysClock/ 3000)); //Ïû¶¶
ulStatus=GPIOIntStatus(KEY_PORTF,true); // ¶ÁÈ¡ÖжÏ״̬
GPIOIntClear(KEY_PORTF, ulStatus); // Çå³ýÖжÏ״̬£¬ÖØÒª
if (ulStatus&KEY_PIN_L) //Èç¹ûKEY_LµÄÖжÏ״̬ÓÐЧ
{
SysCtlDelay(5*(TheSysClock/ 3000)); // ÑÓʱԼ10ms£¬Ïû³ýËɼü¶¶¶¯
key_val=KeyIn(K_In); //¶ÁÈ¡°´¼üÖµ
KeyChecKend();//¼ì²é°´¼ü½áÊø
}
Int_flag=0;
Nokia5110_DisNumber(0,5,key_val);
}
void Key_IntInit(void)
{
/*¸ß4λKEY_PIN_HÅäÖÃ*/
{
/*KEY_PIN_HʹÄÜ*/
SysCtlPeripheralEnable(KEY_PERIPH_GPIOC); //¸ß4λʹÄÜ
/*¸ß4λKEY_PIN_Hģʽ*/
// GPIOPinTypeGPIOOutput(KEY_PORTC,KEY_PIN_H);//¸ß4ΪÊä³ö
// GPIOPinWrite(KEY_PORTC,KEY_PIN_H,0x00); //¸ß4λÊä³ö0
GPIODirModeSet(KEY_PORTC, KEY_PIN_H, GPIO_DIR_MODE_OUT);
GPIOPadConfigSet(KEY_PORTC, KEY_PIN_H,
GPIO_STRENGTH_4MA,
GPIO_PIN_TYPE_STD);
GPIOPinWrite(KEY_PORTC,KEY_PIN_H,0x00); //¸ß4λÊä³ö0
}
/*µÍ4λÖжÏÊäÈëÉèÖÃ*/
{
/*ʹÄÜKEY_PIN_LËùÔÚGPIO¶Ë¿Ú*/
SysCtlPeripheralEnable(KEY_PERIPH_GPIOF); //µÍ4λʹÄÜ
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0x4c4f434b; //½âËøPF0
HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = GPIO_PIN_0;
/*ÉèÖÃKEY_PIN_LËùÔÚGPIO¶Ë¿ÚÊäÈëģʽ*/
//GPIOPinTypeGPIOInput(KEY_PORTF,KEY_PIN_L);//µÍ4λÊäÈë
GPIOPadConfigSet(GPIO_PORTF_BASE,KEY_PIN_L,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
GPIODirModeSet(GPIO_PORTF_BASE,KEY_PIN_L, GPIO_DIR_MODE_IN);
/*ÉèÖÃKEY_PIN_LÖжÏÀàÐÍ*/
GPIOIntTypeSet(KEY_PORTF,KEY_PIN_L,GPIO_FALLING_EDGE);//µÍ4λϽµÑØ´¥·¢ÖжÏ
//IntPrioritySet(INT_GPIOF, 1 << 5); // ÉèÖÃKEYÖжÏÓÅÏȼ¶Îª1
/*×¢²áÖжÏ*/
GPIOIntRegister(KEY_PORTF,GPIO_Port_F_ISR);
/*ÖжÏÅäÖÃ*/
GPIOIntEnable(KEY_PORTF,KEY_PIN_L);//µÍ4λÖжÏÊäÈëʹÄÜ
IntEnable(INT_GPIOF);
}
}
/*********************************************************************************************************
** Function name: Keycheckend
** Descriptions: ¼ì²é°´¼ü½áÊø
** input parameters: ÎÞ
** output parameters: ÎÞ
** Returned value: ÎÞ
*********************************************************************************************************/
void KeyChecKend(void)
{
SysCtlDelay(10 * (TheSysClock/ 3000)); // ÑÓʱԼ10ms£¬Ïû³ý°´¼ü¶¶¶¯
while (GPIOPinRead(KEY_PORTF,KEY_PIN_L) == 0x00); // µÈ´ýKEY̧Æð
SysCtlDelay(10*(TheSysClock/ 3000)); // ÑÓʱԼ10ms£¬Ïû³ýËɼü¶¶¶¯
}
/*********************************************************************************************************
** Function name: KeyIn
** Descriptions: °´¼üÖµ¼ì²âÄ£¿é
** input parameters: ÎÞ
** output parameters: ¼ì²âµ½µÄ¼üÅÌÊäÈëÖµ key_val
** Returned value: ÎÞ
*********************************************************************************************************/
unsigned char KeyIn(unsigned char K_In)
{
unsigned char keyH_out;
unsigned char temp1;
unsigned char row;
unsigned char col;
unsigned char pinStatus;
for(row=0;row<4;row++)
{
keyH_out=0xF0;
keyH_out-=K_In;
K_In>>=1;
GPIOPinWrite(KEY_PORTC, KEY_PIN_H,keyH_out);
pinStatus=GPIOPinRead(KEY_PORTF,KEY_PIN_L);
if((pinStatus&0x0f)<0x0f)
{
temp1=0x01;
for(col=0;col<4;col++)
{
if((pinStatus&temp1)==0x00)
{
key_val=col+row*4;
}
temp1<<=1;
}
}
}
GPIOPinWrite(KEY_PORTC, KEY_PIN_H,0x00);
return key_val;
}
//Ö÷º¯Êý£¨³ÌÐòÈë¿Ú£©
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4 |
SYSCTL_USE_PLL |
SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);//ÅäÖÃΪPLL 4·ÖƵ£¬Íⲿ16Mhz¾§Õñ£¬ÔòϵͳʱÖÓΪ200Mhz/4=50Mhz
Nokia5110_Init(); //Òº¾§³õʼ»¯
Key_IntInit(); // KEYÖжϳõʼ»¯
IntMasterEnable(); // ʹÄÜ´¦ÀíÆ÷ÖжÏ
while(1)
{
Nokia5110_DisNumber(0,0,key_val);
Nokia5110_DisNumber(0,1,1);
}
// while(1) // µÈ´ý°´¼üÖжÏ
// {
// Nokia5110_DisNumber(0,5,key_val+1);
// if(Int_flag==0)
// {
// Nokia5110_DisNumber(0,3,Int_flag);
// Nokia5110_DisNumber(0,2,Int_flag);
// if(key_val<15&&(key_val>0|| key_val==0))
// {
// Nokia5110_DisNumber(0,0,key_val);
// input[num2]=keyinput_val[key_val];
// }
// Int_flag=1;
// num2++;
// if(key_val==0x0F)
// {
// num2=0;
// Nokia5110_Dis6x8(0,0,input);
// }
// }
// }
}
上面程序为什么出不了中断函数,进入中断后就出不来l!
|
|