頻率可調(diào)的方波信號發(fā)生器設計及電路
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計時 8位自動裝載定時模式,T0計數(shù)p3.4的脈沖數(shù)
TH1=0x6; //250微秒溢出一次; 250(256-x)*12/12 -> x=6
TL1=0x6; //200Hz的半周期為2.5毫秒,要溢出中斷10次
EA=1; //開中斷
ET1=1;
TR1=1; //定時器T1
while(1)
{ key_val=scan_key(); //掃描按鍵
if (key_val!=key_val_old)
{ //說明有鍵按下或彈起
key_val_old=key_val;
if (key_val!=255)
{ //說明鍵按下
state_val=0; //清除連續(xù)按鍵標志
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 //說明鍵彈起
{ state_val=0; second=0;
}
}
else //一直按下或彈起
{ if (key_val!=255)
{ state_val=1; //連續(xù)按鍵
}
else
{state_val=0;} //沒有按鍵按下,一直處于彈起狀態(tài)
}
led_show(); //數(shù)碼管顯示,動態(tài)掃描
}
}//----方波發(fā)生器-----------------
本文引用地址:http://cafeforensic.com/article/172701.htm
DIY機械鍵盤相關(guān)社區(qū):機械鍵盤DIY
評論