找回密码
 立即注册

QQ登录

只需一步,快速开始

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

新手求助,为什么会出现这种错误啊,找了半天原因都没找到

[复制链接]
跳转到指定楼层
楼主
自己尝试写的旋转led的程序

#include <STC15F2K60S2.H>
#define uint unsigned int
#define uchar unsigned char
void delay(int ms)
{    uint i,j;
    for(i=0;i<ms;i++)
    {
      for(j=0;j<5;j++);
      }
    //a??????????
uchar num_a[]={0x24,0x24,0x25,0x7F,0xC4,0x44,0x00,0x7C,0x44,0x44,0x44,0x44,0x44,0x7C,0x00,0x00,/*????????*/
    0x00,0x00,0x3F,0x20,0x20,0x20,0x28,0xA8,0x6A,0x29,0x2A,0x2C,0x28,0x20,0x20,0x00,/*????????*/
    0x04,0x0C,0x35,0xC6,0x04,0x18,0x10,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0x10,0x00,/*????????*/
    0x08,0x08,0x0B,0xFF,0x09,0x08,0x02,0x0C,0xF0,0x13,0x10,0x10,0x10,0x1F,0x00,0x00,/*?????????*/
    0x02,0x02,0x42,0x33,0x00,0x02,0x05,0x79,0x41,0x41,0x41,0x79,0x05,0x04,0x04,0x00, /*????????*/
    0x02,0x02,0x42,0x33,0x00,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x02,0x00, /*????????*/
     };
     //b??????°???
uchar num_b[]={0x10,0x60,0x80,0xFF,0x80,0x60,0x02,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x82,0x00,/*????°???*/
    0x02,0x0C,0xF0,0x00,0x80,0x80,0x80,0x82,0x81,0xFE,0x80,0x80,0x80,0xA0,0xC0,0x00,/*????°???*/
    0x44,0xE6,0x44,0x48,0x48,0x48,0x00,0x7F,0x42,0x42,0x42,0x42,0x42,0x7F,0x00,0x00,/*????°???*/
    0x20,0xC0,0x00,0xFF,0x00,0xC0,0x00,0x30,0xD0,0x10,0x52,0x39,0x02,0xFC,0x00,0x00, /*?????°???*/
    0x00,0x00,0x00,0xFC,0x09,0x11,0x02,0xC2,0x34,0x08,0x14,0x62,0x82,0x01,0x01,0x00, /*????°???*/
    0x00,0x00,0x00,0xFE,0x04,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,  /*????°???*/
     };
uchar num_c[]={0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0x0F,0x00,0x00,0x00,/*?е??????*/
      0x00,0x3F,0x04,0x24,0x15,0xFF,0x15,0x24,0x00,0x3F,0x22,0x22,0x23,0x42,0x02,0x00,/*????????*/
      0x00,0x00,0x44,0x4C,0x54,0x65,0x45,0x46,0x84,0x88,0x90,0x81,0x80,0x00,0x00,0x00,/*????????*/
      0x04,0x0C,0x35,0xC6,0x0C,0x00,0x11,0x13,0x15,0x99,0x71,0x11,0x15,0x13,0x11,0x00,/*????????*/
      };
uchar num_d[]={0x00,0x00,0xF0,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0xF0,0x00,0x00,0x00,/*?е??°???*/
               0x00,0xFC,0x44,0x84,0x04,0xF4,0x04,0xC5,0x06,0xF8,0x00,0x00,0xFF,0x00,0x00,0x00,/*????°???*/
      0x00,0x42,0x44,0xC8,0xD0,0x42,0x41,0x7E,0x40,0x40,0x50,0x48,0xC4,0x62,0x00,0x00,/*????°???*/
      0x44,0xE6,0x44,0x48,0x48,0x01,0x02,0x0C,0xF0,0x00,0x00,0xFC,0x02,0x02,0x8E,0x00,/*????°???*/
      
      };
uint i=0;
uint k=0;
void zhongduan() interrupt 0 //?ж???????????????
   {
   display();
   }
void display()
{  
k++;
if(k<200)
display_1();
else if(k<400)
display_2();
else if(k<600)
display_3();
}
void display_1()
{
  P0=0x00;
  P1=0x00;
  p2=0x00;
  P4^5=0;
} //???
void display_2()
{
   uint m;
   for(m=0;m<192;m++)
   {
       P0=~num_a[16*(m/16)+16-(m%16)];
    p1=~num_b[16*(m/16)+16-(m%16)];
    p2=oxff;
       P4^5=1;
    delay(30);
   }
}  //???????????
void display_3()
{  uint l;
     for(l=0;l<192;l++)
   {
       P0=~num_c[16*((l+i)/16)+16-((l+i)%16)%192];
    p1=~num_d[16*((l+i)/16)+16-((l+i)%16)%192];
    p2=oxff;
       P4^5=1;
    delay(30);
   }
   i++;
}
void main()
{
  P0=0xff;
  P1=0xff;
  P2=0xff;
  P4^5=1;
EA=1;//允许中断
  IT0=1;//int0中断
  EX0=1;
}






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

使用道具 举报

沙发
ID:525872 发表于 2019-5-4 12:12 | 只看该作者
main里最后加一个死循环while(1);
回复

使用道具 举报

板凳
ID:525872 发表于 2019-5-4 12:14 | 只看该作者
还有P是大写,你很多dispplay有很多小写
回复

使用道具 举报

地板
ID:525872 发表于 2019-5-4 12:23 | 只看该作者
#include <STC15F2K60S2.H>
#define uint unsigned int
#define uchar unsigned char
void delay(int ms)
{    uint i,j;
    for(i=0;i<ms;i++)
    {
      for(j=0;j<5;j++);
      }
    //a??????????
uchar num_a[]={0x24,0x24,0x25,0x7F,0xC4,0x44,0x00,0x7C,0x44,0x44,0x44,0x44,0x44,0x7C,0x00,0x00,/*????????*/
    0x00,0x00,0x3F,0x20,0x20,0x20,0x28,0xA8,0x6A,0x29,0x2A,0x2C,0x28,0x20,0x20,0x00,/*????????*/
    0x04,0x0C,0x35,0xC6,0x04,0x18,0x10,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0x10,0x00,/*????????*/
    0x08,0x08,0x0B,0xFF,0x09,0x08,0x02,0x0C,0xF0,0x13,0x10,0x10,0x10,0x1F,0x00,0x00,/*?????????*/
    0x02,0x02,0x42,0x33,0x00,0x02,0x05,0x79,0x41,0x41,0x41,0x79,0x05,0x04,0x04,0x00, /*????????*/
    0x02,0x02,0x42,0x33,0x00,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x02,0x00, /*????????*/
     };
     //b??????°???
uchar num_b[]={0x10,0x60,0x80,0xFF,0x80,0x60,0x02,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x82,0x00,/*????°???*/
    0x02,0x0C,0xF0,0x00,0x80,0x80,0x80,0x82,0x81,0xFE,0x80,0x80,0x80,0xA0,0xC0,0x00,/*????°???*/
    0x44,0xE6,0x44,0x48,0x48,0x48,0x00,0x7F,0x42,0x42,0x42,0x42,0x42,0x7F,0x00,0x00,/*????°???*/
    0x20,0xC0,0x00,0xFF,0x00,0xC0,0x00,0x30,0xD0,0x10,0x52,0x39,0x02,0xFC,0x00,0x00, /*?????°???*/
    0x00,0x00,0x00,0xFC,0x09,0x11,0x02,0xC2,0x34,0x08,0x14,0x62,0x82,0x01,0x01,0x00, /*????°???*/
    0x00,0x00,0x00,0xFE,0x04,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,  /*????°???*/
     };
uchar num_c[]={0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0x0F,0x00,0x00,0x00,/*?е??????*/
      0x00,0x3F,0x04,0x24,0x15,0xFF,0x15,0x24,0x00,0x3F,0x22,0x22,0x23,0x42,0x02,0x00,/*????????*/
      0x00,0x00,0x44,0x4C,0x54,0x65,0x45,0x46,0x84,0x88,0x90,0x81,0x80,0x00,0x00,0x00,/*????????*/
      0x04,0x0C,0x35,0xC6,0x0C,0x00,0x11,0x13,0x15,0x99,0x71,0x11,0x15,0x13,0x11,0x00,/*????????*/
      };
uchar num_d[]={0x00,0x00,0xF0,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0xF0,0x00,0x00,0x00,/*?е??°???*/
               0x00,0xFC,0x44,0x84,0x04,0xF4,0x04,0xC5,0x06,0xF8,0x00,0x00,0xFF,0x00,0x00,0x00,/*????°???*/
      0x00,0x42,0x44,0xC8,0xD0,0x42,0x41,0x7E,0x40,0x40,0x50,0x48,0xC4,0x62,0x00,0x00,/*????°???*/
      0x44,0xE6,0x44,0x48,0x48,0x01,0x02,0x0C,0xF0,0x00,0x00,0xFC,0x02,0x02,0x8E,0x00,/*????°???*/
      
      };
uint i=0;
uint k=0;
void zhongduan() interrupt 0 //?ж???????????????
   {
   display();
   }
void display()
{  
k++;
if(k<200)
display_1();
else if(k<400)
display_2();
else if(k<600)
display_3();
}
void display_1()
{
  P0=0x00;
  P1=0x00;
  P2=0x00;
  P4^5=0;
} //???
void display_2()
{
   uint m;
   for(m=0;m<192;m++)
   {
       P0=~num_a[16*(m/16)+16-(m%16)];
    P1=~num_b[16*(m/16)+16-(m%16)];
    P2=oxff;
       P4^5=1;
    delay(30);
   }
}  //???????????
void display_3()
{  uint l;
     for(l=0;l<192;l++)
   {
       P0=~num_c[16*((l+i)/16)+16-((l+i)%16)%192];
    P1=~num_d[16*((l+i)/16)+16-((l+i)%16)%192];
    P2=oxff;
       P4^5=1;
    delay(30);
   }
   i++;
}
void main()
{
  P0=0xff;
  P1=0xff;
  P2=0xff;
  P4^5=1;
EA=1;//允许中断
  IT0=1;//int0中断
  EX0=1;
  while(1);
}
//你这块芯片是电平触发中断,对这个芯片没有查询过,51系列是下降沿触发外部中断

评分

参与人数 1黑币 +70 收起 理由
admin + 70 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

5#
ID:155507 发表于 2019-5-4 15:03 | 只看该作者
给你改了,对比一下就知道哪里错了。

  1. #include <STC15F2K60S2.H>
  2. #define uint unsigned int
  3. #define uchar unsigned char
  4. sbit p45=P4^5;

  5. //a??????????
  6. uchar num_a[]={0x24,0x24,0x25,0x7F,0xC4,0x44,0x00,0x7C,0x44,0x44,0x44,0x44,0x44,0x7C,0x00,0x00,/*????????*/
  7.         0x00,0x00,0x3F,0x20,0x20,0x20,0x28,0xA8,0x6A,0x29,0x2A,0x2C,0x28,0x20,0x20,0x00,/*????????*/
  8.         0x04,0x0C,0x35,0xC6,0x04,0x18,0x10,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0x10,0x00,/*????????*/
  9.         0x08,0x08,0x0B,0xFF,0x09,0x08,0x02,0x0C,0xF0,0x13,0x10,0x10,0x10,0x1F,0x00,0x00,/*?????????*/
  10.         0x02,0x02,0x42,0x33,0x00,0x02,0x05,0x79,0x41,0x41,0x41,0x79,0x05,0x04,0x04,0x00, /*????????*/
  11.         0x02,0x02,0x42,0x33,0x00,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x02,0x00, /*????????*/
  12. };
  13. //b??????°???
  14. uchar num_b[]={0x10,0x60,0x80,0xFF,0x80,0x60,0x02,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x82,0x00,/*????°???*/
  15.         0x02,0x0C,0xF0,0x00,0x80,0x80,0x80,0x82,0x81,0xFE,0x80,0x80,0x80,0xA0,0xC0,0x00,/*????°???*/
  16.         0x44,0xE6,0x44,0x48,0x48,0x48,0x00,0x7F,0x42,0x42,0x42,0x42,0x42,0x7F,0x00,0x00,/*????°???*/
  17.         0x20,0xC0,0x00,0xFF,0x00,0xC0,0x00,0x30,0xD0,0x10,0x52,0x39,0x02,0xFC,0x00,0x00, /*?????°???*/
  18.         0x00,0x00,0x00,0xFC,0x09,0x11,0x02,0xC2,0x34,0x08,0x14,0x62,0x82,0x01,0x01,0x00, /*????°???*/
  19.         0x00,0x00,0x00,0xFE,0x04,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,  /*????°???*/
  20. };
  21. uchar num_c[]={0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0x0F,0x00,0x00,0x00,/*?е??????*/
  22.         0x00,0x3F,0x04,0x24,0x15,0xFF,0x15,0x24,0x00,0x3F,0x22,0x22,0x23,0x42,0x02,0x00,/*????????*/
  23.         0x00,0x00,0x44,0x4C,0x54,0x65,0x45,0x46,0x84,0x88,0x90,0x81,0x80,0x00,0x00,0x00,/*????????*/
  24.         0x04,0x0C,0x35,0xC6,0x0C,0x00,0x11,0x13,0x15,0x99,0x71,0x11,0x15,0x13,0x11,0x00,/*????????*/
  25. };
  26. uchar num_d[]={0x00,0x00,0xF0,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0xF0,0x00,0x00,0x00,/*?е??°???*/
  27.         0x00,0xFC,0x44,0x84,0x04,0xF4,0x04,0xC5,0x06,0xF8,0x00,0x00,0xFF,0x00,0x00,0x00,/*????°???*/
  28.         0x00,0x42,0x44,0xC8,0xD0,0x42,0x41,0x7E,0x40,0x40,0x50,0x48,0xC4,0x62,0x00,0x00,/*????°???*/
  29.         0x44,0xE6,0x44,0x48,0x48,0x01,0x02,0x0C,0xF0,0x00,0x00,0xFC,0x02,0x02,0x8E,0x00,/*????°???*/
  30.        
  31. };
  32. uint i=0;
  33. uint k=0;
  34. void delay(int ms)
  35. {    uint i,j;
  36.         for(i=0;i<ms;i++)
  37.         {
  38.                 for(j=0;j<5;j++);
  39.         }
  40. }
  41. void zhongduan() interrupt 0 //?ж???????????????
  42. {
  43.         display();
  44. }
  45. void display()
  46. {  
  47.         k++;
  48.         if(k<200)
  49.         display_1();
  50.         else if(k<400)
  51.         display_2();
  52.         else if(k<600)
  53.         display_3();
  54. }
  55. void display_1()
  56. {
  57.         P0=0x00;
  58.         P1=0x00;
  59.         P2=0x00;  //p2=0x00;
  60.         p45=0; //P4^5=0;  不允许
  61. } //???
  62. void display_2()
  63. {
  64.         uint m;
  65.         for(m=0;m<192;m++)
  66.         {
  67.                 P0=~num_a[16*(m/16)+16-(m%16)];
  68.                 P1=~num_b[16*(m/16)+16-(m%16)]; //p1=~num_b[16*(m/16)+16-(m%16)];
  69.                 P2=0xff; //p2=oxff;
  70.                 p45=1; //P4^5=1;  不允许
  71.                 delay(30);
  72.         }
  73. }  //???????????
  74. void display_3()
  75. {  uint l;
  76.         for(l=0;l<192;l++)
  77.         {
  78.                 P0=~num_c[16*((l+i)/16)+16-((l+i)%16)%192];
  79.                 P1=~num_d[16*((l+i)/16)+16-((l+i)%16)%192];
  80.                 P2=0xff; //p2=oxff;
  81.                 p45=1; //P4^5=1;  不允许
  82.                 delay(30);
  83.         }
  84.         i++;
  85. }
  86. void main()
  87. {
  88.         P0=0xff;
  89.         P1=0xff;
  90.         P2=0xff;
  91.         p45=1; //P4^5=1; 不允许
  92.         EA=1;//允许中断
  93.         IT0=1;//int0中断
  94.         EX0=1;
  95.     while(1); //main里最后加一个死循环while(1);
  96. }

复制代码
回复

使用道具 举报

6#
ID:170318 发表于 2019-5-4 20:14 | 只看该作者
数组最后一个逗号去掉(大括号前面的),这个子程序void delay(int ms)
{    uint i,j;
     for(i=0;i<ms;i++)
     {
       for(j=0;j<5;j++);
       }

最后少个大括号
回复

使用道具 举报

7#
ID:170318 发表于 2019-5-4 20:16 | 只看该作者
修改过的程序也没有完全改正
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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