2016年4月24日 星期日

四軸直升機: 馬達控制+藍芽遙控+組裝

         今天花了幾個小時研究,購買材料,再進行組裝,終於把四軸直升機機身完成了,感覺還不賴,其中用到五金行買的木條,鐵絲,膠帶,甚至是寶特瓶和廢棄的衣架....哈! 反正是原型機嘛! 包裝不是太重要,重要的是軟硬體的整合是否完善。

        組裝完成後,在自家院子試飛,連摔了兩次機,因為我還沒把陀螺儀和動態平衡加進來,所以我的四軸直升機一升空,便會失去平衡,結果必然是摔機收場,還好機身只有一點小擦傷。
     
        雖然還有一段路要走,但是看到自己親手組裝的四軸直升機真的可以飛起來,心理還是蠻開心的 ~~~打起精神來, Keep Going!


運用最經濟的材料組裝四軸直升機: 我用裁切過的寶特瓶放置ESC, Arduino和藍芽電路板, 木條是五金行買的: 成本大概10元,四隻腳是用廢衣架做的,其他固定的部分就是用鐵絲和膠帶了~~~



馬達可以透過藍芽由手機來控制轉速,但是還沒做動態平衡,會墜機.......
所以還要繼續努力啦~~~





2016年4月18日 星期一

LabVIEW: 讀出檔案內容 + 搜尋比對資料

延續 LabVIEW: 樂透彩開獎程式(模擬) + 存檔紀錄程式,把之前寫入的資料讀出並統計開出號碼的次數,並繪製成圖表。

block diagram



人機介面

LabVIEW: 樂透彩開獎程式(模擬) + 存檔紀錄

根據上一個練習: LabVIEW: 樂透彩開獎程式(模擬) 加上存檔功能。





LabVIEW: 樂透彩開獎程式(模擬)

這個程式使用了build array, delete from array, rotate 1D array等陣列操作元件和兩個shift register。

block diagram

人機介面

2016年4月13日 星期三

LabVIEW: 計時碼錶

這個練習主要在於練習計時器的使用,並且裡用flat sequence來控制執行順序,另外還有一個重點: 利用按鍵隨時停止程式。

執行結果:





人機介面

Block diagram

2016年4月12日 星期二

LabVIEW: 溫度監控系統(模擬)

本練習用一個模擬的溫度感測器讀取溫度變化並繪製成圖表和存檔。

執行結果:





程式如下:

人機介面

Block diagram




2016年4月11日 星期一

RS232 串列埠連接 Arduino 控制LED燈

   RS232 串列埠連接 Arduino 控制LED燈


     利用 RS232 串列埠連接 Arduino 控制LED燈, 將pin5及pin10各接一個LED ,注意地線(GND)要接。



       設定pinMode 5 & 10 為 OUTPUT, 初始值設為LOW, LED滅; 當OUTPUT為HIGH, LED亮。程式設定String sign 為 1, 2, 3, 4時, LED分別亮一紅, 一黃 , 全亮, 全滅。程式如下:



執行結果如下:
用Arduino IDE執行串列埠控制LED燈明滅


      接著利用C#來控制串列埠,由工具箱加入1個seialPort及5個button, 其中 seialPort 屬性BaudRate & PortName 要和之前設定相同, 此處BaudRate為 115200 , PortName 為 COM3 。
      5個button為 Start及按鍵1, 按鍵2, 按鍵3, 按鍵4 ,分別控制按鍵開/關及LED四種明滅情況。




程式如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace W20160411a
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (btnStart.Text == "Start")
            {
                serialPort1.Open();
                btnStart.Text = "Close";
            }
            else 
            {
                serialPort1.Close();
                btnStart.Text = "Start";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
                serialPort1.Write("1");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
                serialPort1.Write("2");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
                serialPort1.Write("3");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
                serialPort1.Write("4");
        }
    }
}



執行結果如下:
以Visual Studio撰寫串列埠C#程式控制LED燈明滅





2016年4月5日 星期二

