胚芽鞘 发表于 2022-10-15 17:20:14

流水灯,它不闪烁啊啊啊

代码如下#include "reg51.h"

sbit P0_0 = P0^0;
sbit P0_1 = P0^1;
sbit P0_2 = P0^2;
sbit P0_3 = P0^3;
sbit P0_4 = P0^4;
sbit P0_5 = P0^5;
sbit P0_6 = P0^6;
sbit P0_7 = P0^7;

void delay(int time);
void delay(int time)
{
        int i=0;
        for(i=time;i>0;i--);
}

void int0() interrupt 0
{
        int i;
        for(i = 0; i < 3; i ++)
        {
                P0_0 = 0;
                delay(10000000000);
                P0_0 = 1;
                P0_1 = 0;
                delay(10000000000);
                P0_1 = 1;
                P0_2 = 0;
                delay(10000000000);
                P0_2 = 1;
                P0_3 = 0;
                delay(10000000000);
                P0_3 = 1;
                P0_4 = 0;
                delay(10000000000);
                P0_4 = 1;
                P0_5 = 0;
                delay(10000000000);
                P0_5 = 1;
                P0_6 = 0;
                delay(10000000000);
                P0_6 = 1;
                P0_7 = 0;
                delay(10000000000);
                P0_7 = 1;
        }
}

void int1() interrupt 1
{
        int i;
        for(i = 0; i < 3; i ++)
        {
                P0_7 = 0;
                delay(10000000000);
                P0_7 = 1;
                P0_6 = 0;
                delay(10000000000);
                P0_6 = 1;
                P0_5 = 0;
                delay(10000000000);
                P0_5 = 1;
                P0_4 = 0;
                delay(10000000000);
                P0_4 = 1;
                P0_3 = 0;
                delay(10000000000);
                P0_3 = 1;
                P0_2 = 0;
                delay(10000000000);
                P0_2 = 1;
                P0_1 = 0;
                delay(10000000000);
                P0_1 = 1;
                P0_0 = 0;
                delay(10000000000);
                P0_0 = 1;
        }
}

int main()
{
        IT0 = 1;
        IT1 = 1;
        EX0 = 1;
        EA = 1;
        while(1)
        {
                P0_0 = 0;
                P0_1 = 0;
                P0_2 = 0;
                P0_3 = 0;
                P0_4 = 0;
                P0_5 = 0;
                P0_6 = 0;
                P0_7 = 0;
                delay(10000000000);
                P0_0 = 1;
                P0_1 = 1;
                P0_2 = 1;
                P0_3 = 1;
                P0_4 = 1;
                P0_5 = 1;
                P0_6 = 1;
                P0_7 = 1;
        }
       
}

小伤口 发表于 2022-10-15 18:51:50

本帖最后由 小伤口 于 2022-10-15 18:53 编辑

EX1 = 1;//INT1中断允许
EA = 1;//全局中断打开
IT1 = 1;//触发方式为下降沿触发
打开外部中断1应该是interrupt 2
页: [1]
查看完整版本: 流水灯,它不闪烁啊啊啊