鱼C论坛

 找回密码
 立即注册
查看: 1095|回复: 1

[已解决]流水灯,它不闪烁啊啊啊

[复制链接]
发表于 2022-10-15 17:20:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
代码如下
#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
QQ图片20221015171712.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-10-15 18:51:50 | 显示全部楼层    本楼为最佳答案   
本帖最后由 小伤口 于 2022-10-15 18:53 编辑

EX1 = 1;//INT1中断允许
EA = 1;//全局中断打开
IT1 = 1;//触发方式为下降沿触发

打开外部中断1应该是interrupt 2
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-28 00:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表