頻率可調(diào)的方波信號(hào)發(fā)生器設(shè)計(jì)
else
{ hz_shu=200; }
T1_over_num=get_T1_over_num(hz_shu);
break;
case 1: if(hz_shu>10)
{ hz_shu=hz_shu-10; } //減10/秒
else
{ hz_shu=1;}
T1_over_num=get_T1_over_num(hz_shu);
break;
}
TR1=1;
}
}
}
}
//-------------------------
main()
{pulse_out=0; //初始化各變量
hz_shu=5;
T1_cnt=0;
state_val=0;
second=0;
sec_over_num=0;
T1_over_num=get_T1_over_num(hz_shu);
//初始化51的寄存器
TMOD=0x20;//用T1計(jì)時(shí) 8位自動(dòng)裝載定時(shí)模式,T0計(jì)數(shù)p3.4的脈沖數(shù)
TH1=0x6; //250微秒溢出一次; 250(256-x)*12/12 -> x=6
TL1=0x6; //200Hz的半周期為2.5毫秒,要溢出中斷10次
EA=1; //開(kāi)中斷
ET1=1;
TR1=1; //定時(shí)器T1
while(1)
{ key_val=scan_key(); //掃描按鍵
if (key_val!=key_val_old)
{ //說(shuō)明有鍵按下或彈起
key_val_old=key_val;
if (key_val!=255)
{ //說(shuō)明鍵按下
state_val=0; //清除連續(xù)按鍵標(biāo)志
sec_over_num=0;
switch (key_val)
{ case 0: //增1鍵
hz_shu++;
T1_over_num=get_T1_over_num(hz_shu);
break;
case 1: //減1鍵
if(hz_shu>=2)
{hz_shu--;}
else
{hz_shu=1;}
T1_over_num=get_T1_over_num(hz_shu);
break;
}
}
else //說(shuō)明鍵彈起
{ state_val=0; second=0;
}
}
else //一直按下或彈起
{ if (key_val!=255)
{ state_val=1; //連續(xù)按鍵
}
else
{state_val=0;} //沒(méi)有按鍵按下,一直處于彈起狀態(tài)
}
led_show(); //數(shù)碼管顯示,動(dòng)態(tài)掃描
}
}//----方波發(fā)生器-----------------
本文引用地址:http://2s4d.com/article/170862.htm 負(fù)離子發(fā)生器相關(guān)文章:負(fù)離子發(fā)生器原理
評(píng)論