新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 单片机控制三盏LED灯亮灭的程序

单片机控制三盏LED灯亮灭的程序

作者:时间:2012-10-11来源:网络收藏
**************************控制要求*****************************按下p1.0一次 LED1 亮 ,再按一次 LED1   LED2 亮    ,再按一次 LED1   LED2  LED3 亮 ,再按一次 三盏全部熄灭。#include reg52.h>#define uchar unsigned char#define uint unsigned intuchar num;sbit p10=P1^0;   /*按键*/sbit p01=P0^1;   /*LED1*/sbit p02=P0^2;   /*LED2*/sbit p03=P0^3;   /*LED3*/void delay(uint xms)//{uint k,j;for(k=xms;k>0;k--)for(j=1;j>0;j--);}void main(){while(1){if(p10==0) //按键按下{delay(10); //延时消抖10毫秒if(p10==0){           num++;while(p10==0);//等待按键释放                 }}if(num==0){p03=1;p02=1;p01=1;}if(num==1){p03=1;p02=1;p01=0;}                if(num==2){p03=1;p01=0;p02=0;}if(num==3){p02=0;p01=0;p03=0;}if(num==4){num=0;}}}

led灯相关文章:led灯原理




评论


相关推荐

技术专区

关闭