|
|
楼主 |
发表于 2008-4-15 14:39
|
显示全部楼层
/*
edited by Huang sheng , Huang kun, Yang yuqiang
initialed edit ---- 2008.2.25
ended edit -------- 2008.3.11
*/
#include <t_services.h>
#include <3048f.h>
#include "kernel_id.h"
#include "sample1.h"
#include "global.h"
/*****************************************************/
/* void main_menu(VP_INT exinf)
/* display menu function list
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void main_menu(VP_INT exinf){
initaled_setting(); // inital set of the micro
while(1){
PB.DR.BIT.B6 = 1; // turn off LED
PB.DR.BIT.B7 = 1;
ITU3.GRAH = 0x01; // inital set of the music voice
ITU3.GRAL = 0xF6;
syslog(LOG_NOTICE,"\n----------------- Menu ------------------------");
syslog(LOG_NOTICE,"---------- 1(s1) : System menu ----------------");
syslog(LOG_NOTICE,"---------- 2(s2) : Music menu -----------------");
syslog(LOG_NOTICE,"---------- 3(s3) : Audio menu -----------------");
syslog(LOG_NOTICE,"---------- 4(s4) : Flower menu ----------------");
syslog(LOG_NOTICE,"-----------------------------------------------");
while(1){
if(push_button(1) == 1){ // act the system menu
act_tsk(SYSTEM_MENU);
break;
}
else if(push_button(2) == 1){ // act the music menu
act_tsk(MUSIC_MENU);
break;
}
else if(push_button(3) == 1){ // act the audio menu
act_tsk(AUDIO_MENU);
break;
}
else if(push_button(4) == 1){ // act the piano menu
act_tsk(FLOWER_MENU);
break;
}
}
slp_tsk(); // sleep the main menu
}
}
/*****************************************************/
/* void initaled_setting(void)
/* inital set of the micro
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void initaled_setting(void){
char i;
for(i = 0; i < 3; i++){ // get the memory
get_mpf(POOL, &MEMORY_start_fp);
MEMORY_end_fp = MEMORY_start_fp + 262144;
}
AD.ADCSR.BIT.ADST = 1; // set the AD begin
DA.DACR.BIT.DAOE1 = 1; // enable DA1
DA.DADR1 = 2; // initialize DADR1
SCI0.SCR.BYTE = 0x00; // initialize SCI
SCI0.SMR.BYTE = 0x00; // format SCI
SCI0.BRR=71; // Baud rate 9600 (22118400/(32*B))-1
SCI0.SCR.BIT.TE=1; // start Transmit
SCI0.SCR.BIT.RE=1; // start Receive
ITU1.TIOR.BYTE = 0x00; // set the ITU1
ITU1.TCR.BYTE = 0x22; // set the HZ
ITU1.GRAH = 0x01; // set the GRA(11.025HZ)
ITU1.GRAL = 0xF6;
ITU2.TIOR.BYTE = 0x00; // set the ITU2
ITU2.TCR.BYTE = 0x22; // set the HZ
ITU2.GRAH = 0x01; // set the GRA(11.025HZ)
ITU2.GRAL = 0xF6;
ITU3.TIOR.BYTE = 0x00; // set the ITU3
ITU3.TCR.BYTE = 0x22;
ITU4.TIOR.BYTE = 0x00; // set the ITU4
ITU4.TCR.BYTE = 0x20;
ITU.TSTR.BYTE |= 0x1E; // begin the counting
}
//////////////////////////////////////////////////////////////////////////////////////////////
//system menu
//////////////////////////////////////////////////////////////////////////////////////////////
/*****************************************************/
/* void system_menu(VP_INT exinf)
/* display system menu function
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void system_menu(VP_INT exinf){
syslog(LOG_NOTICE,"\n------------- System Menu ---------------------");
syslog(LOG_NOTICE,"------ 1(s1) : Receive data from computer -----");
syslog(LOG_NOTICE,"------ 2(s2) : Send data to computer ----------");
syslog(LOG_NOTICE,"------ 3(s3) : Delete the music ---------------");
syslog(LOG_NOTICE,"------ 4(s4) : Save the piano to music --------");
syslog(LOG_NOTICE,"------ 5(s16): Quit----------------------------");
while(1){
if(push_button(1) == 1){ // receive the data from computer
music_receive();
wup_tsk(MAIN_MENU);
break;
}
else if(push_button(2) == 1){ // send data to computer
music_send();
wup_tsk(MAIN_MENU);
break;
}
else if(push_button(3) == 1){ // delete the music
music_delete();
wup_tsk(MAIN_MENU);
break;
}
else if(push_button(4) == 1){ // save the piano music to memory by 11.025KHZ
piano_save();
wup_tsk(MAIN_MENU);
break;
}
else if(push_button(16) == 1){ // exit the system memu
wup_tsk(MAIN_MENU);
break;
}
}
}
/*****************************************************/
/* void music_receive(void)
/* get the data from computer
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void music_receive(void){
char i = 0;
while(1){
if(i > 2){ // judge there are no enough memory
syslog(LOG_NOTICE,"\nThere are no enough memory,please press s16 to exit!");
while(1){
if(push_button(16) == 1){ // get out of the system menu
wup_tsk(MAIN_MENU);
ext_tsk();
}
}
}
if(MEMORY_SIGN == 0){ // there is empty memory
start_fp = MEMORY_start_fp; // get teh beginning address
syslog(LOG_NOTICE,"\nPlease press s1 to start receive or press s16 to exit!");
while(1){
if(push_button(16) == 1){ // exit the system menu
wup_tsk(MAIN_MENU);
ext_tsk();
}
if(push_button(1) == 1){ // begin to get the data
MEMORY_SIGN = 1; // set the flag
syslog(LOG_NOTICE, "begin to receive.");
while(1){
while (!(SCI0.SSR.BIT.RDRF)); // wait the change of the data
*start_fp =SCI0.RDR; // write the memory
if(*start_fp=='h'&& *(start_fp-1)=='a'&& *(start_fp-2)=='e'&& *(start_fp-3)=='y'){ // judge the end of data
syslog(LOG_NOTICE, "receive end");
break;
}
if(push_button(16) == 1){ // exit while receiving
syslog(LOG_NOTICE, "someone press the key to break");
break;
}
if(start_fp == MEMORY_end_fp){ // judge the end of the memory
syslog(LOG_NOTICE, "There are no enough memory!");
break;
}
start_fp++;
SCI0.SSR.BIT.RDRF = 0; // reset the flag of data changing
}
MUSIC_end_fp = start_fp - 5; // set the end of the music
break;
}
}
break;
}
i++;
}
}
/*****************************************************/
/* void music_send(void)
/* send the data to computer
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void music_send(void){
char i = 0, n = 1;
long size;
unsigned char s[4];
unsigned char *send_data;
syslog(LOG_NOTICE,"\n--------- music send list ------------"); // the list of the music
while(1){
if(MEMORY_SIGN == 1) syslog(LOG_NOTICE,"--------- Music %d(s%d) ----------------",(i+1),(i+1));
i++;
if(i > 3) break;
}
syslog(LOG_NOTICE,"--------- (s16) Quit -----------------");
while(1){
if((push_button(n) == 1) && (MEMORY_SIGN[n-1] == 1)){ // choose the music
syslog(LOG_NOTICE,"send begin!");
send_data = MEMORY_start_fp[n-1];
size = MUSIC_end_fp[n-1] - MEMORY_start_fp[n-1];
for(i = 0; i < 4; i++){
s = size % 256;
size = size / 256;
if(SCI0.SSR.BIT.TDRE){
SCI0.TDR = s;
SCI0.SSR.BIT.TDRE = 0;
while(!(SCI0.SSR.BIT.TEND));
}
}
dly_tsk(500);
while(1){
if(push_button(16) == 1){
wup_tsk(MAIN_MENU);
ext_tsk();
}
if(SCI0.SSR.BIT.TDRE){
SCI0.TDR = *send_data;
SCI0.SSR.BIT.TDRE = 0;
while(!(SCI0.SSR.BIT.TEND));
if (SCI0.SSR.BIT.TEND){
send_data++;
if(send_data == MUSIC_end_fp[n-1]){
syslog(LOG_NOTICE, "send over");
break;
}
}
}
}
break;
}
n++;
if(n > 3) n = 1;
}
}
/*****************************************************/
/* void music_delete(void)
/* delete the music data
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void music_delete(void){
char i = 0, n = 1;
syslog(LOG_NOTICE,"\n-------- music delete list -----------");// the list of the music
while(1){
if(MEMORY_SIGN == 1) syslog(LOG_NOTICE,"----------- Music %d(s%d) --------------",(i+1),(i+1));
i++;
if(i > 3) break;
}
syslog(LOG_NOTICE,"----------- (s16) Quit ---------------");
while(1){
if((push_button(n) == 1) && (MEMORY_SIGN[n-1] == 1)){ // choose the music
end_fp = MUSIC_end_fp[n-1]; // get the address of the music
start_fp = MEMORY_start_fp[n-1];
MEMORY_SIGN[n-1] = 0; // set the flag of the memory
while(1){ // delete the data
*start_fp = 0;
if(start_fp == end_fp) break;
start_fp++;
}
break; // exit by delete all data
}
n++;
if(n > 3) n = 1;
if(push_button(16) == 1) break; // exit by push s16
}
}
/*****************************************************/
/* void piano_save(void)
/* save the piano record to music data
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void piano_save(void){
char i = 0, j = 0, n = 1, num = 0;
syslog(LOG_NOTICE,"\n-------- Piano music list -----------"); // list the recorded music
while(1){
if(PIANO[0] != 0) syslog(LOG_NOTICE,"-------- Piano music %d(s%d) ----------",(i+1),(i+1));
i++;
if(i > 4) break;
}
syslog(LOG_NOTICE,"----------- (s16) Quit --------------");
while(1){
if((push_button(n) == 1) && (PIANO[n-1][0] != 0)){ // get the choose music
while(1){
if(j > 2){ // judge if the memory is empty
syslog(LOG_NOTICE,"\nThere are no enough memory,please press s16 to exit!");
while(1){
if(push_button(16) == 1){ // exit by push s16
wup_tsk(MAIN_MENU);
ext_tsk();
}
}
}
if(MEMORY_SIGN[j] == 0){ // there are empty memory
end_fp = MEMORY_end_fp[j]; // get the address
start_fp = MEMORY_start_fp[j];
MEMORY_SIGN[j] = 1; // set the flag
ITU1.TIER.BYTE = 0x01; // begin interrupt
while(1){
ITU4.GRAH = ITAH[PIANO[n-1][num]-1]; // set the HZ
ITU4.GRAL = ITAL[PIANO[n-1][num]-1];
ITU4.TIER.BYTE = 1; // start the interrupt
tslp_tsk(PIANO_TIME); // set the play time
ITU4.TIER.BYTE = 0; // close the interrupt
num++; // cycle
if(PB.DR.BIT.B6 == 0) break; // the memory is full
if((PIANO[n-1][num] == 0) || (num > 255)) break;
// judge the end of the music
}
ITU1.TIER.BYTE = 0; // end play
ITU4.TIER.BYTE = 0;
MUSIC_end_fp[j] = start_fp; // write the end music
wup_tsk(MAIN_MENU); // wake up main task
ext_tsk(); // exit the task
}
j++;
}
}
n++;
if(n > 4) n = 1;
if(push_button(16) == 1) break; // exit at the choosing
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//music menu
//////////////////////////////////////////////////////////////////////////////////////////////
/*****************************************************/
/* void music_menu(VP_INT exinf)
/* display music function
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void music_menu(VP_INT exinf){
char i = 0, n = 1;
syslog(LOG_NOTICE,"\n------------- music list -----------"); // print the list
while(1){
if(MEMORY_SIGN == 1) syslog(LOG_NOTICE,"------------- Music %d(s%d) ----------",(i+1),(i+1));
i++;
if(i > 3) break;
}
syslog(LOG_NOTICE,"------------- (s16) Quit -----------");
while(1){
if((push_button(n) == 1) && (MEMORY_SIGN[n-1] == 1)){ // judge the choose
end_fp = MUSIC_end_fp[n-1]; // get the address
start_fp = MEMORY_start_fp[n-1];
syslog(LOG_NOTICE,"\n----- data is playing,please choose button operation ---");
syslog(LOG_NOTICE,"---------- 1(s1) : Volume up ---------------------------");
syslog(LOG_NOTICE,"---------- 2(s2) : Volume down -------------------------");
syslog(LOG_NOTICE,"---------- 4(s3) : >> 4s -------------------------------");
syslog(LOG_NOTICE,"---------- 5(s4) : << 4s -------------------------------");
syslog(LOG_NOTICE,"---------- 6(s5) : voice down --------------------------");
syslog(LOG_NOTICE,"---------- 6(s6) : voice up ----------------------------");
syslog(LOG_NOTICE,"---------- 3(s7) : Pause/go on -------------------------");
syslog(LOG_NOTICE,"---------- 7(s16): Quit --------------------------------");
ITU3.TIER.BYTE = 0x01; // begin the interrupt
while(1){
if(push_button(1) == 1){ // volume up
if(VOLUME < 10) VOLUME++;
}
if(push_button(2) == 1){ // volume down
if(VOLUME > 1) VOLUME--;
}
if(push_button(3) == 1){ // play the music 4s before
ITU3.TIER.BIT.IMIEA = 0;
start_fp = start_fp + 44100;
if(start_fp >= MUSIC_end_fp[n-1]) start_fp = MUSIC_end_fp[n-1];
ITU3.TIER.BIT.IMIEA = 1;
}
if(push_button(4) == 1){ // play the music 4s later
start_fp = start_fp - 44100;
if(start_fp <= MEMORY_start_fp[n-1]) start_fp = MEMORY_start_fp[n-1];
}
if(push_button(5) == 1){ // voice up change
ITU3.TIER.BIT.IMIEA = 0; // stop the interrupt
if(ITU3.GRAL > 247) ITU3.GRAH++; // change the interrupt time
ITU3.GRAL = ITU3.GRAL + 8;
ITU3.TIER.BIT.IMIEA = 1; // begin the interrupt
}
if(push_button(6) == 1){ // voice down change
ITU3.TIER.BIT.IMIEA = 0;
if(ITU3.GRAL < 8) ITU3.GRAH--;
ITU3.GRAL = ITU3.GRAL - 8;
ITU3.TIER.BIT.IMIEA = 1;
}
if(push_button(7) == 1){ // pause
ITU3.TIER.BIT.IMIEA = ~ITU3.TIER.BIT.IMIEA; // stop or begin the interrupt
}
if(push_button(16) == 1){ // exit with push s16
ITU3.TIER.BYTE = 0x00; // stop the interrupt
wup_tsk(MAIN_MENU); // wake up the main menu
ext_tsk(); // exit the task
}
if(PB.DR.BIT.B6 == 0){ // play again
tslp_tsk(2000); // 2s stop
end_fp = MUSIC_end_fp[n-1]; // reset the address
start_fp = MEMORY_start_fp[n-1];
PB.DR.BIT.B6 = 1; // close the light
ITU3.TIER.BYTE = 0x01; // begin the interrupt
}
}
}
n++;
if(n > 3) n = 1; // the cicycle of list choose
if(push_button(16) == 1){ // exit by push s16
wup_tsk(MAIN_MENU); // wake up the main menu
break;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
//audio display
///////////////////////////////////////////////////////////////////////////////////////////////
/*****************************************************/
/* void audio_menu(VP_INT exinf)
/* display audio menu
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void audio_menu(VP_INT exinf){
char i = 0;
while(1){
if(i > 2){ // judge if the memory is empty
syslog(LOG_NOTICE,"\nThere are no enough memory,please press s16 to exit!");
while(1){
if(push_button(16) == 1){ // exit by push s16
wup_tsk(MAIN_MENU);
ext_tsk();
}
}
}
if(MEMORY_SIGN == 0){ // there are empty memory
end_fp = MEMORY_end_fp; // get the address
start_fp = MEMORY_start_fp;
syslog(LOG_NOTICE,"\n---- Push s1 to start audio --");
syslog(LOG_NOTICE,"---- Push s2 to pause/go on --");
syslog(LOG_NOTICE,"---- Push s16 to exit --------");
while(1){
if(push_button(16) == 1){ // exit
wup_tsk(MAIN_MENU); // wake up main menu
ext_tsk(); // end the task
}
if(push_button(1) == 1){ // start the music record
MEMORY_SIGN = 1; // set the flag
ITU2.TIER.BYTE = 0x01; // begin interrupt
while(1){
if(push_button(16) == 1){ // exit
ITU2.TIER.BYTE = 0x00; // end the interrupt
break;
}
if(PB.DR.BIT.B7 == 0) break; // end play
if(push_button(2) == 1) ITU2.TIER.BIT.IMIEA = ~ITU2.TIER.BIT.IMIEA;
// pause
}
MUSIC_end_fp = start_fp; // write the end music
wup_tsk(MAIN_MENU); // wake up main task
ext_tsk(); // exit the task
}
}
}
i++; // check the memory
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
//flower display
///////////////////////////////////////////////////////////////////////////////////////////////
/*****************************************************/
/* void flower_menu(VP_INT exinf)
/* display flower menu
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void flower_menu(VP_INT exinf){
syslog(LOG_NOTICE,"\n-------------- Flower Menu --------------------");
syslog(LOG_NOTICE,"---------- 1(s1): Record the piano ------------");
syslog(LOG_NOTICE,"---------- 2(s2): Play the piano record -------");
syslog(LOG_NOTICE,"---------- 3(s3): Delete the piano record -----");
syslog(LOG_NOTICE,"---------- 3(s16): Quit -----------------------");
while(1){
if(push_button(1) == 1){ // record the piano
flower_record();
wup_tsk(MAIN_MENU);
break;
}
if(push_button(2) == 1){ // play the recorded piano
flower_play();
wup_tsk(MAIN_MENU);
break;
}
if(push_button(3) == 1){ // delete the recorded piano
delete_record();
wup_tsk(MAIN_MENU);
break;
}
if(push_button(16) == 1){ // exit
wup_tsk(MAIN_MENU);
break;
}
}
ext_tsk(); //exit
}
/*****************************************************/
/* void flower_record(void)
/* record the music
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void flower_record(void){
char but = 1, i = 0;
unsigned char num = 0;
while(1){
if(i > 3){ // judge if there are memories
syslog(LOG_NOTICE,"\nThere are no enough memory, please input s16 to exit!");
while(1){
if(push_button(16) == 1) break; // exit
}
break;
}
if(PIANO[0] == 0){ // there is memory
syslog(LOG_NOTICE,"\n---- Piano begin -----------------------------");
syslog(LOG_NOTICE,"---- Play the music by s1 - s14 --------------");
syslog(LOG_NOTICE,"---- Use the s15 to return the last button----");
syslog(LOG_NOTICE,"---- Exit by s16!-----------------------------");
while(1){
if(push_button(but) == 1){ // judge the button
ITU4.GRAH = ITAH[but-1]; // set the HZ
ITU4.GRAL = ITAL[but-1];
ITU4.TIER.BYTE = 1; // begin the interrupt
tslp_tsk(320); // the piano lasting time
ITU4.TIER.BYTE = 0; // end the interrupt
PIANO[num] = but; // read the next data
num++;
}
but++;
if(but > 14) but = 1; // recycle the button judge
if(num > 255){ // the memory is full
syslog(LOG_NOTICE,"It is the end of the music!");
break;
}
if(push_button(15) == 1){ // delete one of the data
PB.DR.BIT.B6 = 0; // on the red light
num--; // delete the last data
PIANO[num] = 0;
PB.DR.BIT.B6 = 1; // off the red light
}
if(push_button(16) == 1){ // exit
break;
}
}
break;
}
i++;
}
}
/*****************************************************/
/* void flower_play(void)
/* play the recorded music
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void flower_play(void){
char i = 0, num = 0,n = 1;
syslog(LOG_NOTICE,"\n--------- Piano music list -----------"); // list the recorded music
while(1){
if(PIANO[0] != 0) syslog(LOG_NOTICE,"--------- Piano music %d(s%d) ----------",(i+1),(i+1));
i++;
if(i > 4) break;
}
syslog(LOG_NOTICE,"------------ (s16) Quit --------------");
while(1){
if((push_button(n) == 1) && (PIANO[n-1][0] != 0)){ // get the choose music
syslog(LOG_NOTICE,"\n---- data is playing,please choose button operation ----");
syslog(LOG_NOTICE,"---------- 1(s1) : Volume up ---------------------------");
syslog(LOG_NOTICE,"---------- 2(s2) : Volume down -------------------------");
syslog(LOG_NOTICE,"---------- 4(s3) : voice down --------------------------");
syslog(LOG_NOTICE,"---------- 5(s4) : voice up ----------------------------");
syslog(LOG_NOTICE,"---------- 6(s5) : Pause/go on -------------------------");
syslog(LOG_NOTICE,"---------- 7(s16): Quit --------------------------------");
while(1){
if(push_button(1) == 1){
if(VOLUME < 10) VOLUME++;
}
if(push_button(2) == 1){
if(VOLUME > 1) VOLUME--;
}
if(push_button(3) == 1){
if(PIANO_TIME < 480) PIANO_TIME = PIANO_TIME + 20;
}
if(push_button(4) == 1){
if(PIANO_TIME > 20) PIANO_TIME = PIANO_TIME - 20;
}
if(push_button(5) == 1){
while(push_button(5) != 1);
ITU4.GRAH = ITAH[PIANO[n-1][num]-1]; // set the HZ
ITU4.GRAL = ITAL[PIANO[n-1][num]-1];
ITU4.TIER.BYTE = 1; // start the interrupt
tslp_tsk(PIANO_TIME); // set the play time
ITU4.TIER.BYTE = 0; // close the interrupt
num++; // cycle
if((PIANO[n-1][num] == 0) || (num > 255)){ // judge the end of the music
tslp_tsk(3000); // pause
num = 0; // play again
}
if(push_button(16) == 1) break; // exit
}
break;
}
n++;
if(n > 4) n = 1;
if(push_button(16) == 1) break;
}
}
/*****************************************************/
/* void delete_record(void)
/* delete the recorded music
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void delete_record(void){
char i = 0, num = 0,n = 1;
syslog(LOG_NOTICE,"\n------------ Piano music delete list ---------");
// list the recorded music
while(1){
if(PIANO[0] != 0) syslog(LOG_NOTICE,"------------ Piano music %d(s%d) --------------",(i+1),(i+1));
i++;
if(i > 4) break;
}
syslog(LOG_NOTICE,"----------- (s16) Quit --------------------");
while(1){
if((push_button(n) == 1) && (PIANO[n-1][0] != 0)){ // judge the choose music
while(1){
PIANO[n-1][num] = 0; // delete the data
num++;
if((PIANO[n-1][num] == 0) || (num > 255)) break; // judge the end
}
break;
}
n++;
if(n > 4) n = 1; // the choose cycle
if(push_button(16) == 1) break; // exit
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
//interrupt
///////////////////////////////////////////////////////////////////////////////////////////////
/*****************************************************/
/* void imia1_handler(void)
/* play the piano music
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void imia1_handler(void){
ITU1.TSR.BIT.IMFA = 0; // reset the flag of the interrupt
*start_fp = SAVE; // record the data
start_fp++;
if(start_fp == end_fp) PB.DR.BIT.B6 = 0; // judge the end
}
/*****************************************************/
/* void imia2_handler(void)
/* record the audio
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void imia2_handler(void){
ITU2.TSR.BIT.IMFA = 0; // reset the flag of the interrupt
PB.DR.BIT.B6 = ~PB.DR.BIT.B6; // light the red
if(AD.ADCSR.BIT.ADF == 1){ // judge the A/D finished
AD.ADCSR.BIT.ADF = 0; // reset the A/D flag
AD.ADCSR.BIT.ADST = 1; // set the D/A enabled
*start_fp = AD.ADDRAH; // record the data
start_fp++;
DA.DADR1 = AD.ADDRAH ; // play the music
if(start_fp == end_fp){ // judge the end
PB.DR.BIT.B7 = 0; // on the green light
ITU2.TIER.BYTE = 0; // end the interrupt
}
}
}
/*****************************************************/
/* void imia3_handler(void)
/* play the audio music
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void imia3_handler(void){
ITU3.TSR.BIT.IMFA = 0; // reset the flag of the interrupt
PB.DR.BIT.B7 = ~PB.DR.BIT.B7; // on the green light
DA.DADR1 = (*start_fp - 128) * VOLUME / 5 + 128; // play the music
start_fp++;
if(start_fp == end_fp){ // judge the end of the music
PB.DR.BIT.B6 = 0; // on the red light
ITU3.TIER.BYTE = 0; // end the interrupt
}
}
/*****************************************************/
/* void imia4_handler(void)
/* play the piano music
/*
/* argument
/* none
/*
/* return
/* none
/*****************************************************/
void imia4_handler(void){
ITU4.TSR.BIT.IMFA = 0; // reset the flag of the interrupt
PB.DR.BIT.B7 = ~PB.DR.BIT.B7; // on the green light
DA.DADR1 = SAVE =(128 - 2*VOLUME) + VOLUME*4*PB.DR.BIT.B7;// play the music
}
///////////////////////////////////////////////////////////////////////////////////////////////
//button
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************/
/* char push_button(char s) */
/* judge the button */
/* */
/* argument: */
/* char s */
/* return: */
/* 1/0 */
/*********************************************************************/
char push_button(char s){
char i,j;
i = ( s + 3 ) / 4; // set the line
j = s % 4; // set the horizonial
PA.DR.BYTE = 0x0F; // reset the PA to 1
BOOL re = 0;
switch(j){ // judge the line
case 1: {PA.DR.BIT.B0 = 0; break;}
case 2: {PA.DR.BIT.B1 = 0; break;}
case 3: {PA.DR.BIT.B2 = 0; break;}
case 0: {PA.DR.BIT.B3 = 0; break;}
}
switch(i){ // judge the horizonal
case 1: if(P7.DR.BIT.B5 == 0) { // judge the button push
dly_tsk(100); // delay 0.1 second
if(P7.DR.BIT.B5 == 0){ // judge if it is ture push
while(P7.DR.BIT.B5 == 0); // wait until the button is unpush
re = 1; // close the judge and return 1
}
}
break;
case 2: if(P7.DR.BIT.B4 == 0) { // judge the B4 horizonal
dly_tsk(100);
if(P7.DR.BIT.B4 == 0){
while(P7.DR.BIT.B4 == 0);
re = 1;
}
}
break;
case 3: if(P7.DR.BIT.B3 == 0) { // judge the B3 horizonal
dly_tsk(100);
if(P7.DR.BIT.B3 == 0){
while(P7.DR.BIT.B3 == 0);
re = 1;
}
}
break;
case 4: if(P7.DR.BIT.B2 == 0) { // judge the B2 horizonal
dly_tsk(100);
if(P7.DR.BIT.B2 == 0){
while(P7.DR.BIT.B2 == 0);
re = 1;
}
}
break;
}
return (re);
} |
|