3723|7

93

帖子

0

TA的资源

纯净的硅(中级)

楼主
 

LED程序 [复制链接]

#define uchar unsigned char //定义一下方便使用
#define uint  unsigned int
#define ulong unsigned long
#include <reg52.h>     //包括一个52标准内核的头文件

sbit K0=P1^0;   /*R通道*/
sbit K1=P1^1;   /*G通道*/
sbit K2=P1^2;   /*B通道*/
sbit K3=P1^3;   /*W通道*/
sbit K4=P1^4;   /* AUTO RUN 模式  */
sbit K5=P1^5;   /* MUSIC    模式 */
sbit K6=P1^6;   /* DXM 控制模式 */
sbit K7=P1^7;   /* ALL LIGHT  */
sbit K8=P3^2;

void delay_ms(uint);
void timer0();

char code dx516[3] _at_ 0x003b;//这是为了仿真设置的

void main(void) // 主程序
{

 while(1)
 {
  if (K4==0)         /*判断K4是否按下*/
    {
    P0=0x01;P2=0x00;delay_ms(400);
    P0=0x10;P2=0x00;delay_ms(400);
    P0=0x00;P2=0x80;delay_ms(400);
    P0=0x00;P2=0x08;delay_ms(400); 
    P0=0x11;P2=0x88;delay_ms(100);  
    P0=0x00;P2=0x00;delay_ms(100);
    P0=0x55;P2=0xaa;delay_ms(100); 
    P0=0x77;P2=0xee;delay_ms(100);  

    P0=0xff;P2=0xff;delay_ms(100); 

    P0=0x77;P2=0xee;delay_ms(100); 
    P0=0x55;P2=0xaa;delay_ms(100); 

    P0=0x11;P2=0x88;delay_ms(100);
    P0=0x00;P2=0x00;delay_ms(100);
    if(K4==1)
    break;
    }
  else if(K5==0)        /*判断K5是否按下*/
    {
    timer0();
    if(K5==1)
    break;
    }
  else
    {P0=0x00,P2=0x00;}
 }
}

void timer0() interrupt 1
{ uchar i;

 IT1=0; 
 EX1=1;

 EA = 1;    //打开总中断

 while(1)
 {
  if(!K8) 
  {
   while(!K8);
   
   switch(i)
   {
    case 0:
      P0=0xff,P2=0x00; 
    break;
    case 1:
      P0=0x00,P2=0xff; 
    break;
    case 2:
      P0=0x0f,P2=0x0f; 
    break;
    case 3:
      P0=0xf0,P2=0xf0; 
    break;
    case 4:
      P0=0x0f,P2=0xf0; 
    break;
    case 5:
      P0=0xf0,P2=0x0f; 
    break;
   }
   i++;
   if(K5==1)break;
   if(i==6)i=0;

  } break;
 }

}

void delay_ms(uint z)
{
 unsigned int  i,j;
 for(i=z;i>0;i--)
  for(j=100;j>0;j--);
}

各位高手,我的程序在红色部分无法中断,就是在程序在执行红色部时,我断开K4,然后按下K5时,无法直接进入中断,要等红色部分走完,要什么改呢,希望给我指点一下,非常感谢!我的QQ:306048732

[ 本帖最后由 czc568 于 2010-6-3 09:13 编辑 ]
此帖出自单片机论坛

最新回复

你在主程序里面没有开设外部中断,也就是没有开中断初始化,你改一下程序试试。  详情 回复 发表于 2010-6-3 10:53
点赞 关注
 

回复
举报

6366

帖子

4917

TA的资源

版主

沙发
 
延时程序占用了太多时间,导致你按下K5时,这些演示程序还没跑完呢,也就响应不到你的按下K5这个事件,
建议使用状态及的方法来实现按键的检测
此帖出自单片机论坛
 
 

回复

1759

帖子

0

TA的资源

裸片初长成(高级)

板凳
 
你在主程序里面没有开设外部中断,也就是没有开中断初始化,你改一下程序试试。
此帖出自单片机论坛
 
个人签名南京璞晓电子   www.cpx0.com需要
msn:njlianjian@hotmail.com
 
 

回复

93

帖子

0

TA的资源

纯净的硅(中级)

4
 

