标题: 三个按键,控制不同状态的LED [打印本页]

作者: 紫影    时间: 2016-3-18 13:12
标题: 三个按键,控制不同状态的LED
  #include <reg51.h>
  #include <intrins.h>
  #define uchar unsigned char
  #define uint unsigned int
  sbit P1_0=P1^0;
  sbit P1_1=P1^1;
  sbit P1_2=P1^2;
  void delay();
  void main()
  {      
  unsigned char num=0xfe,c=0;
   EX0=1;EA=1;IT0=0;
  for(c=0;c<8;c++)
   {
    P0=num;
  delay();
  num=_cror_(num,1);
  delay();  
   }
      for(c=0;c<8;c++)
   {
    P0=num;
  delay();
  num=_crol_(num,1);
  delay();
}
  
  P0=0x00;delay();P0=0xff;delay();
    P0=0x00;delay();P0=0xff;delay();
   P0=0x00;delay();P0=0xff;delay();
  
  }
  void int0() interrupt 0
  {  
  
  if(P1_0==0)
  {
  unsigned char num=0xfe,c=0;
   for(c=0;c<8;c++)
  {
  P0=num;num=_crol_(num,1);delay();
  }
  }
  if(P1_1==0)
  {  
   unsigned char num=0xfe,c=0;
for(c=0;c<8;c++)
  {
  P0=num;num=_cror_(num,1);delay();
  }
  }
  if(P1_2==0   )
  {
  P0=0x00;delay();P0=0xff;delay();
    P0=0x00;delay();P0=0xff;delay();
   P0=0x00;delay();P0=0xff;delay();
  }
  }
  void delay()
  {
  unsigned char a,b;
  for(a=0;a<250;a++)
   for(b=0;b<200;b++);
  }


作者: 紫影    时间: 2016-3-18 13:13
Proteus线路图

捕获.PNG (75.54 KB, 下载次数: 121)

捕获.PNG





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1