This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
#include <stdbool.h>
#include <stdint.h>
#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
}
/*低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中断初始化
//GPIOIntClear(KEY_PORTF, KEY_PIN_L); // 清除中断状态,重要
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);
// }
// }
// }
}
上面的程序进入中断后,就在中断里面循环,出不来。不知到时怎么回事? 我看了一下硬件图发现WAKE引脚和按键硬件PF0连在一起,猜想是不是有影响
#include <stdbool.h> #include <stdint.h> #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 } /*��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�жϳ�ʼ�� //GPIOIntClear(KEY_PORTF, KEY_PIN_L); // ����ж�״̬����Ҫ 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); // } // } // } }