本帖最后由 进击的蜗牛 于 2017-12-18 19:49 编辑
下面是我的程序以及错误求大师们帮我改一下,最后是跑马灯加音乐就行,我用的是AT89C52
- #include "reg52.h"
- sbit key1=P0^0;
- sbit key2=P0^1;
- sbit key3=P0^2;
- sbit key4=P0^3;
- sbit key5=P0^4;
- sbit key6=P0^5;
- sbit key7=P0^6;
- sbit key8=P0^7;
- #include <INTRINS.H>
- sbit Beep = P1^2;
- unsigned char n=0; //n为节拍常数变量
- unsigned char code music_tab[] ={
- 0x18, 0x30, 0x1C , 0x10, //格式为: 频率常数, 节拍常数, 频率常数, 节拍常数,
- 0x20, 0x40, 0x1C , 0x10,
- 0x18, 0x10, 0x20 , 0x10,
- 0x1C, 0x10, 0x18 , 0x40,
- 0x1C, 0x20, 0x20 , 0x20,
- 0x1C, 0x20, 0x18 , 0x20,
- 0x20, 0x80, 0xFF , 0x20,
- 0x30, 0x1C, 0x10 , 0x18,
- 0x20, 0x15, 0x20 , 0x1C,
- 0x20, 0x20, 0x20 , 0x26,
- 0x40, 0x20, 0x20 , 0x2B,
- 0x20, 0x26, 0x20 , 0x20,
- 0x20, 0x30, 0x80 , 0xFF,
- 0x20, 0x20, 0x1C , 0x10,
- 0x18, 0x10, 0x20 , 0x20,
- 0x26, 0x20, 0x2B , 0x20,
- 0x30, 0x20, 0x2B , 0x40,
- 0x20, 0x20, 0x1C , 0x10,
- 0x18, 0x10, 0x20 , 0x20,
- 0x26, 0x20, 0x2B , 0x20,
- 0x30, 0x20, 0x2B , 0x40,
- 0x20, 0x30, 0x1C , 0x10,
- 0x18, 0x20, 0x15 , 0x20,
- 0x1C, 0x20, 0x20 , 0x20,
- 0x26, 0x40, 0x20 , 0x20,
- 0x2B, 0x20, 0x26 , 0x20,
- 0x20, 0x20, 0x30 , 0x80,
- 0x20, 0x30, 0x1C , 0x10,
- 0x20, 0x10, 0x1C , 0x10,
- 0x20, 0x20, 0x26 , 0x20,
- 0x2B, 0x20, 0x30 , 0x20,
- 0x2B, 0x40, 0x20 , 0x15,
- 0x1F, 0x05, 0x20 , 0x10,
- 0x1C, 0x10, 0x20 , 0x20,
- 0x26, 0x20, 0x2B , 0x20,
- 0x30, 0x20, 0x2B , 0x40,
- 0x20, 0x30, 0x1C , 0x10,
- 0x18, 0x20, 0x15 , 0x20,
- 0x1C, 0x20, 0x20 , 0x20,
- 0x26, 0x40, 0x20 , 0x20,
- 0x2B, 0x20, 0x26 , 0x20,
- 0x20, 0x20, 0x30 , 0x30,
- 0x20, 0x30, 0x1C , 0x10,
- 0x18, 0x40, 0x1C , 0x20,
- 0x20, 0x20, 0x26 , 0x40,
- 0x13, 0x60, 0x18 , 0x20,
- 0x15, 0x40, 0x13 , 0x40,
- 0x18, 0x80, 0x00
- };
- void int0() interrupt 1
- { TH0=0xd8;
- TL0=0xef;
- n--;
- }
- void delay (unsigned char m) //控制频率延时
- {
- unsigned i=3*m;
- while(--i);
- }
- void delayms(unsigned char a) //豪秒延时子程序
- {
- while(--a);
- }
- void sound()
- { unsigned char p,m; //m为频率常数变量
- unsigned char i=0;
- TMOD&=0x0f;
- TMOD|=0x01;
- TH0=0xd8;TL0=0xef;
- IE=0x82;
- play:
- while(1)
- {
- a: p=music_tab[i];
- if(p==0x00) { i=0, delayms(1000); goto play;} //
- else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;}
- else {m=music_tab[i++], n=music_tab[i++];} /
- TR0=1; //开定时器1
- while(n!=0) Beep=~Beep,delay(m); /
- TR0=0; //关定时器1
- }
- }
- int num=0;
- int flag_hz=10;
- void main()
- {
- TMOD=0X01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- TR0=1;
- P2=0xff;
- while(1)
- {
- sound();
- if(key1==0)
- {
- flag_hz=5;
-
- }
- if(key2==0)
- {
- flag_hz=25;
- }
- if(key3==0)
- {
- flag_hz=45;
- }
- if(key4==0)
- {
-
- }
- if(key5==0)
- {
- P3=0X03;
-
- P2=0X03;
- }
- if(key6==0)
- {
- P3=0X33;
- P2=0X33;
- }
- if(key7==0)
- {
- P3=0XAA;
- P2=0XAA;
- }
- if(key8==0)
- {
- P3=0X99;
- P2=0X99;
- }
- }
- }
- void T0_time() interrupt 1 //50MS
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- num++;
- if(num>=flag_hz)
- {
- num=0;
- P3=~P3;
- P2=~P2;
- }
- }
复制代码
警告:Build target 'Target 1'
assembling STARTUP.A51...
compiling shijian 7.c...
linking...
*** WARNING L5: CODE SPACE MEMORY OVERLAP
FROM: 000BH
TO: 000DH
Program Size: data=14.0 xdata=0 code=606
creating hex file from "shijian 7"...
"shijian 7" - 0 Error(s), 1 Warning(s). |