- 打卡等级:初来乍到
- 打卡总天数:5
- 最近打卡:2026-02-02 08:30:39
已绑定手机
注册会员
- 积分
- 66
|
大家好,我用STC8G1K芯片,P3.3设为输入带上拉,外接一机械开关,
用别人写好的可用的程序,但检测不到开关,能指点下么?
第一次用STC芯片,能加个联系方式么,谢谢!V 是ABC6036783谢谢。
我有下载一些资料查看,但没解决
sbit KEY0 = P3^3; //
sbit KEY1 = P5^4; //
sbit KEY2 = P5^5; //
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//设置P5.4、P5.5口工作模式
GPIO_InitStructure.Pin=GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.Mode=GPIO_PullUp; //配置P1.4口为准双向口
//GPIO_InitStructure.Mode=GPIO_OUT_PP; //配置P1.4口为推挽输出(强上拉)
//GPIO_InitStructure.GPIO_HighZ; //配置P1.4口为高阻输入
//GPIO_InitStructure.Mode=GPIO_OUT_OD; //配置P1.4口为开漏输出
GPIO_Inilize(GPIO_P5,&GPIO_InitStructure);
GPIO_InitStructure.Pin=GPIO_Pin_3;
GPIO_InitStructure.Mode=GPIO_PullUp; //配置P口为准双向口
GPIO_Inilize(GPIO_P3,&GPIO_InitStructure);
KEY0 = 1; //
KEY1 = 1; //
KEY2 = 1; //
}
//按键处理函数
//返回按键值
//mode:0,不支持连续按;1,支持连续按;
//返回值:
//0,没有任何按键按下
//KEY0_PRES,KEY0按下
//KEY1_PRES,KEY1按下
//KEY2_PRES,KEY2按下
//KEY3_PRES,KEY3按下
unsigned char KEY_Scan(char mode)
{
static char key_up=1;//按键按松开标志
if(mode)key_up=1; //支持连按
if(key_up&&(KEY0==0||KEY1==0||KEY2==0))
{
Delay20ms();//去抖动
key_up=0;
if(KEY0==0)return KEY0_PRES;
else if(KEY1==0)return KEY1_PRES;
else if(KEY2==0)return KEY2_PRES;
}else if(KEY0==1&&KEY1==1&&KEY2==1)key_up=1;
return 0;// 无按键按下
}
|
|