微處理器實作: AT89S52 迷你俄羅斯輪盤(電子骰子)遊戲

        既然我們會控制四個七段顯示器、按鍵,也會播放音樂,而且知道timer和中斷如何運作,那麼來製作一個小遊戲應該部會太困難吧?! 是的,集合之前練習所獲的相關知識,確實已經可以來做個遊戲試試看。

         這個遊戲很簡單,利用三個七節顯示器的六個小方格當俄羅斯輪盤,讓玩家先選擇一個方格(編號1~6),然後再用亂數讓目標方格跑動,如果目標方格和玩家選擇的方格重合,則玩家贏得此局比賽,當然選擇的時候要有按鍵音,目標方格跑動的時候要有跳格音效,中獎後也要有慶祝動畫和音樂(超級馬力歐)囉! 雖然這個遊戲很簡單,但是已經具備娛樂軟體的雛型,製作過程還蠻有樂趣的 !!! 你也可以試試看。


執行結果:



完整程式:

#include <regx52.h>
#include "music.h"

#define LED_NUM_0 0xC0
#define LED_NUM_1 0xF9
#define LED_NUM_2 0xA4
#define LED_NUM_3 0xB0
#define LED_NUM_4 0x99
#define LED_NUM_5 0x92
#define LED_NUM_6 0x82
#define LED_NUM_7 0xF8
#define LED_NUM_8 0x80
#define LED_NUM_9 0x98

#define LED_OUT P1

#define MUSIC_MAX_NUM 6

unsigned char count_10ms;
unsigned int  Tone;
unsigned char Beat;
unsigned char playNum=0;


unsigned short count2 = 10;
unsigned short count3 = 0;

unsigned int mynum2 = 0;

unsigned char myarray[4]={0xff, 0xff, 0xff, 0xff};

unsigned char music_mode=0;
unsigned char num_sel = 1;
unsigned char num_now = 1;

unsigned char SelButtonState=0;
unsigned char ButtonPressTime=0;
unsigned char LED_IN_USE=0;
unsigned char GAME_MODE=0;

unsigned char code led_show[56][5] = {
{ 255, 255, 255, 255, 10 },
{ 156, 255, 255, 255, 10 },
{ 156, 156, 255, 255, 10 },
{ 156, 156, 156, 255, 10 },
{ 156, 156, 156, 156, 10 },
{ 156, 156, 156, 128, 10 },
{ 156, 156, 128, 128, 10 },
{ 156, 128, 128, 128, 10 },
{ 128, 128, 128, 128, 10 },
{ 128, 128, 128, 128, 10 },
{ 192, 128, 128, 128, 10 },
{ 192, 192, 128, 128, 10 },
{ 192, 192, 192, 128, 10 },
{ 192, 192, 192, 192, 10 },
{ 208, 192, 192, 192, 10 },
{ 240, 192, 192, 192, 10 },
{ 244, 192, 192, 192, 10 },
{ 246, 192, 192, 192, 10 },
{ 246, 208, 192, 192, 10 },
{ 246, 240, 192, 192, 10 },
{ 246, 244, 192, 192, 10 },
{ 246, 246, 192, 192, 10 },
{ 246, 246, 208, 192, 10 },
{ 246, 246, 240, 192, 10 },
{ 246, 246, 244, 192, 10 },
{ 246, 246, 246, 192, 10 },
{ 246, 246, 246, 208, 10 },
{ 246, 246, 246, 240, 10 },
{ 246, 246, 246, 244, 10 },
{ 246, 246, 246, 246, 10 },
{ 246, 246, 246, 254, 10 },
{ 246, 246, 254, 254, 10 },
{ 246, 254, 254, 254, 10 },
{ 254, 254, 254, 254, 10 },
{ 255, 254, 254, 254, 10 },
{ 255, 255, 254, 254, 10 },
{ 255, 255, 255, 254, 10 },
{ 255, 255, 255, 255, 10 },
{ 255, 255, 255, 255, 10 },
{ 0, 255, 255, 255, 10 },
{ 0, 0, 255, 255, 10 },
{ 0, 0, 0, 255, 10 },
{ 0, 0, 0, 0, 10 },
{255,255,255,255,10},
{ 0, 0, 0, 0, 10 },
{255,255,255,255,10},
{ 0, 0, 0, 0, 10 },
{255,255,255,255,10},
{ 0, 0, 0, 0, 10 },
{255,255,255,255,10},
{ 0, 0, 0, 0, 10 },
{255,255,255,255,10},
{ 0, 0, 0, 0, 10 },
{255,255,255,255,10},
{ 0, 0, 0, 0, 10 },
{255,255,255,255,10},
};

