独立按键

独立按键原理


按键在闭合和断开时触电存在抖动现象
硬件消抖电路如下

实验代码

#include "reg52.h"typedef unsigned char u8;typedef unsigned int u16;void delay(u16 i){while(i--);}sbit led=P2^0;sbit k1=P3^1;void keypro(){if(k1==0){delay(1000);if(k1==0){led=~led;}while(!k1);}}void main(){while(1){keypro();}}