全新论坛MCU智学网上线,欢迎访问新论坛!稀缺资源、技术干货、参考设计、原厂资料尽在MCU智学网
更新自动建库工具PCB Footprint Expert 2023.13 Pro / Library Expert 破解版

大家帮忙看看啊

[复制链接]
2591 4

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
下面的代码怎么会使灯闪烁三次啊?

                           delayms(300);
                        yellow_b=~yellow_b;
                        blue_b=1;
                              if(++count!=10) return;
                         count=0;

举报

回复

4 个评论

ad***  管理员  发表于 2012-8-14 18:54:58  | 显示全部楼层
这个代码不会让灯闪烁3次的 建议你吧全部代码发出来帮你看下
9716***  新手上路  发表于 2012-8-15 08:50:09  | 显示全部楼层
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit red_a=P1^0;//东西向灯
sbit yellow_a=P1^1;
sbit blue_a=P1^2;
sbit red_b=P1^3;
sbit yellow_b=P1^4;
sbit blue_b=P1^5;
uchar count=0,type=1;//闪烁次数,操作类型变量
void delayms(uint xm)
{
     uint i,j;
         for(i=xm;i>0;i--)
                 for(j=110;j>0;j--);
}
void traffic_light()
{
     switch(type)
         {
             case 1:
                    red_a=1;
                        yellow_a=1;
                        blue_a=0;
                        red_b=0;
                        yellow_b=1;
                        blue_b=1;
                        delayms(2000);
                        type=2;
                        break;
                case 2:
                    delayms(300);
                        yellow_a=~yellow_a;
                        blue_a=1;
                    if(++count!=10) return;
                         count=0;
                        type=3;
                        break;
                 case 3:
                    red_a=0;
                        yellow_a=1;
                        blue_a=1;
                        red_b=1;
                        yellow_b=1;
                        blue_b=0;
                        delayms(2000);
                        type=4;
                        break;
                case 4:
                    delayms(300);        //五次闪烁
                        yellow_b=~yellow_b;
                        blue_b=1;
                    if(++count!=10) return;
                         count=0;
                        type=1;
                        break;



      }

}
void main()
{
     while(1)
         {
           traffic_light();
         }
}
り亚马***  注册会员  发表于 2012-8-15 11:41:52  | 显示全部楼层
不打注释很难看啊。
ad***  管理员  发表于 2012-8-16 18:44:54  | 显示全部楼层
把你要求的效果 和这段代码出现的BUG说下帮你调试下
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

打开支付宝扫一扫,最高立得1212元红包
搜索

图文热点

更多

社区学堂

更多

客服中心

QQ:187196467 服务时间:周一至周日 8:30-20:30

关注我们

关于我们
关于我们
友情链接
联系我们
帮助中心
网友中心
购买须知
支付方式
服务支持
资源下载
售后服务
定制流程
关注我们
官方微博
官方空间
官方微信
快速回复 返回顶部 返回列表