unsigned char led_num[10] =
{
LED_NUM_0, LED_NUM_1, LED_NUM_2, LED_NUM_3, LED_NUM_4, 
LED_NUM_5, LED_NUM_6, LED_NUM_7, LED_NUM_8, LED_NUM_9
};

void my_delay_ms(unsigned int n)
{
unsigned int i, j;

for(j=0; j<n; j++)
for(i=0; i<120; i++) ; 

}

void led_write_1s(unsigned char r, unsigned char x)
{
 P3_4=1;
 switch(r)
{
case 0: P3_3 = 0; break;
case 1: P3_2 = 0; break;
case 2: P3_1 = 0; break;
case 3: P3_0 = 0; break;
default: break;
}
 LED_OUT = x;
 my_delay_ms(3);
 LED_OUT = 0xFF;
switch(r)
{
case 0: P3_3 = 1; break;
case 1: P3_2 = 1; break;
case 2: P3_1 = 1; break;
case 3: P3_0 = 1; break;
default: break;
}
P3_4=0;

}

void T0_int(void) interrupt 1
{
TL0 = (65536-10000)%256;
TH0 = (65536-10000)/256;
    count_10ms++;

if(count2 ==0 )
{
count2=10;                
    myarray[3]= ~(1<<mynum2); 
    mynum2++;

if(mynum2==6) mynum2=0;
}
else 
count2--;

count3++; // for update 7-seg-display
    
  if(SelButtonState==1)
{
if(ButtonPressTime<40)  
ButtonPressTime++;
else
{
ButtonPressTime=0;
SelButtonState=0;
num_sel++;
if(num_sel==(MUSIC_MAX_NUM+1)) 
num_sel=1;
}
}
}

void T1_int(void) interrupt 3
{
TH1=Tone/256;
  TL1=Tone%256;
 
if(Tone!=0xff && Tone!=0x00 ) //0xff is no_sound, 0x00 is the end
P2_0=~P2_0;
}


void EX0_int(void) interrupt 0
{
if(P3_4 == 0)
GAME_MODE=1;
}

void EX1_int(void) interrupt 2
{
if(P3_4 == 0 && GAME_MODE ==0)
SelButtonState=1;  //marking for the button is pressed
}

void timer0_init(void)
{
TMOD = (TMOD&0xf0) | 0x01; 
TL0 = (65536-10000) % 256;  
TH0 = (65536-10000) / 256;
ET0 = 1; 
TR0 = 1;
}

void timer1_init(void)
{
TMOD = (TMOD&0x0f) | 0x10;  
TL1 = (65536-10000) % 256; 
TH1 = (65536-10000) / 256; 
ET1 = 1; 
TR1 = 1;
}

void sys_init(void)
{

P2_0=1;
myarray[3] = 0xff;
playNum=0;
count_10ms = 0;

EX0=1;
IT0=1;
EX1=1;
IT1=1;
P3_4 = 0;
EA = 1;
timer0_init(); 
timer1_init();

}

void set_dice_num(unsigned char x, unsigned char user_num)
{
myarray[0] = 0xff;
myarray[1] = 0xff;
myarray[2] = 0xff;

switch(x)
{
case 1: myarray[2]=0x9c; break;
case 2: myarray[1]=0x9c; break;
case 3: myarray[0]=0x9c; break;
case 4: myarray[0]=0xa3; break;
case 5: myarray[1]=0xa3; break;
case 6: myarray[2]=0xa3; break;
default: break;
}
switch(user_num)
{
case 1: myarray[2]&=0x9c; break;
case 2: myarray[1]&=0x9c; break;
case 3: myarray[0]&=0x9c; break;
case 4: myarray[0]&=0xa3; break;
case 5: myarray[1]&=0xa3; break;
case 6: myarray[2]&=0xa3; break;
default: break;
}
}

