51单片机的状态机消抖
#include
enum State {Init, Press, Free}; //定义按键状态的枚举类型
enum State Key_State;
sbit Key1 =
sbit Key2 =
sbit Key3 =
sbit Key4 =
void Delay_ms(unsigned int x)
{
int i,j;
for(i=0; i<110; i++)
for(j=0; j ; } //=============================================================================== //函数名称:键盘扫描(状态机无延时消抖) //说明:键盘接口对应: key1 = P2-4 key2 = P2-5 //参数: //返回值: //日期:2011-6-22 //修改: //=============================================================================== void Keyscan(void) { switch (Key_State) { P1 = 0xfe; Delay_ms(500); P1 = 0xff; P1 = 0xfd; Delay_ms(500); P1 = 0xff; P1 = 0xfb; Delay_ms(500); P1 = 0xff; P1 = 0xf7; Delay_ms(500); P1 = 0xff; } } 这是另外一种,其实都差不多,只不过比较直观而已。 void Keyscan(void) { switch (Key_State) { P1 = 0xfe; Delay_ms(500); P1 = 0xff; P1 = 0xfd; Delay_ms(500); P1 = 0xff; P1 = 0xfb; Delay_ms(500); P1 = 0xff; P1 = 0xf7; Delay_ms(500); P1 = 0xff; } }
51单片机状态机消 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)