|
本帖最后由 yoxi 于 2020-8-21 15:13 編輯
拿去不謝
#include<reg52.h>
sbit beep=P1^5;
unsigned int count0=0;
void T0_Init()
{
P1 = 0;
TMOD=0x01;
TL0=0x50;
TH0=0xc3; //50ms,12MHz
ET0=1;
EA=1;
TR0=1;
}
// void beep_Hz() //兩括號都不一樣,你還說能過?
//{
//while(1);
//}
void main()
{
beep=0;
T0_Init();
while(1)
{
;
}
}
void T_0() interrupt 1
{
TF0 = 0;
TL0 = 0x50;
TH0 = 0xc3;
count0++;
if(count0==40)
{
count0=0;
TR0 =0;
TL0 = 0x50;
TH0 = 0xc3;
beep=~beep;
}
TF0 = 1;
}
|
|