void update_dice_display(unsigned char *a)
{

P3_4=1;
led_write_1s(0, a[0]);
led_write_1s(1, a[1]);
led_write_1s(2, a[2]);
P3_4=0;

}

void play_tone(unsigned int *tone_table, unsigned char *beat_table, 
unsigned short t, unsigned char mode)
{
playNum=0;
count_10ms=0;
Tone = tone_table[playNum];
Beat = beat_table[playNum];
TR1=1;
while(playNum < t)
{
if(count_10ms>Beat)
{
TR1=0;
playNum++;
count_10ms=0;
Tone=tone_table[playNum];
Beat=beat_table[playNum];
TH1=Tone/256;
TL1=Tone%256;
          TR1=1;
}
if(mode==1)
{

P3_4=1;
led_write_1s(3, led_show[playNum][0]);
led_write_1s(2, led_show[playNum][1]);
led_write_1s(1, led_show[playNum][2]);
led_write_1s(0, led_show[playNum][3]);
P3_4=0;
}
//else // 如果你不喜歡閃爍的跑格畫面,請把這行打開
   //{                                                         // 如果你不喜歡閃爍的跑格畫面,請把這行打開
   //   led_write_1s(3,led_num[num_sel]);  // 如果你不喜歡閃爍的跑格畫面,請把這行打開
   //   update_dice_display(myarray);        // 如果你不喜歡閃爍的跑格畫面,請把這行打開   
   //}                                                        // 如果你不喜歡閃爍的跑格畫面,請把這行打開


}
TR1=0;
}

main()
{
unsigned char num_result=1;
unsigned int game_speed_count=0;
unsigned int dice_run_num; 

sys_init();
set_dice_num(num_now, num_sel);
dice_run_num= TH0%7+TL0%13+(TH0+TL0)%23+19;
while(1)
{

if(GAME_MODE==1)
{  
if(game_speed_count==3)
{
set_dice_num(num_result, num_sel);
play_tone(ToneTable_3, BeatTable_3, 1, 0);
dice_run_num--;
if(dice_run_num == 0) 
{
if(num_result==num_sel) //Bingo!!!
{
play_tone(ToneTable_1, BeatTable_1, 56, 1);
}

GAME_MODE = 0;
game_speed_count=0;
dice_run_num=TH0%7+TL0%13+(TH0+TL0)%23+19;
}
else
{
num_result++; 
if(num_result==7) num_result=1;
}
game_speed_count=0;
}
game_speed_count++;
}
 else //GAME_MODE == 0
{
if(num_now != num_sel)
{
num_now = num_sel;
play_tone(ToneTable_2, BeatTable_2, 1, 0);
set_dice_num(num_sel, num_result);
}
}
led_write_1s(3,led_num[num_sel]);
 update_dice_display(myarray);
}
}

music.h 的內容:

/* --------------------- 超級馬利歐-----------------------------*/
unsigned int code ToneTable_1[]=
{
65347, 65347,   255, 65347,   255, 65298, 65347,   255, 65377,   255, 
  255,   255, 65218,   255,   255,   255, 65298,   255,   255, 65218, 
  255,   255, 65157,   255,   255, 65252,   255, 65283,   255, 65268, 
65252,   255, 65218, 65347, 65377, 65394,   255, 65358, 65377,   255, 
65347,   255, 65298, 65324, 65283,   255,   255, 65298,   255,   255, 
65218,   255,   255, 65157,   255,   255, 65252,   255, 65283,   255, 
65268, 65252,   255, 65218, 65347, 65377, 65394,   255, 65358, 65377, 
  255, 65347,   255, 65298, 65324, 65283,   255,   255, 0
};

