蜂鳴器仿真
0.png (24.29 KB, 下載次數: 103)
下載附件
2017-1-2 23:42 上傳
- #include "reg51.h"
- sbit P1_3=P1^3;
- unsigned char code 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,
- 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,0};
- unsigned int code TABLE1[]={64260,64400,64524,64580,64684,64777,64820,64898,
- 64968,65030,65058,65110,65157,65178,65217 } ;
- unsigned char th0_temp,tl0_temp;
- void SING(unsigned char hi);
- void DELAY(unsigned char lo);
- main()
- {unsigned char i,hi,lo,coute;
- TMOD= 0X01;
- ET0 = 1;
- EA = 1;
- TR0 = 1;
- while(1)
- {
- P1_3= 1;
- coute= 0;
-
- while(TABLE[coute]!=0)
- {
- i=TABLE[coute];
- coute++;
- lo=i&0x0f;
- hi=(i&0xf0)>>4;
- if(hi>0)
- SING(hi);
- else
- TR0=0;
- DELAY(lo);
- }
- }
- }
- void SING(unsigned char hi)
- {
- th0_temp=(TABLE1[hi-1]/256);
- TH0=th0_temp;
- tl0_temp=(TABLE1[hi-1]%256);
- TL0=tl0_temp;
- TR0=1;
- }
- void DELAY(unsigned char lo)
- {
- unsigned char temp1,temp2;
- do
- {
- for(temp1=0;temp1<150;temp1++)
- for(temp2=0;temp2<200;temp2++);
- }while(lo--);
- }
- void INTT0() interrupt 1
- {
- TH0=th0_temp;
- TL0=tl0_temp;
- P1_3=~P1_3;
- }
復制代碼
0.png (75.05 KB, 下載次數: 104)
下載附件
2017-1-2 23:43 上傳
|