新聞中心

51單片機-蜂鳴器

作者: 時間:2016-12-02 來源:網(wǎng)絡(luò) 收藏

uint key(){
P0 = 0xfe;
if(H0 == 0)return 13;
if(H1 == 0)return 9;
if(H2 == 0)return 5;
if(H3 == 0)return 1;
P0 = 0xfd;
if(H0 == 0)return 14;
if(H1 == 0)return 10;
if(H2 == 0)return 6;
if(H3 == 0)return 2;
P0 = 0xfb;
if(H0 == 0)return 15;
if(H1 == 0)return 11;
if(H2 == 0)return 7;
if(H3 == 0)return 3;
P0 = 0xf7;
if(H0 == 0)return 16;
if(H1 == 0)return 12;
if(H2 == 0)return 8;
if(H3 == 0)return 4;
return 0;
}

void main(){
EA = 1;
ET0 = 1;
TMOD = 0x01;
TR0 = 0;
while(1){
i = key();
if(i == 0){
TR0 = 0;
buzz = 1;
}
else{
if(i > 8){
DATE = 65536 - (50000/(qin[i-9]*2))*10;
TH0_DATA= DATE >> 8;
TL0_DATA = DATE & 0x00ff;
}
else{
DATE = 65536 - (50000/qin[i-1])*10;
TH0_DATA = DATE >> 8;
TL0_DATA = DATE & 0x00ff;
}
TR0 = 1;
}
}
}

void time0() interrupt 1{
buzz = ~buzz;
TH0 = TH0_DATA;
TL0 = TL0_DATA;
}

由于我使用的板子自帶的有源蜂鳴器,所以聲音很難聽,哈哈。


上一頁 1 2 3 下一頁

評論


技術(shù)專區(qū)

關(guān)閉