求助各位高手,本人现在遇到一个STM8S105S4自定义加一个触摸按键控制LED开发难题.
要求是自己定义一个按键,来控制LED2灯,我现在已经在电路板的PA端口,用(PA5)引出一个线,并连上一个自定义按键,PA6用于LOAD, PA4用于中断屏蔽.其程序修改如下
在头文件 STM8_TSL_RC_Configuration.h中修改:
#define SCKEY_P2_KEY_COUNT (1) /**< Single channel key Port 2: Number of keys used (value from 0 to 8) */
#define SCKEY_P2_PORT_ADDR (GPIOA_BaseAddress) /**< Single channel key Port 2: GPIO base address */
#define SCKEY_P2_A (0x10) /**< Single channel key Port 2: 1st key mask */
#define SCKEY_P2_B (0) /**< Single channel key Port 2: 2nd key mask */
#define SCKEY_P2_C (0) /**< Single channel key Port 2: 3rd key mask */
#define SCKEY_P2_D (0) /**< Single channel key Port 2: 4th key mask */
#define SCKEY_P2_E (0) /**< Single channel key Port 2: 5th key mask */
#define SCKEY_P2_F (0) /**< Single channel key Port 2: 6th key mask */
#define SCKEY_P2_G (0) /**< Single channel key Port 2: 7th key mask */
#define SCKEY_P2_H (0) /**< Single channel key Port 2: 8th key mask */
#define SCKEY_P2_DRIVEN_SHIELD_MASK (0x08)
原触摸按键有三个,用的是PB端口.
另外在源文件STM8_TS_LIB夹中的STM8_TSL_RC_Singlechannelkey.c中添加如下:
/**
******************************************************************************
* @brief Select Port 1 I/Os to burst and call IO driver for burst sequence.
* @par Parameters:
* None
* @retval void None
* @par Required preconditions:
* None
******************************************************************************
*/
void TSL_SCKEY_P1_Acquisition(void)
{
sTouchIO.PORT_ADDR = (GPIO_TypeDef *) (SCKEY_P1_PORT_ADDR);
for ( KeyIndex = 0; KeyIndex < SCKEY_P1_KEY_COUNT; KeyIndex++ )
{
TSL_SetStructPointer();
if ( (pKeyStruct->State.whole != ERROR_STATE) && (pKeyStruct->State.whole != DISABLED_STATE) )
{
sTouchIO.AcqMask = Table_SCKEY_BITS[KeyIndex];
sTouchIO.DriveMask = (u8)(sTouchIO.AcqMask | SCKEY_P1_DRIVEN_SHIELD_MASK);
sTouchIO.Measurement = &sSCKeyInfo[KeyIndex].Channel.LastMeas;
sTouchIO.RejectedNb = &sSCKeyInfo[KeyIndex].Channel.LastMeasRejectNb;
sTouchIO.Type = SCKEY_TYPE;
TSL_IO_Acquisition(SCKEY_ACQ_NUM, SCKEY_ADJUST_LEVEL);
}
}
}
另外,在main.c中添加
if (sSCKeyInfo[3].Setting.b.DETECTED) /* KEY 1 touched */
{
if (Led1State == OFF)
{
LED1_ON();
}
else
{
LED1_OFF();
}
}
}
可最终无法实现自定义加一个触摸按键控制LED功能,难道是程序有问题吗?恳请各位高手指点 |
|