DSP

简简单单---一个TMS320F28035的按键驱动程序

2019-07-13 16:47发布

/************************************ 标题:key.h 软件平台:CCS v5.2 硬件平台:毕设控制板 主频:60M 欢迎光临 http://greatech.taobao.com author:小船 data:2013-02-23 *************************************/ #ifndef KEY_H_ #define KEY_H_ #include "PeripheralHeaderIncludes.h" #include #define delay_cheak 15000 #define KEY1 1 #define KEY2 2 #define KEY3 3 #define KEY4 4 #define noKEY 0 #define KEY1_on GpioDataRegs.GPADAT.bit.GPIO19 == 0 #define KEY2_on GpioDataRegs.GPADAT.bit.GPIO6 == 0 #define KEY3_on GpioDataRegs.GPADAT.bit.GPIO12 == 0 #define KEY4_on GpioDataRegs.GPADAT.bit.GPIO16 == 0 #define KEYs_on (GpioDataRegs.GPADAT.all & 0x00091040) != 0x00091040 extern void (*key1_handle)(); extern void (*key2_handle)(); extern void (*key3_handle)(); extern void (*key4_handle)(); void KEY_init(void (*key1_dle)(), void (*key2_dle)(), void (*key3_handle)(), void (*key4_dle)()); char KEY_scanf_handle(); #endif /* KEY_H_ */
/************************************ 标题:key.c 软件平台:CCS v5.2 硬件平台:毕设控制板 主频:60M 欢迎光临 http://greatech.taobao.com author:小船 data:2013-02-23 *************************************/ #include "key.h" void (*key1_handle) () = NULL; void (*key2_handle) () = NULL; void (*key3_handle) () = NULL; void (*key4_handle) () = NULL; void KEY_init(void (*key1_dle)(), void (*key2_dle)(), void (*key3_dle)(), void (*key4_dle)()) { EALLOW; GpioCtrlRegs.GPAPUD.all &= (~0x00091040); //除能上拉电阻 GpioCtrlRegs.GPADIR.all &= (~0x00091040); //输入 GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 0; //GPIO19 GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 2; // 6 samples GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; //GPIO6 GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 2; // 6 samples GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0; //GPIO12 GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 2; // 6 samples GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 0; //GPIO16 GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 2; // 6 samples EDIS; GpioDataRegs.GPASET.all |= 0x00091040; key1_handle = key1_dle; key2_handle = key2_dle; key3_handle = key3_dle; key4_handle = key4_dle; } char KEY_scanf_handle() { char KEY_mun = 0; if(KEYs_on) { DELAY_US(delay_cheak); if(KEYs_on) { if(KEY1_on) { (*key1_handle)(); KEY_mun = KEY1; } if(KEY2_on) { (*key2_handle)(); KEY_mun = KEY2; } if(KEY3_on) { (*key3_handle)(); KEY_mun = KEY3; } if(KEY4_on) { (*key4_handle)(); KEY_mun = KEY4; } } } return KEY_mun; }