unsigned char code BeatTable_1[]=
{
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 22, 22, 22, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 22, 22, 22, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 
};

unsigned int code ToneTable_2[]=
{
63628
};

unsigned char code BeatTable_2[]=
{
16, 
};

unsigned int code ToneTable_3[]=
{64778};

unsigned char code BeatTable_3[]=
{7};

2016年4月2日 星期六

微處理器實作: AT89S52 音樂盒

        在這個練習中,我設計了一個由四首歌所組成的音樂盒,使用者可以用案件選取所要的音樂,進行播放,這四首歌曲分別是: 0.周杰倫的青花瓷 ,  1. 超級馬力歐 , 2.馬利兄弟-地底世界 ,3.俄羅斯方塊背景音樂。

        程式中會用到兩個timer和一個外部中斷,timer0負責計時,timer1負責發出特定頻率的聲音,外部中斷是由按鍵(用來選擇歌曲)所產生。

執行結果:


完整程式:

#include <regx52.h>
#include "music.h"

#define LED_NUM_0 0xC0
#define LED_NUM_1 0xF9
#define LED_NUM_2 0xA4
#define LED_NUM_3 0xB0
#define LED_NUM_4 0x99
#define LED_NUM_5 0x92
#define LED_NUM_6 0x82
#define LED_NUM_7 0xF8
#define LED_NUM_8 0x80
#define LED_NUM_9 0x98

#define LED_OUT P1

#define MUSIC_MAX_NUM 4

unsigned char count_10ms;
unsigned int  Tone;
unsigned char Beat;
unsigned char playNum=0;


unsigned short count2 = 10;
unsigned short count3 = 0;

unsigned int mynum2 = 0;

unsigned char myarray[4];

unsigned char music_mode=0;
unsigned char music_sel = 0;
unsigned char music_playing = 0;
unsigned  int *ToneTableList[]=
{ToneTable_0, ToneTable_1, ToneTable_2, ToneTable_3};

unsigned char *BeatTableList[]=
{BeatTable_0, BeatTable_1, BeatTable_2, BeatTable_3};

unsigned char SelButtonState=0;
unsigned char ButtonPressTime=0;


unsigned char led_num[10] =
{
LED_NUM_0, LED_NUM_1, LED_NUM_2, LED_NUM_3, LED_NUM_4, 
LED_NUM_5, LED_NUM_6, LED_NUM_7, LED_NUM_8, LED_NUM_9
};

void my_delay_ms(unsigned int n)
{
unsigned int i, j;

for(j=0; j<n; j++)
for(i=0; i<120; i++) ; 

}

void T0_int(void) interrupt 1
{
   TL0 = (65536-10000)%256;
   TH0 = (65536-10000)/256;
    count_10ms++;

   if(count2 ==0 )
  {
count2=10;                
    myarray[3]= ~(1<<mynum2); 
    mynum2++;

        if(mynum2==6) mynum2=0;
 }
else 
count2--;
count3++; // for update 7-seg-display
       
        if(SelButtonState==1)
{
if(ButtonPressTime<40)  
ButtonPressTime++;
else
{
ButtonPressTime=0;
SelButtonState=0;
music_sel++;

          if(music_sel==MUSIC_MAX_NUM) 
           music_sel=0;
}
}
}

void T1_int(void) interrupt 3
{
    TH1=Tone/256;
    TL1=Tone%256;
 
    if(Tone!=0xff && Tone!=0x00 ) //0xff is no_sound, 0x00 is the end
  P2_0=~P2_0;
}

void EX0_int(void) interrupt 0
{
SelButtonState=1; //marking for the button is pressed
}

void timer0_init(void)
{
TMOD = (TMOD&0xf0) | 0x01; 
TL0 = (65536-10000) % 256;  
TH0 = (65536-10000) / 256;
ET0 = 1; 
TR0 = 1;
}

void timer1_init(void)
{
TMOD = (TMOD&0x0f) | 0x10;  
TL1 = (65536-10000) % 256; 
TH1 = (65536-10000) / 256; 
ET1 = 1; 
TR1 = 1;
}