补充LED程序

#define uchar unsigned char //定宏义
#define uint  unsigned int
#define ulong unsigned long
#include <reg52.h>      //包括一个52标准内核的头文件
/********************************
*        IO口定义                 *
********************************/
sbit K0=P1^0;   //R通道
sbit K1=P1^1;   //G通道
sbit K2=P1^2;   //B通道
sbit K3=P1^3;   //W通道
sbit K4=P1^4;   // AUTO RUN 模式  
sbit K5=P1^5;   // MUSIC    模式 
sbit K6=P1^6;   // DXM 控制模式 
sbit K7=P1^7;   // ALL LIGHT  
sbit K8=P3^2;
/********************************
*        子函数定义             *
********************************/
void delay_ms(uint);
void INTR0();
void ZT_0();
void ZT_1();
void ZT_2();
void ZT_3();
void ZT_4();
void ZT_5();
void ZT_6();
void ZT_7();
void ZT_8();
void ZT_9();
void ZT_10();
void ZT_11();
void ZT_12();
void ZT_13();
void ZT_14();
void ZT_15();
void ZT_16();
/********************************
*          参数定义               *
********************************/
uint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,
aa=0,bb=0,cc=0,dd=0,ee=0,ff=0,gg=0,hh=0;

/********************************
*         主函数                    *
********************************/
void main(void)          
{        
 P0=0x00,P2=0x00;  //端口初始化
 while(1)
 { 
  if (K4==0)  //判断K4是否按下
    {
    delay_ms(100);
//    ZT_0();if(a<33)continue;
//    ZT_1();if(b<41)continue;
    ZT_2();if(c<9)continue;                 //我想让这个子程序在这里循环3次,怎么修改呢。
    ZT_7();if(h<16)continue;
    ZT_3();if(d<8)continue;
    ZT_16();if(s<9)continue;
    ZT_6();if(g<11)continue;
    ZT_8();if(k<5)continue;
    ZT_15();if(r<8)continue;
    ZT_4();if(e<5)continue;
    ZT_14();if(q<16)continue;
    ZT_5();if(f<5)continue;
    ZT_9();
    ZT_10();
    ZT_11();
    ZT_12();
    ZT_13();
    if(K4==1)
    break;
    }
  else if(K5==0)     //判断K5是否按下
    {
    delay_ms(100);
    IT0=1;    //设定中断触发方式
    EX0=1;    //开启外部中断1(INT1)
    EA=1;     //打开总中断
    INTR0();
    if(K5==1)
    break;
    }
  else if(K0==0)     //判断K0是否按下
    {
    delay_ms(100);
    P0=0x22;P2=0x44;  //R 亮
    if(K0==1)
    break;
    }
  else if(K1==0)     //判断K1是否按下
    {
    delay_ms(100);
    P0=0x44;P2=0x22;  //G 亮
    if(K1==1)
    break;
    }
  else if(K2==0)     //判断K2是否按下
    {
    delay_ms(100);
    P0=0x88;P2=0x11;  //B 亮
    if(K2==1)
    break;
    }
  else if(K3==0)     //判断K3是否按下
    {
    delay_ms(100);
    P0=0x11;P2=0x88;  //W 亮
    if(K3==1)
    break;
    }
  else if(K6==0)
    {
    delay_ms(100);
    P0=0xff;P2=0xff;delay_ms(200);  //频闪
    P0=0x00;P2=0x00;delay_ms(100);
    if(K6==1)
    break;
    }
  else {P0=0x00;P2=0x00;}
 }
}

/************************************
*          中断服务子程序         *   
************************************/
void INTR0() interrupt 0
{ uchar i;
// PX1=1; 
 EX0=0;

 while(1)
 {
  if(!K8) 
  { 
   while(!K8);   
   switch(i)
   {
    case 0:
      ZT_0();if(a<33)
     continue;  
     break;
    case 1:
      ZT_1();if(b<45)
     continue; 
     break;
    case 2:
      ZT_2();if(c<8)
     continue; 
     break;
    case 3:
      ZT_16();if(s<9)
     continue; 
     break;
    case 4:
     ZT_8();if(k<10)
      continue; 
     break;
    case 5:
     ZT_7();if(h<16)
      continue; 
     break;
   }
   i++;
   if(K5==1)break;
   if(i==5)i=0;
   EX0=1;
  } break;
 }

}

 

