全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1759
推到 Plurk!
推到 Facebook!

89S51 單晶片,音效程式一直出錯

尚未結案
grass0423
一般會員


發表:3
回覆:2
積分:1
註冊:2011-08-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2015-04-30 10:02:38 IP:61.219.xxx.xxx 訂閱
各位大哥,可否幫我看一下這是89s51,C語言 有關音效的片段程式碼
SND_FAIL 在最後發聲宣告程式中
就這段一直出現
各位大大可以幫忙一下嗎??


#define SND_SUCCESS 2 // 成功
#define SND_NORMAL 4 // 正常

{57, 51, 45, 43, 38} };

{30} };
unsigned char code tone4[1][19] = { // success
void playSound(int x) { // 宣告 發出 聲音(區域名稱 X)
switch(x) { // 開關(X)
for(idx = 0; idx < 1; idx ) {
for(idz = 0; idz < 50; idz ) {
delay8us(tone2[idx][idy]);
delay8us(tone2[idx][idy]);
break; // 跳出迴圈
for(idx = 0; idx < 1; idx ) {
for(idz = 0; idz < 50; idz ) {
delay8us(tone4[idx][idy]);
delay8us(tone4[idx][idy]);
break;
case SND_FAIL: //音效 正常
for(idx = 0; idx < 1; idx ) {
for(idy = 0; idy < 3; idy ) {
for(idz = 0; idz < 50; idz ) {
SPK = 0; // (蜂音器 = 按)
delay8us(tone3[idx][idy]);
SPK = 1; // (蜂音器 = 沒按)
delay8us(tone3[idx][idy]);
} } }
break; // 跳出迴圈

}}

taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2015-04-30 18:26:20 IP:59.127.xxx.xxx 訂閱
找一下 編譯器不認得它
jxchen
一般會員


發表:5
回覆:13
積分:3
註冊:2007-02-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2015-05-24 22:31:04 IP:39.1.xxx.xxx 訂閱
#include <AT89X51.H>

void delay8us(unsigned char j,unsigned char i)
{

}



#define SND_RANDOM 1 // ??

#define SND_SUCCESS 2 // ??

#define SND_FAIL 3 // ?? (??? ???)

#define SND_NORMAL 4 // ??

sbit SPK=P3^5; //在這理我先用P3.5,你可以依據你電路設計去更改
//你沒有定義此IO PIN

unsigned char code tone1[1][5] = {

{57, 51, 45, 43, 38} };



unsigned char code tone2[1][1] = {

{30} };

unsigned char code tone3[1][3] = { // SND_FAIL

{115, 153, 153} };



unsigned char code tone4[1][19] = { // success

{77, 77, 57, 57, 45, 45, 38, 38, 38, 38, 45, 45, 45, 38, 38, 38, 38, 38, 38} };





//=======?? ??===============

void playSound(int x) { // ?? ?? ??(???? X)

int idx, idy, idz; // ????????

switch(x) { // ??(X)

case SND_RANDOM: // ?? (snd????? ??)

for(idx = 0; idx < 1; idx ) {

for(idy = 0; idy < 1; idy ) {

for(idz = 0; idz < 50; idz ) {

SPK = 0; // (??? = ?)

delay8us(tone2[idx][idy]);

SPK = 1; // (??? = ??)

delay8us(tone2[idx][idy]);

} } }

break; // ????

case SND_SUCCESS: // ?? (snd????? ??)

for(idx = 0; idx < 1; idx ) {

for(idy = 0; idy < 19; idy ) {

for(idz = 0; idz < 50; idz ) {

SPK = 0; // (??? = ?)

delay8us(tone4[idx][idy]);

SPK = 1; // (??? = ??)

delay8us(tone4[idx][idy]);

} } }

break;

case SND_FAIL: //?? ??

for(idx = 0; idx < 1; idx )
{

for(idy = 0; idy < 3; idy ) {

for(idz = 0; idz < 50; idz ) {

SPK = 0; // (??? = ?)

delay8us(tone3[idx][idy]);

SPK = 1; // (??? = ??)

delay8us(tone3[idx][idy]);

}
}
}

break; // ????

}
}

那有你的說的那個問題,我重新編譯後,只有SPK IO PIN 沒有定義
compiler no error
ADDRESS: 0110H
Program Size: data=13.0 xdata=0 code=477
"6" - 0 Error(s), 11 Warning(s).
系統時間:2024-04-24 18:04:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!