找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1049|回复: 2
收起左侧

单片机程序没有错误,还显示target no creat?

[复制链接]
ID:668359 发表于 2021-1-9 15:16 | 显示全部楼层 |阅读模式
  1. #include<REG51.H>

  2. sbit play_up=P1^0;         
  3. sbit play_down=P1^1;   
  4. sbit pause=P1^2;     
  5. sbit speaker=P3^1;   

  6. unsigned char timer0h,timer0l,time;
  7. unsigned char music_num;      
  8. unsigned int num;
  9. signed int fre;

  10. unsigned char code FREQL[]={
  11.     0x42, 0xC1, 0x17, 0xB6, 0xD0, 0xD1, 0xB6,   
  12.     0x21, 0xE1, 0x8C, 0xD8, 0x68, 0xE9, 0x5B, 0x8F,
  13.     0xEE, 0x44, 0x6B, 0xB4, 0xF4, 0x2D,            
  14.     0x47, 0x77, 0xA2, 0xB6, 0xDA, 0xFA, 0x16};  
  15. unsigned char code FREQH[]={
  16.     0xF2, 0xF3, 0xF5, 0xF5, 0xF6, 0xF7, 0xF8,   
  17.     0xF9, 0xF9, 0xFA, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC,
  18.     0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFE,            
  19.     0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF};   
  20. unsigned code dm[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x0c};
  21. unsigned code sz[]={9,1,6,0,9,5,2,1};
  22. unsigned code wm[]={0x01,0x02,0x04,0x08,0x80,0x40,0x20,0x10};
  23. bit play_enable;                  
  24. void delay(unsigned char t);         
  25. void delayms(unsigned int t);           
  26. void song(void);                           
  27. void music_play(void);                 


  28. unsigned char code song1[]={
  29.      5,2,1, 3,2,1, 2,2,2, 2,2,4, 3,2,1, 1,2,1, 2,2,1, 3,2,4,
  30.          5,2,1, 3,2,1, 2,2,2, 2,2,2, 5,1,1, 3,2,1, 4,2,1, 3,2,4,
  31.          3,2,1, 3,2,1, 7,2,1, 3,2,1, 2,2,2, 1,2,1, 7,1,1, 1,2,1,
  32.          2,2,1, 3,2,1, 6,2,3, 6,1,1, 1,2,1, 3,2,1, 2,2,1, 6,1,1,
  33.          1,2,1, 7,1,1, 5,1,1, 6,1,6, 5,2,1, 3,2,1, 2,2,2, 2,2,1,
  34.          2,2,1, 3,2,1, 1,2,1, 2,2,1, 3,2,4, 5,2,1, 3,2,1, 2,2,2,
  35.          2,2,1, 2,2,1, 5,1,1, 3,2,1, 4,2,1, 3,2,4, 3,2,1, 3,2,1,
  36.          7,2,3, 3,2,1, 2,2,2, 1,2,1, 7,1,1, 1,2,1, 2,2,1, 3,2,1,
  37.          6,2,3, 6,1,1, 1,2,1, 3,2,1, 2,2,1, 6,1,1, 1,2,1, 7,1,2,
  38.          5,1,2, 6,1,6, 0,0,0 };


  39. unsigned char code song2[]={
  40.      5,1,1, 2,2,1, 3,2,2, 2,2,1, 3,2,1, 5,2,1, 6,2,1, 5,2,3, 1,2,1, 2,2,1,
  41.          3,2,1, 6,2,1, 5,2,1, 3,2,1, 5,2,3, 5,2,1, 6,2,1, 1,3,2, 6,2,1, 5,2,1,
  42.          3,2,1, 5,2,1, 3,2,2, 1,2,1, 2,2,1, 3,2,1, 1,2,1, 6,1,1, 3,2,1, 2,2,1,
  43.          5,1,1, 2,2,1, 3,2,2, 2,2,1, 3,2,1, 5,2,1, 6,2,1, 5,2,3, 1,2,1, 2,2,1,
  44.          3,2,1, 6,2,1, 5,2,3, 5,2,1, 6,2,1, 1,3,2, 6,2,1,
  45.          5,2,1, 3,2,1, 5,2,1, 3,2,2, 1,2,1, 6,1,1, 3,2,1, 2,2,1, 1,2,1, 6,1,1,
  46.          1,2,1, 2,2,1, 2,2,1, 1,2,4, 0,0,0 };


  47. unsigned char code song3[]={
  48.      5,1,1, 1,2,1, 2,2,1, 3,2,1, 2,2,1, 3,2,1, 4,2,1, 5,2,1, 5,2,1, 5,2,1,
  49.          4,2,1, 3,2,1, 2,2,3, 5,1,1, 1,2,1, 2,2,1, 3,2,1, 4,2,1, 5,2,1, 5,2,1,
  50.          5,2,1, 6,2,1, 5,2,2, 2,2,1, 3,2,1, 1,2,2, 1,2,1, 6,1,1, 2,2,1, 2,2,1,
  51.          3,2,1, 3,2,1, 1,2,1, 5,2,1, 1,2,1, 5,2,1, 1,2,1, 7,1,1, 1,2,1, 1,2,1, 6,1,1,
  52.          2,2,1, 2,2,1, 3,2,1, 3,2,1, 5,2,1, 5,2,1,
  53.          5,2,1, 6,2,1, 5,2,2, 2,2,1, 3,2,1, 1,2,2,  
  54.          5,1,1, 1,2,1, 2,1,2, 3,2,1, 2,2,1, 3,2,1, 4,2,1, 5,2,1, 5,2,1, 5,2,1,
  55.          4,2,1, 3,2,1, 2,2,3, 5,1,1, 1,2,1, 2,2,1, 3,2,1, 2,2,1, 3,2,1, 4,2,1,
  56.          5,2,1, 5,2,1, 5,2,2, 2,2,1, 3,2,1, 1,2,2, 1,2,1, 6,1,1, 2,2,1, 2,2,1,
  57.          3,2,1, 3,2,1, 1,2,2, 5,2,1, 1,2,1, 5,2,1, 5,2,1, 7,1,1, 1,2,1, 0,0,0 };


  58. unsigned char code song4[]={
  59.      6,2,3, 5,2,1, 3,2,2, 5,2,2, 1,3,2, 6,2,1,
  60.      5,2,1,6,2,4, 3,2,2, 5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1,6,1,1, 5,2,1,
  61.          3,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2, 5,2,1, 6,2,1, 3,2,2, 2,2,2,
  62.          1,2,4, 5,2,3, 3,2,1,2,2,1, 1,2,1, 6,1,1, 1,2,1, 5,1,6, 0,0,0};


  63. unsigned char code song5[]={
  64.      3,2,2, 3,2,1, 4,2,1, 3,2,2, 2,2,1, 1,2,1,  2,2,2, 5,2,2, 2,2,2, 2,2,3,
  65.          1,2,2, 1,2,1, 2,2,1, 1,2,2, 7,1,1, 6,1,1, 7,1,2, 3,2,2, 7,1,2, 7,1,3,
  66.          6,1,2, 2,2,1, 3,2,1, 2,2,1, 1,2,1, 6,1,2, 5,1,2, 2,2,1, 3,2,1, 2,2,1,
  67.          1,2,1, 6,1,2, 6,1,2, 2,2,1, 3,2,1, 2,2,1, 1,2,1, 6,1,1, 7,1,1, 1,2,6, 0,0,0 };


  68. unsigned char code song6[]={
  69.      3,1,2, 3,1,1, 3,1,1, 6,0,1, 6,0,1, 1,1,2,
  70.      6,0,1, 5,0,1, 6,0,4, 6,0,2, 6,0,1 ,6,0,1, 6,0,2, 6,0,1, 1,1,1,
  71.      2,1,2, 2,1,1, 3,1,1, 2,1,4, 3,1,1, 3,1,1, 3,1,1, 2,1,1, 4,1,2,
  72.      4,1,2, 3,1,2, 2,1,1, 1,1,1, 2,1,4, 7,0,1, 7,0,1, 7,0,1, 6,0,1,
  73.      5,0,1, 5,0,1, 6,0,1, 7,0,1, 7,0,1, 6,0,1, 5,0,1, 6,0,4, 6,1,2,
  74.      3,1,1, 6,1,1, 7,1,1, 6,1,1, 5,1,1, 5,1,2, 5,1,1, 2,1,1, 5,1,1,
  75.      6,1,1, 5,1,1, 4,1,1, 4,1,2, 4,1,1, 3,1,1, 2,1,2, 1,1,1, 2,1,1,
  76.      3,1,1, 2,1,1, 1,1,1, 2,1,1, 3,1,4, 6,1,2, 3,1,1, 6,1,1, 7,1,1,
  77.          6,1,1, 5,1,1, 5,1,2, 2,1,1, 5,1,1, 6,1,1, 5,1,1, 4,1,1, 0,0,0};     


  78. unsigned char code song7[]={
  79.      5,1,2, 3,1,3, 5,1,1, 1,2,3, 6,1,2, 1,2,2,
  80.      5,1,4, 5,1,2, 1,1,1, 2,1,1, 3,1,2, 2,1,1, 1,1,1, 2,1,4, 5,1,2,
  81.          3,1,1, 5,1,1, 1,2,2, 7,1,1, 6,1,2, 1,2,2, 5,1,4, 5,1,2, 2,1,1,
  82.          3,1,1, 4,1,2, 7,0,1, 1,1,4, 6,1,2, 1,2,2, 1,2,4, 7,1,2, 6,1,1,
  83.          7,1,1, 1,2,4, 6,1,1, 7,1,1, 1,2,1, 6,1,1, 6,1,1, 5,1,1, 3,1,1,
  84.          1,1,1, 2,1,8, 5,1,2, 3,1,1, 5,1,1, 1,2,2, 7,1,1, 6,1,2, 1,2,2,
  85.          5,1,4, 5,1,2, 2,1,1, 3,1,1, 4,1,2, 7,0,2, 1,1,4, 0,0,0};


  86. unsigned char code song8[]={
  87.      5,1,1, 6,1,1, 1,2,1, 6,1,2, 6,1,1, 5,1,1, 6,1,1, 5,1,1, 3,1,1, 5,1,5,
  88.          5,1,1, 6,1,1, 1,2,1, 6,1,2, 6,1,1, 5,1,1, 6,1,1, 5,1,1, 6,1,1, 1,1,5,
  89.          1,1,1, 2,1,1, 3,1,1, 2,1,1, 2,1,1, 2,1,1, 1,1,1, 2,1,1, 1,1,1, 6,1,1,
  90.          3,1,2, 2,1,3, 5,1,1, 6,1,1, 1,2,1, 6,1,2, 6,1,1, 5,1,1, 6,1,1, 5,1,1,
  91.          6,1,1, 1,1,5, 1,1,1, 2,1,1, 3,1,1, 4,1,2, 4,1,1, 5,1,1, 6,1,1, 6,1,1,
  92.          5,1,1, 6,1,2, 1,2,1, 6,1,3, 1,2,1, 6,1,1, 5,1,1, 5,1,4, 1,1,1, 6,1,1,
  93.          5,1,5, 5,1,1, 6,1,1, 1,2,1, 3,1,1, 2,1,1, 3,1,1, 1,1,6, 0,0,0};




  94. void KEY()
  95. {
  96.         if(!pause)               
  97.                 {
  98.                 delayms(5);
  99.                 if(!pause)
  100.                 {
  101.                         TR0=0;
  102.                         speaker=1;
  103.                         if(music_num==0)   
  104.                         {
  105.                                 music_num=1;   
  106.                                 num=0;               
  107.                                 play_enable=1;        
  108.                         }
  109.                         else
  110.                         {
  111.                                 play_enable=~play_enable;
  112.                             speaker=1;
  113.                         }
  114.                         while(!pause)         
  115.                         {
  116.                         if(play_enable==0){}               

  117.                   }
  118.         }

  119.                 if((!play_up)&&(music_num!=0))
  120.                 {
  121.                 delayms(5);
  122.                 if((!play_up)&&(music_num!=0))
  123.                 {
  124.                    TR0=0;
  125.                    speaker=1;
  126.                         music_num-=1;
  127.                         if(music_num<=0)
  128.                         music_num=8;
  129.                         num=0;                 

  130.                         delayms(500);
  131.                 }        
  132.                 }

  133.                 if((!play_down)&&(music_num!=0))
  134.                 {
  135.                 delayms(5);
  136.                 if((!play_down)&&(music_num!=0))
  137.                 {   
  138.                         TR0=0;
  139.                         speaker=1;
  140.                         music_num+=1;
  141.                         if(music_num>=9)
  142.                         music_num=1;
  143.                         num=0;                 

  144.                         delayms(500);
  145.                 }
  146.                 }
  147. }
  148. }
  149. void main(void)
  150. {
  151.         TMOD=0x11;
  152.         ET0=1;  
  153.         EA=1;   
  154.         while(1)
  155.         {
  156.                 music_play();        
  157.                 KEY();
  158.         }
  159. }

  160. void delayms(unsigned int t)           
  161. {
  162.         unsigned int i,j;
  163.         for(i=0;i<t;i++)
  164.         {
  165.                 for(j=0;j<123;j++)
  166.                         ;
  167.         }
  168. }

  169. void delay(unsigned char t)            
  170. {
  171.         unsigned char t1;
  172.         unsigned long t2;
  173.         for(t1=0;t1<t;t1++)               
  174.         {
  175.             for(t2=0;t2<6500;t2++)
  176.         {
  177.                 KEY();
  178.         }
  179.         }
  180.         TR0=0;                             
  181. }

  182. void timer0(void) interrupt 1
  183. {speaker=!speaker;
  184.         TH0=timer0h;         
  185.         TL0=timer0l;
  186. }

  187. void song(void)         
  188. {
  189.         TH0=timer0h;   
  190.         TL0=timer0l;
  191.         TR0=1;                    
  192.         delay(time);   
  193. }

  194. void music_play(void)
  195. { int i;
  196.         i=0;
  197.         
  198.         for(i=0;i<8;i++)
  199.                 {  P2=0x00;
  200.              P0=0x00;
  201.                         if(play_enable==1)
  202.             {
  203.                                 P0=dm[music_num];
  204.                     P2=0x99;
  205.              break;}
  206.            else if(play_enable==0)
  207.             {
  208.                          P0=dm[sz[i]];
  209.                    P2=wm[i];
  210.                    delayms(5);
  211.                    P2=0x00;
  212.                    };
  213.         }
  214.         if((music_num==1)&&(play_enable==1))
  215.         {
  216.                 fre=song1[num]+7*song1[num+1]-1;
  217.                 timer0h=FREQH[fre];                    
  218.             timer0l=FREQL[fre];
  219.             time=song1[num+2];              
  220.             num+=3;
  221.                 if(fre<0)               
  222.                 {
  223.                         num=0;            
  224.                         music_num=2;
  225.             }
  226.                 song();               
  227.         }

  228.         if((music_num==2)&&(play_enable==1))
  229.         {  
  230.                 fre=song2[num]+7*song2[num+1]-1;
  231.                 timer0h=FREQH[fre];
  232.             timer0l=FREQL[fre];
  233.             time=song2[num+2];
  234.             num+=3;
  235.                 if(fre<0)
  236.                 {
  237.                         num=0;
  238.                         music_num=3;
  239.             }
  240.                 song();               
  241.         }

  242.                 if((music_num==3)&&(play_enable==1))
  243.         {  
  244.                 fre=song3[num]+7*song3[num+1]-1;
  245.                 timer0h=FREQH[fre];
  246.             timer0l=FREQL[fre];
  247.             time=song3[num+2];
  248.             num+=3;
  249.                 if(fre<0)
  250.                 {
  251.                         num=0;
  252.                         music_num=4;
  253.             }
  254.                 song();               
  255.         }

  256.         if((music_num==4)&&(play_enable==1))
  257.         {
  258.                 fre=song4[num]+7*song4[num+1]-1;
  259.                 timer0h=FREQH[fre];
  260.             timer0l=FREQL[fre];
  261.             time=song4[num+2];
  262.             num+=3;
  263.                 if(fre<0)
  264.                 {
  265.                         num=0;
  266.                         music_num=5;
  267.             }
  268.                 song();               
  269.         }

  270.         if((music_num==5)&&(play_enable==1))
  271.         {
  272.                 fre=song5[num]+7*song5[num+1]-1;
  273.                 timer0h=FREQH[fre];
  274.             timer0l=FREQL[fre];
  275.             time=song5[num+2];
  276.             num+=3;
  277.                 if(fre<0)
  278.                 {
  279.                         num=0;
  280.                         music_num=6;
  281.             }
  282.                 song();               
  283.         }

  284.         if((music_num==6)&&(play_enable==1))
  285.         {
  286.                 fre=song6[num]+7*song6[num+1]-1;
  287.                 timer0h=FREQH[fre];
  288.             timer0l=FREQL[fre];
  289.             time=song6[num+2];
  290.             num+=3;
  291.                 if(fre<0)
  292.                 {
  293.                         num=0;
  294.                         music_num=7;
  295.             }
  296.                 song();               
  297.         }

  298. if((music_num==7)&&(play_enable==1))
  299.         {
  300.                 fre=song7[num]+7*song7[num+1]-1;
  301.                 timer0h=FREQH[fre];
  302.             timer0l=FREQL[fre];
  303.             time=song7[num+2];
  304.             num+=3;
  305.                 if(fre<0)
  306.                 {
  307.                         num=0;
  308.                         music_num=8;
  309.             }
  310.                 song();               
  311.         }

  312. if((music_num==8)&&(play_enable==1))
  313.         {
  314.                 fre=song8[num]+7*song8[num+1]-1;
  315.                 timer0h=FREQH[fre];
  316.             timer0l=FREQL[fre];
  317.             time=song8[num+2];
  318.             num+=3;
  319.                 if(fre<0)
  320.                 {
  321.                         num=0;
  322.                         music_num=1;
  323.             }
  324.                 song();               
  325.         }

  326. }
复制代码
回复

使用道具 举报

ID:91697 发表于 2021-1-9 16:11 | 显示全部楼层
目标未创建?你换编译器试试?
回复

使用道具 举报

ID:517466 发表于 2021-1-9 18:51 | 显示全部楼层
楼主要确认两件事:
1、你的工程是否选择了MPU的型号?
2、你的这个工程是否包含了c文件(就是你罗列的那些代码所在的文件)
我试着建立个工程,做个C文件,粘贴你提供的代码。然后把文件添加到工程里。变异没有问题,生成hex文件了。没有任何错误和警告信息。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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