void delay_ms(uint z)
{
 uint  i,j;
 for(i=z;i>0;i--)
  for(j=100;j>0;j--);
}

LED仿真图.rar

17.2 KB, 下载次数: 0

此帖出自单片机论坛
 
 
 

回复

93

帖子

0

TA的资源

纯净的硅(中级)

5
 

连接上一页

void ZT_0(void)         
{
 switch(a)
  {
  case 0:P0=0x01,P2=0x00;delay_ms(400);break;   //1W
  case 1:P0=0x10,P2=0x00;delay_ms(400);break;   //2W
  case 2:P0=0x00,P2=0x80;delay_ms(400);break;   //3W
  case 3:P0=0x00,P2=0x08;delay_ms(400);break;   //4W
  case 4:P0=0x04,P2=0x00;delay_ms(400);break;   //1G
  case 5:P0=0x40,P2=0x00;delay_ms(400);break;   //2G
  case 6:P0=0x00,P2=0x20;delay_ms(400);break;   //3G
  case 7:P0=0x00,P2=0x02;delay_ms(400);break;   //4G
  case 8:P0=0x02,P2=0x00;delay_ms(400);break;   //1R
  case 9:P0=0x20,P2=0x00;delay_ms(400);break;   //2R
  case 10:P0=0x00,P2=0x40;delay_ms(400);break;  //3R
  case 11:P0=0x00,P2=0x04;delay_ms(400);break;  //4R
  case 12:P0=0x08,P2=0X00;delay_ms(400);break;  //1B
  case 13:P0=0x80,P2=0X00;delay_ms(400);break;  //2B
  case 14:P0=0x00,P2=0x10;delay_ms(400);break;  //3B
  case 15:P0=0x00,P2=0x01;delay_ms(400);break;  //4B
  case 16:P0=0x00,P2=0x04;delay_ms(400);break;  //4R
  case 17:P0=0x00,P2=0x44;delay_ms(400);break;  //4R-3R
  case 18:P0=0x20,P2=0x44;delay_ms(400);break;  //4R-3R-2R
  case 19:P0=0x22,P2=0x44;delay_ms(400);break;  //4R-3R-2R-1R
  case 20:P0=0x00,P2=0x02;delay_ms(400);break;  //4G
  case 21:P0=0x00,P2=0x22;delay_ms(400);break;  //4G-3G
  case 22:P0=0x40,P2=0x22;delay_ms(400);break;  //4G-3G-2G
  case 23:P0=0x44,P2=0x22;delay_ms(400);break;  //4G-3G-2G-1G
  case 24:P0=0x00,P2=0x01;delay_ms(400);break;  //4B
  case 25:P0=0x00,P2=0x11;delay_ms(400);break;  //4B-3B
  case 26:P0=0x80,P2=0x11;delay_ms(400);break;  //4B-3B-2B
  case 27:P0=0x88,P2=0x11;delay_ms(400);break;  //4B-3B-2B-1B
  case 28:P0=0x00,P2=0x08;delay_ms(400);break;  //4W
  case 29:P0=0x00,P2=0x88;delay_ms(400);break;  //4W-3W
  case 30:P0=0x10,P2=0x88;delay_ms(400);break;  //4W-3W-2W
  case 31:P0=0x11,P2=0x88;delay_ms(400);break;  //4W-3W-2W-1W
  case 32:P0=0x00,P2=0x00;delay_ms(200);break;  //hold on
  }
 a++; 
// if(a==32)a=0; 
}
void ZT_1(void)
{
 switch(b)
  {
  case 0:P0=0x00;P2=0x00;delay_ms(200);break;   //hold on    
  case 1:P0=0x0f;P2=0x00;delay_ms(400);break;   //one
  case 2:P0=0xff;P2=0x00;delay_ms(400);break;   //one two    
  case 3:P0=0xff;P2=0xf0;delay_ms(400);break;   //one two three
  case 4:P0=0xff;P2=0xff;delay_ms(400);break;   //one two three four
  case 5:P0=0xff;P2=0xf0;delay_ms(400);break;   //one two three
  case 6:P0=0xff;P2=0x00;delay_ms(400);break;   //one two
  case 7:P0=0x0f;P2=0x00;delay_ms(400);break;   //one
  case 8:P0=0x00;P2=0x00;delay_ms(200);break;   //hold on
  case 9:P0=0x02;P2=0x00;delay_ms(400);break;   //1R
  case 10:P0=0x22;P2=0x00;delay_ms(400);break;  //1R-2R
  case 11:P0=0x22;P2=0x40;delay_ms(400);break;  //1R-2R-3R
  case 12:P0=0x22;P2=0x44;delay_ms(400);break;  //1R-2R-3R-4R
  case 13:P0=0x26;P2=0x44;delay_ms(400);break;  //R+1G
  case 14:P0=0x66;P2=0x44;delay_ms(400);break;  //R+1G-2G
  case 15:P0=0x66;P2=0x64;delay_ms(400);break;  //R+1G-2G-3G
  case 16:P0=0x66;P2=0x66;delay_ms(400);break;  //R+1G-2G-3G-4G
  case 17:P0=0x6e;P2=0x66;delay_ms(400);break;  //R+G+1B
  case 18:P0=0xee;P2=0X66;delay_ms(400);break;  //R+G+1B-2B
  case 19:P0=0xee;P2=0x76;delay_ms(400);break;  //R+G+1B-2B-3B
  case 20:P0=0xee;P2=0x77;delay_ms(400);break;  //R+G+1B-2B-3B-4B
  case 21:P0=0xef;P2=0x77;delay_ms(400);break;  //R+G+B+1W
  case 22:P0=0xff;P2=0x77;delay_ms(400);break;  //R+G+B+1W-2W
  case 23:P0=0xff;P2=0xf7;delay_ms(400);break;  //R+G+B+1W-2W-3W
  case 24:P0=0xff;P2=0xff;delay_ms(400);break;  //R+G+B+1W-2W-3W-4W
  case 25:P0=0x00;P2=0x00;delay_ms(200);break;  //hold on
  case 26:P0=0x20;P2=0x40;delay_ms(400);break;  //内R
  case 27:P0=0x02;P2=0x04;delay_ms(400);break;  //外R
  case 28:P0=0x04;P2=0x02;delay_ms(400);break;  //外G
  case 29:P0=0x40;P2=0x20;delay_ms(400);break;  //内G
  case 30:P0=0x80;P2=0x10;delay_ms(400);break;  //外B
  case 31:P0=0x08;P2=0x01;delay_ms(400);break;  //内B
  case 32:P0=0x01;P2=0x08;delay_ms(400);break;  //内W
  case 33:P0=0x10;P2=0x80;delay_ms(400);break;  //外W
  case 34:P0=0x11;P2=0x88;delay_ms(500);break;  //W亮
  case 35:P0=0x44;P2=0x22;delay_ms(500);break;  //G亮
  case 36:P0=0x22;P2=0x44;delay_ms(500);break;  //R亮
  case 37:P0=0x88;P2=0x11;delay_ms(500);break;  //B亮
  case 38:P0=0x00;P2=0x00;delay_ms(200);break;  //hold on
  case 39:P0=0x66;P2=0x66;delay_ms(400);break;  //RG
  case 40:P0=0x99;P2=0x99;delay_ms(400);break;  //WB
  case 41:P0=0xaa;P2=0x55;delay_ms(400);break;  //RB
  case 42:P0=0x55;P2=0xaa;delay_ms(400);break;  //WG
  case 43:P0=0x33;P2=0xcc;delay_ms(400);break;  //RW
  case 44:P0=0xcc;P2=0x33;delay_ms(400);break;  //GB
  }
  b++;
//  if(b==45)b=0;
}
void ZT_2(void)           //外收缩
{
 switch(c)
  {
  case 0:P0=0x00,P2=0x00;delay_ms(100);break;  //hold on  
  case 1:P0=0x11,P2=0x88;delay_ms(200);break;    //W
  case 2:P0=0x55,P2=0xaa;delay_ms(200);break;  //WG
  case 3:P0=0x77,P2=0xee;delay_ms(200);break;  //WRG
  case 4:P0=0xff,P2=0xff;delay_ms(200);break;  //WRGB
  case 5:P0=0x77,P2=0xee;delay_ms(200);break;  //WRG
  case 6:P0=0x55,P2=0xaa;delay_ms(200);break;  //WG
  case 7:P0=0x11,P2=0x88;delay_ms(200);break;  //W
  case 8:P0=0x00,P2=0x00;delay_ms(100);break;  //hold on
  
  }
  c++;
//  if(c==9)c=0;
}
void ZT_3(void)           //循环3次
{
 switch(d)
  {
  case 0:P0=0x00;P2=0x00;delay_ms(100);break;  //hold on
  case 1:P0=0x0f;P2=0x00;delay_ms(400);break;  //one
  case 2:P0=0xf0;P2=0x00;delay_ms(400);break;  //two
  case 3:P0=0x00;P2=0xf0;delay_ms(400);break;  //three
  case 4:P0=0x00;P2=0x0f;delay_ms(400);break;  //four
  case 5:P0=0x00;P2=0xf0;delay_ms(400);break;  //three
  case 6:P0=0xf0;P2=0x00;delay_ms(400);break;  //two
  case 7:P0=0x0f;P2=0x00;delay_ms(400);break;  //one
  case 8:P0=0x00;P2=0x00;delay_ms(100);break;  //hold on
  }
  d++;
//  if(d==9)c=0;
}

 

 

 