void sys_init(void)
{
P2_0=1;
myarray[3] = 0xff;
playNum=0;
count_10ms = 0;

        Tone = ToneTableList[music_playing][playNum];
Beat = BeatTableList[music_playing][playNum];

EX0=1;
IT0=1;
P3_4 = 0;
EA = 1;
timer0_init(); 
timer1_init();

}

main()
{
sys_init();
while(1)
{
   if(music_playing == music_sel)
  {
     if(Tone!=0)
    {
if(count_10ms>Beat)
{
      TR1=0;
   playNum++;
   count_10ms=0;
   Tone=ToneTableList[music_playing][playNum];
   Beat=BeatTableList[music_playing][playNum];
   TH1=Tone/256;
  TL1=Tone%256;
                  TR1=1;
}
        }
   else
          {
       music_mode = 0xff;
    TR1=0;
   }
     } // music number changed
     else
     {
EA=0;
        music_playing = music_sel;
sys_init();
     }
  P3_1 = 0; //enable control bit: active LOW
 LED_OUT = led_num[music_playing];
 my_delay_ms(3);
 LED_OUT = 0xFF;
  P3_1 = 1;

  P3_0 = 0; //enable control bit: active LOW
 LED_OUT = myarray[3];
 my_delay_ms(3);
 LED_OUT = 0xFF;
  P3_0 = 1;
}
}

music.h 的內容(歌曲部分):

/*-------------------- 青花瓷-----------------------------*/
unsigned int code ToneTable_0[]=
{
  255, 63836, 63628, 63264, 63628, 63628, 63264, 63628, 63628, 63264, 
63628, 63264, 62985,   255,   255, 63836, 63628, 63264, 63628, 63628, 
63264, 63628, 63628, 64021, 63836, 63628, 63628,   255,   255, 62985, 
63264, 64021, 64021, 64021, 63836, 64021, 64021, 63836, 64021, 64261, 
64021, 64021,   255,   255, 64021, 64021, 64021, 63836, 63836, 63836, 
63836, 63836, 63628, 64021, 64021, 63836,   255,   255, 63836, 63628, 
63264, 63628, 63628, 63264, 63628, 63628, 63264, 63628, 63264, 62985, 
  255,   255, 62985, 63264, 64021, 64261, 64261, 64021, 64261, 64261, 
64021, 63836, 63628, 63628,   255,   255, 63836, 63628, 63836, 64021, 
63836, 63836, 63628, 63836, 63628, 63264, 63836, 63628, 63628, 63264, 
63628, 63628, 63628,   255,   255, 64261, 64261, 64021, 63836, 64021, 
63264, 63836, 64021, 64261, 64021, 63836,   255,   255, 64261, 64261, 
64021, 63836, 64021, 62985, 63836, 64021, 64261, 63836, 63628,   255, 
  255, 63628, 63836, 64021, 64261, 64400, 64261, 64104, 64261, 64021, 
64021, 63836, 63836,   255,   255, 63628, 63836, 63628, 63628, 63836, 
63628, 63836, 63836, 64021, 64261, 64021, 64021,   255,   255, 64261, 
64261, 64021, 63836, 64021, 63264, 63836, 64021, 64261, 64021, 63836, 
  255,   255, 64261, 64261, 64021, 63836, 64021, 62985, 63836, 64021, 
64261, 63836, 63628,   255,   255, 63628, 63836, 64021, 64261, 64400, 
64261, 64104, 64261, 64021, 64021, 63836, 63836, 62985, 64021, 63836, 
63836, 63836, 63628,   255, 0
};

