主要代碼
#include "reg52.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit BEEP=P1^0;
uchar tick,tl,th;
uchar TABLE[]={
0x82,0x01,0x81,0x94,0x84,0xB4,0xA4,0x04,
0x82,0x01,0x81,0x94,0x84,0xC4,0xB4,0x04,
0x82,0x01,0x81,0xF4,0xD4,0xB4,0xA4,0x94,
0xE2,0x01,0xE1,0xD4,0xB4,0xC4,0xB4,0x04,
0x00};
uchar TABLE1[]={
0xfb,0x04,0xfb,0x90,0xfc,0x09,0xfc,0x44,
0xfc,0xac,0xfd,0x09,0xfd,0x34,0xfd,0x82,
0xfd,0xc8,0xfe,0x06,0xfe,0x22,0xfe,0x56,
0xfe,0x85,0xfe,0x9a,0xfe,0xC1};
void timer0() interrupt 1 using 1
{
TL0=tl;TH0=th;
//請(qǐng)補(bǔ)充中斷服務(wù)函數(shù)內(nèi)容
BEEP=~BEEP;
}
void delay1()
{
uint i;
for(i=0;i<20000;i++) ;
}
void delay(tt)
{
uint i;
for(i=0;i<=tt;i++)
delay1();
}
void main(void)
{
uchar t,t0,k=0;
while(1)
{
//請(qǐng)補(bǔ)充初始化代碼:定時(shí)器T0,工作方式1,中斷總開(kāi)關(guān)使能,定時(shí)器T0開(kāi)關(guān)使能
TMOD=0x01;IE=0x82;
while(TABLE[k]!=0)
{
tick=(TABLE[k])&0x0f;
t=(_crol_(TABLE[k],4))&0x0f;
if(t!=0)
{
t0=(--t)*2+1;
t=t*2;
tl=TL0=TABLE1[t0];
th=TH0=TABLE1[t];
TR0=1;
}
else TR0=0;
delay(tick);
k++;
}
TR0=0;
}
}
|