keil吧 关注:14,990贴子:30,295
  • 2回复贴,共1

求大家解答

只看楼主收藏回复

单片机正常运行时,P1口驱动8个led灯循环闪烁,当外部中断0产生后,单号流水点亮,同时P0.0驱动一个led灯亮;当外部中断1产生后,双号LED流水点亮,p0.1驱动一个led灯亮,且双号灯优先级高于单号灯


IP属地:湖南来自Android客户端1楼2015-10-27 08:32回复
    #include<reg51.h>
    #define uchar unsigned char
    #define uint unsigned int
    uchar f;
    sbit LED1=P1^0;
    sbit LED2=P1^1;
    sbit LED3=P1^2;
    sbit LED4=P1^3;
    sbit LED5=P1^4;
    sbit LED6=P1^5;
    sbit LED7=P1^6;
    sbit LED8=P1^7;
    void delay_ms()
    {
    uchar i;
    while(i--)
    for(i=0;i<125;i++)
    ;
    }
    void flicker(void)
    {
    P1=0x00;
    delay_ms();
    P1=0xff;
    delay_ms();
    }
    void main(void)
    {
    EA=1;
    EX0=1;
    EX1=1;
    f=1;
    while(1)
    {
    switch(f)
    {
    case 1:flicker();break;
    case 2:
    LED1=0;
    LED3=0;
    LED5=0;
    LED7=0;
    LED2=1;
    LED4=1;
    LED6=1;
    LED8=1;
    break;
    case 3:
    LED1=1;
    LED3=1;
    LED5=1;
    LED7=1;
    LED2=0;
    LED4=0;
    LED6=0;
    LED8=0;
    break;
    }
    delay_ms();
    }
    }
    void int0()interrupt 0
    {
    f=2;
    }
    void int1()interrupt 2
    {
    f=3;


    IP属地:湖南来自Android客户端2楼2015-10-27 08:38
    回复
      不知道怎么让单双号流水


      IP属地:湖南来自Android客户端3楼2015-10-27 08:38
      回复