unsigned char code BeatTable_0[]=
{
25, 25, 25, 25, 50, 25, 25, 50, 25, 25, 
25, 25, 50, 50, 25, 25, 25, 25, 50, 25, 
25, 50, 25, 25, 25, 25, 50, 50, 25, 25, 
25, 25, 50, 25, 25, 50, 25, 25, 25, 25, 
25, 25, 50, 25, 25, 25, 25, 25, 25, 25, 
25, 50, 25, 25, 25, 50, 50, 25, 25, 25, 
25, 50, 25, 25, 50, 25, 25, 25, 25, 50, 
50, 25, 25, 25, 25, 50, 25, 25, 50, 25, 
25, 25, 25, 50, 50, 25, 25, 25, 25, 25, 
25, 25, 25, 50, 25, 25, 25, 25, 25, 25, 
50, 25, 100, 50, 25, 25, 25, 25, 25, 25, 
50, 25, 25, 25, 25, 100, 50, 25, 25, 25, 
25, 25, 25, 50, 25, 25, 25, 25, 100, 50, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 100, 50, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 50, 25, 25, 50, 50, 25, 25, 
25, 25, 25, 25, 50, 25, 25, 25, 25, 100, 
50, 25, 25, 25, 25, 25, 25, 50, 25, 25, 
25, 25, 100, 50, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 100, 25, 50, 25, 
25, 25, 100, 50, 
};

/* --------------------- 超級馬力歐-----------------------------*/
unsigned int code ToneTable_1[]=
{
65347, 65347,   255, 65347,   255, 65298, 65347,   255, 65377,   255, 
  255,   255, 65218,   255,   255,   255, 65298,   255,   255, 65218, 
  255,   255, 65157,   255,   255, 65252,   255, 65283,   255, 65268, 
65252,   255, 65218, 65347, 65377, 65394,   255, 65358, 65377,   255, 
65347,   255, 65298, 65324, 65283,   255,   255, 65298,   255,   255, 
65218,   255,   255, 65157,   255,   255, 65252,   255, 65283,   255, 
65268, 65252,   255, 65218, 65347, 65377, 65394,   255, 65358, 65377, 
  255, 65347,   255, 65298, 65324, 65283,   255,   255, 0
};


unsigned char code BeatTable_1[]=
{
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 22, 22, 22, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 
16, 16, 16, 22, 22, 22, 16, 16, 16, 16, 
16, 16, 16, 16, 16, 16, 16, 16, 
};

/* ---------------- 馬利兄弟: underworld ------------ */
unsigned int code ToneTable_2[]=
{
63628, 64580, 63264, 64400, 63391, 64464,   255,   255, 63628, 64580, 
63264, 64400, 63391, 64464,   255,   255, 62679, 64104, 62135, 63836, 
62331, 63929,   255,   255, 62679, 64104, 62135, 63836, 62331, 63929, 
  255,   255, 63929, 63731, 63836, 63731, 63929, 63929, 63133, 62985, 
63731, 63628, 64185, 64104, 62506, 64464, 64400, 64332, 63929, 63512, 
63391, 63264, 63133,   255,   255,   255, 0
};

unsigned char code BeatTable_2[]=
{
16, 16, 16, 16, 16, 16, 33, 66, 16, 16, 
16, 16, 16, 16, 33, 66, 16, 16, 16, 16, 
16, 16, 33, 66, 16, 16, 16, 16, 16, 16, 
33, 33, 11, 11, 11, 33, 33, 33, 33, 33, 
33, 11, 11, 11, 11, 11, 11, 20, 20, 20, 
20, 20, 20, 66, 66, 66, 
};