各位前辈,这是我的整个程序,在红色部分,我想循环三次怎么修改呢,能具体点吗,谢谢!

LED.rar

2.71 KB, 下载次数: 2

此帖出自单片机论坛
 
 
 

回复

93

帖子

0

TA的资源

纯净的硅(中级)

6
 
void ZT_4(void)           //外散花   
{
 switch(e)
  {
  case 0:P0=0x11;P2=0x88;delay_ms(200);break;    //W
  case 1:P0=0x55;P2=0xaa;delay_ms(200);break;  //WG
  case 2:P0=0x77;P2=0xee;delay_ms(200);break;  //WRG
  case 3:P0=0xff;P2=0xff;delay_ms(200);break;  //WRGB
  case 4:P0=0x00;P2=0x00;delay_ms(100);break;  //hold on
  }
  e++;
//  if(e==5)e=0;
}
void ZT_5(void)           //内散花
{
 switch(f)
  {
  case 0:P0=0xff;P2=0xff;delay_ms(200);break;  //WRGB
  case 1:P0=0x77;P2=0xee;delay_ms(200);break;  //WRG
  case 2:P0=0x55;P2=0xaa;delay_ms(200);break;  //WG
  case 3:P0=0x11;P2=0x88;delay_ms(200);break;    //W
  case 4:P0=0x00;P2=0x00;delay_ms(100);break;  //hold on
  }
  f++;
//  if(f==5)f=0;
}
void ZT_6(void)
{
 switch(g)
  {
  case 0:P0=0xf0;P2=0xf0;delay_ms(400);break;  //two three
  case 1:P0=0x0f;P2=0x0f;delay_ms(400);break;  //one four
  case 2:P0=0xff;P2=0xff;delay_ms(400);break;  //one two three four
  case 3:P0=0x0f;P2=0x0f;delay_ms(400);break;  //one four
  case 4:P0=0xf0;P2=0xf0;delay_ms(400);break;  //two three
  case 5:P0=0x00;P2=0x00;delay_ms(200);break;  //hold on
  case 6:P0=0xff;P2=0xff;delay_ms(400);break;  //WRGB
  case 7:P0=0x77;P2=0xee;delay_ms(400);break;  //WRG
  case 8:P0=0x55;P2=0xaa;delay_ms(400);break;  //WG
  case 9:P0=0x11;P2=0x88;delay_ms(400);break;  //W
  case 10:P0=0x00;P2=0x00;delay_ms(200);break; //hold on
  }
  g++;
//  if(d==11)e=0;
}
void ZT_7(void)
{
 switch(h)
  {
  case 0:P0=0x01;P2=0x00;delay_ms(400);break;  //1W
  case 1:P0=0x05;P2=0x00;delay_ms(400);break;  //1W-1G
  case 2:P0=0x07;P2=0x00;delay_ms(400);break;  //1W-1G-1R
  case 3:P0=0x0f;P2=0x00;delay_ms(400);break;  //1W-1G-1R-1B
  case 4:P0=0x1f;P2=0x00;delay_ms(400);break;  //1+2W
  case 5:P0=0x5f;P2=0x00;delay_ms(400);break;  //1+2W-2G
  case 6:P0=0x7f;P2=0x00;delay_ms(400);break;  //1+2W-2G-2R
  case 7:P0=0xff;P2=0x00;delay_ms(400);break;  //1WRGB+2W-2G-2R-2B
  case 8:P0=0xff;P2=0x80;delay_ms(400);break;  //1+2+3W
  case 9:P0=0xff;P2=0xa0;delay_ms(400);break;  //1+2+3W-3G
  case 10:P0=0xff;P2=0xe0;delay_ms(400);break; //1+2+3W-3G-3R
  case 11:P0=0xff;P2=0xf0;delay_ms(400);break; //1+2+3W-3G-3R-3B
  case 12:P0=0xff;P2=0xf8;delay_ms(400);break; //1+2+3+4W
  case 13:P0=0xff;P2=0xfa;delay_ms(400);break; //1+2+3+4W-4G
  case 14:P0=0xff;P2=0xfe;delay_ms(400);break; //1+2+3+4W-4G-4R
  case 15:P0=0xff;P2=0xff;delay_ms(400);break; //1+2+3+4W-4G-4R-4B
  }
  h++;
//  if(e==16)e=0;
}
void ZT_8(void)           //内收缩
{
 switch(k)
  {
  case 0:P0=0xff;P2=0xff;delay_ms(200);break;  //WRGB
  case 1:P0=0x77;P2=0xee;delay_ms(200);break;  //WRG
  case 2:P0=0x55;P2=0xaa;delay_ms(200);break;  //WG
  case 3:P0=0x11;P2=0x88;delay_ms(200);break;   //W
  case 4:P0=0x00;P2=0x00;delay_ms(100);break;  //hold on
  case 5:P0=0x11;P2=0x88;delay_ms(200);break;   //W
  case 6:P0=0x55;P2=0xaa;delay_ms(200);break;  //WG
  case 7:P0=0x77;P2=0xee;delay_ms(200);break;  //WRG
  case 8:P0=0xff;P2=0xff;delay_ms(200);break;  //WRGB
  case 9:P0=0x00;P2=0x00;delay_ms(100);break;  //hold on
  }  
  k++;
  
//  if(f==10)f=0;
}
void ZT_9(void)           //全色频闪
{
 switch(l)
  {
  case 0:P0=0x00,P2=0x00;delay_ms(200);break;
  case 1:P0=0xff,P2=0xff;delay_ms(200);break;
  }
  l++;
//  if(l==2)l=0;
}
void ZT_10(void)          //R频闪
{
 switch(n)
  {
  case 0:P0=0x22,P2=0x44;delay_ms(200);break;
  case 1:P0=0x00,P2=0x00;delay_ms(200);break;
  }
  n++;
//  if(n==2)n=0;
}
void ZT_11(void)          //G频闪
{
 switch(m)
  {
  case 0:P0=0x44,P2=0x22;delay_ms(200);break;
  case 1:P0=0x00,P2=0x00;delay_ms(200);break;
  }
  m++;
//  if(m==2)m=0;
}
void ZT_12(void)          //B频闪
{
 switch(o)
  {
  case 0:P0=0x88,P2=0x11;delay_ms(200);break;
  case 1:P0=0x00,P2=0x00;delay_ms(200);break;
  }
  o++;
//  if(o==2)o=0;
}
void ZT_13(void)          //W频闪
{
 switch(p)
  {
  case 0:P0=0x11,P2=0x88;delay_ms(200);break;
  case 1:P0=0x00,P2=0x00;delay_ms(200);break;
  }
  p++;
//  if(p==2)p=0;
}
void ZT_14(void)
{
 switch(q)
  {
  case 0:P0=0x01;P2=0x00;delay_ms(400);break;   //1W   
  case 1:P0=0x40;P2=0x00;delay_ms(400);break;   //2G
  case 2:P0=0x00;P2=0x40;delay_ms(400);break;   //3R
  case 3:P0=0x00;P2=0x01;delay_ms(400);break;   //4B
  case 4:P0=0x00;P2=0x08;delay_ms(500);break;   //4W
  case 5:P0=0x00;P2=0xa8;delay_ms(500);break;   //3WR+4W
  case 6:P0=0x70;P2=0xa8;delay_ms(500);break;   //2WRG+3WR+4W
  case 7:P0=0x7f;P2=0xa8;delay_ms(500);break;   //1WRGB+2WRG+3WR+4W
  case 8:P0=0x80;P2=0x10;delay_ms(500);break;   //2B-3B
  case 9:P0=0x08;P2=0x01;delay_ms(500);break;   //1B-4B
  case 10:P0=0x04;P2=0x02;delay_ms(500);break;  //1G-4G
  case 11:P0=0x40;P2=0x20;delay_ms(500);break;  //2G-3G
  case 12:P0=0x02;P2=0x04;delay_ms(500);break;  //1R-4R
  case 13:P0=0x20;P2=0x40;delay_ms(500);break;  //2R-3R
  case 14:P0=0x10;P2=0x80;delay_ms(500);break;  //2W-3W
  case 15:P0=0x01;P2=0x08;delay_ms(500);break;  //1w-4w
  }
  q++;
//  if(q==16)q=0;
}
void ZT_15(void)
{
 switch(r)
  {
  case 0:P0=0x18;P2=0x81;delay_ms(100);break;    
  case 1:P0=0x5a;P2=0xa5;delay_ms(100);break;
  case 2:P0=0x7e;P2=0xe7;delay_ms(100);break;
  case 3:P0=0xff;P2=0xff;delay_ms(100);break;
  case 4:P0=0x7e;P2=0xe7;delay_ms(100);break;
  case 5:P0=0x5a;P2=0xa5;delay_ms(100);break;
  case 6:P0=0x18;P2=0x81;delay_ms(100);break;
  case 7:P0=0x00;P2=0x00;delay_ms(100);break;
  }
  r++;
//  if(r==8)r=0;
}
void ZT_16(void)
{
 switch(s)
  {
  case 0:P0=0xf0;P2=0xf0;delay_ms(200);break;   //WRGB
  case 1:P0=0xe0;P2=0x70;delay_ms(200);break;   //RGB
  case 2:P0=0xa0;P2=0x50;delay_ms(200);break;   //RB
  case 3:P0=0x80;P2=0x10;delay_ms(200);break;   //B
  case 4:P0=0x00;P2=0x00;delay_ms(300);break;   //中间散花
  case 5:P0=0x80;P2=0x10;delay_ms(200);break;   //B
  case 6:P0=0xa0;P2=0x50;delay_ms(200);break;   //RB
  case 7:P0=0xe0;P2=0x70;delay_ms(200);break;   //RGB
  case 8:P0=0xf0;P2=0xf0;delay_ms(200);break;   //WRGB
  }
  s++;
//  if(s==9)s=0;
}

LED.rar

2.71 KB, 下载次数: 4

LED仿真图.rar

17.2 KB, 下载次数: 4

此帖出自单片机论坛
 
 
 

回复

93

帖子

0

TA的资源

纯净的硅(中级)

7
 

问题

各位,我刚学C语言程序,请多多指教,将来有什么需要我帮忙的,我会尽量帮忙的。希望能给我指点一下。在ZT_3和ZT_7循环3次的话怎么修改呢?请指教一下,小弟急需帮助,希望能花点时间帮忙看一下!程序和仿真图都附上了!

此帖出自单片机论坛
 
 
 

回复

93

帖子

0

TA的资源

纯净的硅(中级)

8
 

各位高手,急急!

各位大虾,我的程序要求是这样的,拨K4地址码时程序自走,拨地址码K5时程序进入声控(中断INT0),低电平触发。所以,我用函数调用来设计,子程序在主程序时,自走,也可以让子程序循环多次。当K4断开时,马上停止。当K5按下时,进入中断,子程序在中断时能实现单步走,一有低电平,就走一步。K5断开时,退出中断。

 

 

等回复,谢谢!czc568@163.com

 

QQ:306048732

此帖出自单片机论坛
 
 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表