五、独立按键

课件资源下载:http://download.csdn.net/detail/liuzhuomju/4087359

独立按键:

 

 

例程:

功能:按键K5按下 蜂鸣器响一声

 

#include<reg52.h>
sbit K5=P1^4;
sbit FMQ=P3^6;
//char  wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位选、从低到高
//char duan[]={0x7f,0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//.0123456789
 
void delayms(unsigned int i)
{
unsigned char j;
 while(i--)
 {
 for(j=0;j<115;j++)   //1ms基准延时程序
 {
  ;
 }
 } 
}

void delay500us()
{

unsigned char j;

 for(j=0;j<57;j++)   //500us基准延时程序
 {
  ;
 }
}
 void beef()
 {
 //蜂鸣器
   FMQ=0;
   delay500us();
   FMQ=1;
   delay500us();
 }
void main()
{
 while(1)
 {
 //循环检测
 if(K5==0)
 {
  delayms(1);  //延时消抖
  if(K5==0)
  {
  beef();
  }

 }
 }
}

 

 

矩阵按键:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值