登录  | 立即注册

游客您好!登录后享受更多精彩

扫一扫,访问微社区

QQ登录

只需一步,快速开始

开启左侧

[寒假笔记] 谁能看看我的程序哪里错了(蜂鸣器演奏两只老虎)

[复制链接]
发表于 2019-1-26 17:59:34 | 显示全部楼层 |阅读模式
学习笔记
学习科目: 单片机
学习安排: 解决问题
开始时间: 2019-01-26
结束时间: 2019-01-26
    程序没有报错,下载到到单片机蜂鸣器不发声,谁能不能找找错误!
#include<STC12C5A60S2.H>
sbit BUZZ=P1^3;
unsigned int code NotFrequ[]={//&Ouml;&ETH;&Ograve;&ocirc;&ordm;&Iacute;&cedil;&szlig;&Ograve;&ocirc;//
523, 578, 659, 698, 784, 880, 988,
1047, 1175, 1319, 1397, 1568, 1760, 1976,
};
unsigned int code NoteReload[]={//&para;&Ocirc;&Oacute;&brvbar;&micro;&Auml;&para;¨&Ecirc;±&AElig;÷&Ouml;&Oslash;&Ocirc;&Oslash;//
65536-(33177600/12)/(523*2),
65536-(33177600/12)/(587*2),
65536-(33177600/12)/(659*2),
65536-(33177600/12)/(698*2),
65536-(33177600/12)/(784*2),
65536-(33177600/12)/(880*2),
65536-(33177600/12)/(988*2),
65536-(33177600/12)/(1047*2),
65536-(33177600/12)/(1175*2),
65536-(33177600/12)/(1319*2),
65536-(33177600/12)/(1397*2),
65536-(33177600/12)/(1568*2),
65536-(33177600/12)/(1760*2),
65536-(33177600/12)/(1976*2),

};
bit enable=1;
bit tmrflag=0;
unsigned char T0RH=0xFF;
unsigned char T0RL=0x00;
void PlayTwoTiger();
void main()
{
unsigned int i;

EA=1;
TMOD=0x01;
TH0=T0RH;
TL0=T0RL;
ET0=1;
TR0=1;

while(1)
{
  PlayTwoTiger();
  for(i=0;i<40000;i++);
}
}
void PiayTwoTiger()
{
unsigned char beat;
unsigned char note;
unsigned int time=0;
unsigned int beatTime=0;
unsigned int soundTime=0;

unsigned char code TwoTigerNote[] = {
  1, 2, 3, 1,  1, 2, 3, 1,  3, 4, 5,  3, 4, 5,
  5,6, 5,4, 3, 1,  5,6, 5,4, 3, 1,  1, 5, 1,  1, 5, 1,
};

unsigned char code TwoTigerBeat[] = {
  4,  4,  4, 4,  4,  4,  4, 4,  4, 4, 8,  4, 4, 8,
  3,1, 3,1, 4, 4, 3,1, 3,1, 4, 4,  4, 4, 8,  4, 4, 8,
};
for(beat=0; beat<sizeof(TwoTigerNote);)
{
while(!tmrflag);
tmrflag=0;
if(time == 0)
{
note=TwoTigerNote[beat]-1;
T0RH=NoteReload[note] >> 8;
T0RL=NoteReload[note];
beatTime=(TwoTigerBeat[beat]*NotFrequ[note])>>2;
soundTime=beatTime-(beatTime>>2);
enable=1;
time++;
}
else
{
if (time>=beatTime)
{
  time=0;
  beat++;
}
else
{
  time++;
  if(time == soundTime)
  {
   enable = 0;
   
  }
}
}
}
}
  
void InterruptTimer0() interrupt 1
{
TH0=T0RH;
TL0=T0RL;
tmrflag=1;
if (enable)
  BUZZ = ~BUZZ;
else
  BUZZ = 1;
}


好懒~~不想说~~~
发表于 2019-2-5 10:18:11 | 显示全部楼层
void PiayTwoTiger()应该是void PlayTwoTiger()
好懒~~不想说~~~
 楼主| 发表于 2019-2-5 18:08:35 | 显示全部楼层
嗯嗯!还真是,为什么不报错啊当初?
好懒~~不想说~~~
发表于 2019-2-5 20:56:42 | 显示全部楼层
风尘仆仆 发表于 2019-2-5 18:08
嗯嗯!还真是,为什么不报错啊当初?

用你程序编译的时候有3个警告   有一个说的是定义了未调用的函数
好懒~~不想说~~~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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