本帖最后由 15236966302 于 2021-10-22 16:33 編輯
這是編輯器提示的
task3.c(14): error C141: syntax error near '}'
task3.c(40): error C202: 'P2_0': undefined identifier
task3.c(47): error C202: 'P2_0': undefined identifier
這是單片機源代碼
- #include<reg51.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define fm P2_0
- uint code yj[]={64580,64684,64777,64820,64898,64968,65030,64260,65058}; //音階初值:1,2,3,4,5,6,7
- uchar code yp[]={0x14,0x24,0x24,0x14,0x14,0x24,0x34,0x14,0x34,0x44,0x58,0x34,0x44,0x58,0x52,0x62,0x52,0x42,0x34,0x14,0x52,0x62,0x52,0x42,0x34,0x14,0x14,0x84,0x16,0x02,0x14,0x84,0x16,0x02,0x00}; //兩只老虎
- uchar yf,jp;
- void delay(uint z) //1/4延時時間,250ms
- {
- uchar i,j;
- while(z--)
- for(j=0;j<250;j++)
- for(i=0;i<120;i++)
- }
- void sing(uint i)
- {
- yf=yp[i]/16; //高四位為音符
- jp=yp[i]%16; //低四位為節拍
- }
- void main()
- {
- uint i;
- IE=0x82;
- TMOD=0x01;
- while(1)
- {
- for(i=0;yp[i]!=0;i++)
- {
- sing(i);
- if(yf==0)TR0=0;
- else
- {
- TH0=yj[yf-1]/256;
- TL0=yj[yf-1]%256;
- TR0=1;
- }
- delay(jp);
- }
- TR0=0;
- fm = 0;
- }
- }
- void time0()interrupt 1
- {
- TH0=yj[yf-1]/256;
- TL0=yj[yf-1]%256;
- fm =-fm;
- }
復制代碼
這是圖片
|