找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1825|回复: 8
打印 上一主题 下一主题
收起左侧

哪位大神看下 为什么状态不能循环

[复制链接]
跳转到指定楼层
楼主
ID:117161 发表于 2017-6-14 20:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include<reg51.h>
#include<intrins.h>
sbit P3_0=P3^0;
// unsigned char led[]={0x90,0x82,0xc0,0x90,0xa4,0xc0};
// unsigned char led1[]={0x90,0xc0,0xf9,0xa4,0xa4,0x92};
// unsigned char led2[]={0xff,0xff,0xff,0xff,0xff,
//       0x89,0x86,0xc7,0xc7,0xc0,0xff};
// unsigned char com[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,};
// unsigned char j,n,x;
void delay(unsigned int i)
{
unsigned int k;
for(k=0;k<i;k++);
}
void disp1()
{
unsigned char led[]={0x90,0x82,0xc0,0x90,0xa4,0xc0};
unsigned char x,w;  
   w=0xfe;
  for(x=0;x<6;x++)
      {
       P1=0xff;
    P2=w;
    w=_crol_(w,1);
    P1=led[x];
    delay(100);
       }
   }
  void disp2()
{
unsigned char led1[]={0x90,0xc0,0xf9,0xa4,0xa4,0x92};
unsigned char y,d;
   d=0xfe;
  for(y=0;y<6;y++)
      {
       P1=0xff;
    P2=d;
    d=_crol_(d,1);
    P1=led1[y];
    delay(100);
         
       }
   }
  void disp3()   
  {
    unsigned char led2[]={0xff,0xff,0xff,0xff,0xff,
       0x89,0x86,0xc7,0xc7,0xc0,0xff};
    unsigned char com[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,};
    unsigned char i,j,n;
   {for(n=0;n<6;n++) //HELLO
     for(j=0;j<100;j++)
      for(i=0;i<6;i++)
     {
       P1=0xff;
    P2=com[i];
    P1=led2[n+i];
    delay(100);
      }   
       }
   }   
  void main()
{
  unsigned char num;
  P1=0xff;
   while(1)
   {   
      if(P3_0==0)
   {
    delay(10);
  if(P3_0==0)
   {
     num++;
    if(num==3)
  {
  num=0;
  }
while(P3_0==0);
   }
   }
  
   switch(num)
      {
   case 0:disp1();break;
   case 1:disp2();break;
   case 2:disp3();break;
   }
    }
  }

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:89515 发表于 2017-6-15 01:19 | 只看该作者
延时时间太短
回复

使用道具 举报

板凳
ID:211416 发表于 2017-6-15 09:39 | 只看该作者
延时时间可能短了
回复

使用道具 举报

地板
ID:211740 发表于 2017-6-16 00:14 | 只看该作者
此程序是不是完成按key1,key2,key3时执行对应的显示dis1,dis2,dis3
可能是在显示函数中没有出来,在switch处设置断点调试就能看出来。
回复

使用道具 举报

5#
ID:211740 发表于 2017-6-16 00:18 | 只看该作者
在switch处设置断点看看,可能是没有从显示函数返回。
回复

使用道具 举报

6#
ID:211773 发表于 2017-6-16 09:37 | 只看该作者
switch(num)       {    case 0:disp1();break;    case 1:disp2();break;    case 2:disp3();break;    }     }   } 没有结束语句
回复

使用道具 举报

7#
ID:211778 发表于 2017-6-16 09:46 | 只看该作者
if(num>=3)
回复

使用道具 举报

8#
ID:211792 发表于 2017-6-16 10:22 | 只看该作者
时间短什么的不是问题,关键是关联有问题
回复

使用道具 举报

9#
ID:117161 发表于 2017-6-26 10:46 | 只看该作者
是dis3  没扫完
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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