/* -------------------俄羅斯方塊背景音樂  -------------------------*/
unsigned int code ToneTable_3[]=
{
64778, 62506, 64524, 64580, 64685, 64778, 64685, 64580, 64524, 64400, 
63264, 64400, 64580, 64778, 63264, 64685, 64580, 64524, 64021, 64261, 
64580, 64685, 62506, 64778, 62506, 64580, 63264, 64400, 63264, 64400, 
63264, 61471, 61720, 62135, 64685, 64820, 64968, 64580, 64580, 64899, 
64820, 64778, 61720,   255, 64580, 64778, 64400, 64261, 64685, 64580, 
64524, 64021, 64524, 64580, 64685, 64261, 64778, 64261, 64580, 64021, 
64400, 62506, 64400,   255, 64778, 62506, 64524, 64580, 64685, 64778, 
64685, 64580, 64524, 64400, 63264, 64400, 64580, 64778, 63264, 64685, 
64580, 64524, 64021, 64261, 64580, 64685, 62506, 64778, 62506, 64580, 
63264, 64400, 63264, 64400, 63264, 61471, 61720, 62135, 64685, 64820, 
64968, 64580, 64580, 64899, 64820, 64778, 61720,   255, 64580, 64778, 
64400, 64261, 64685, 64580, 64524, 64021, 64524, 64580, 64685, 64261, 
64778, 64261, 64580, 64021, 64400, 62506, 64400,   255, 64021, 62506, 
60991, 62506, 63628, 62506, 60991, 62506, 63836, 62506, 60729, 62506, 
63512, 62506, 60729, 62506, 63628, 62506, 60991, 62506, 63264, 62506, 
60991, 62506, 63133, 62506, 60729, 62506, 63512, 62506, 60729, 62506, 
64021, 62506, 60991, 62506, 63628, 62506, 60991, 62506, 63836, 62506, 
60729, 62506, 63512, 62506, 60729, 62506, 63628, 62506, 64021, 62506, 
64400, 62506, 60991, 62506, 64332, 62506, 60729, 62506, 60729, 62506, 
60729, 62506, 64778, 62506, 64524, 64580, 64685, 64778, 64685, 64580, 
64524, 64400, 63264, 64400, 64580, 64778, 63264, 64685, 64580, 64524, 
64021, 64261, 64580, 64685, 62506, 64778, 62506, 64580, 63264, 64400, 
63264, 64400, 63264, 61471, 61720, 62135, 64685, 64820, 64968, 64580, 
64580, 64899, 64820, 64778, 61720,   255, 64580, 64778, 64400, 64261, 
64685, 64580, 64524, 64021, 64524, 64580, 64685, 64261, 64778, 64261, 
64580, 64021, 64400, 62506, 64400,   255, 64778, 62506, 64524, 64580, 
64685, 64778, 64685, 64580, 64524, 64400, 63264, 64400, 64580, 64778, 
63264, 64685, 64580, 64524, 64021, 64261, 64580, 64685, 62506, 64778, 
62506, 64580, 63264, 64400, 63264, 64400, 63264, 61471, 61720, 62135, 
64685, 64820, 64968, 64580, 64580, 64899, 64820, 64778, 61720,   255, 
64580, 64778, 64400, 64261, 64685, 64580, 64524, 64021, 64524, 64580, 
64685, 64261, 64778, 64261, 64580, 64021, 64400, 62506, 64400,   255, 
64021, 62506, 60991, 62506, 63628, 62506, 60991, 62506, 63836, 62506, 
60729, 62506, 63512, 62506, 60729, 62506, 63628, 62506, 60991, 62506, 
63264, 62506, 60991, 62506, 63133, 62506, 60729, 62506, 63512, 62506, 
60729, 62506, 64021, 62506, 60991, 62506, 63628, 62506, 60991, 62506, 
63836, 62506, 60729, 62506, 63512, 62506, 60729, 62506, 63628, 62506, 
64021, 62506, 64400, 62506, 60991, 62506, 64332, 62506, 60729, 62506, 
60729, 62506, 60729, 62506, 0
};

unsigned char code BeatTable_3[]=
{
25, 25, 25, 25, 25, 12, 12, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 50, 25, 25, 12, 12, 25, 
25, 25, 25, 25, 25, 25, 12, 12, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 50, 50, 25, 25, 25, 25, 25, 12, 
12, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 50, 25, 
25, 12, 12, 25, 25, 25, 25, 25, 25, 25, 
12, 12, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 50, 50, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 12, 12, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 50, 25, 25, 12, 
12, 25, 25, 25, 25, 25, 25, 25, 12, 12, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 50, 50, 25, 25, 25, 25, 
25, 12, 12, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
50, 25, 25, 12, 12, 25, 25, 25, 25, 25, 
25, 25, 12, 12, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 50, 50, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 
25, 25, 25, 25, 
};