My_Sound.c
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:2k
- #include "My_head.h"
- /*************************************/
- #define BUZZER P1_0
- #define PLAY P2_6
- #define PD P2_7
- //======================================
- BYTE code sound_addr[SOUND_MAX_INDEX+1]=
- {
- WELCOME_ADDR, //0--WELCOME_INDEX
- DEL_CONRECORD_ADDR,//1
- DEL_ALL_ADDR, //2
- CARD_ERR_ADDR, //3
- CARD_WRITEERR_ADDR,//4
- CARD_READERR_ADDR, //5
- CARD_VALERR_ADDR, //6
- KEY_VALERR_ADDR, //7
- 0xff//for test.
- };
- BYTE code err_sound_index[][2]=
- {
- {CARD_ERR_CODE,CARD_ERR_INDEX},
- {CARD_WRITEERR_CODE,CARD_WRITEERR_INDEX},
- {CARD_READERR_CODE,CARD_READERR_INDEX},
- {CARD_VALERR_CODE,CARD_VALERR_INDEX},
- {KEY_VALERR_CODE,KEY_VALERR_INDEX},
- {0,0}//注意:错误代码一定要在(1--250)之间。
- };
- void Sound_Err(BYTE errcod)
- {
- BYTE ii;
- for(ii=0;err_sound_index[ii][0];ii++)
- if(err_sound_index[ii][0]==errcod)
- {
- Sound_Play(err_sound_index[ii][1]);
- //SendStr(&err_sound_index[ii][1],1);
- break;
- }
- //SendStr(&errcod,1);
- //SendStr(&ii,1);
- return;
- }
- bit Sound_Play(BYTE index)
- {
- if(index>SOUND_MAX_INDEX)return(FALSE);
- P0 = sound_addr[index];
- PD = 1;delay_ms(10);
- PD = 0;delay_ms(10);
- PLAY = 0;delay_ms(10);
- PLAY = 1;
- //SendStr(&sound_addr[index],1);
- return(TRUE);
- }
- void Init_Sound(void)
- {
- BUZZER = 1;
- PLAY = 1;
- PD = 1;delay_ms(10);PD = 0;
- }
- void do_buzzer(BYTE count)
- {
- while(count--)
- {
- BUZZER = 0;
- delay_ms(50);
- BUZZER = 1;
- if(!count)break;
- delay_ms(50);
- }
- }
- void My_Do_Buzzer(BYTE time,BYTE count)
- {
- while(count--)
- {
- BUZZER = 0;
- delay_ms(time);
- BUZZER = 1;
- if(!count)break;
- delay_ms(time);
- }
- }