频率转换公式为什么是这样的啊:frq_num = ((Count *65535+Hdata * 256+Ldata) *108 / 100) 关键是*108/100这部分
源代码:
/*********************************************************
* *
* 主函数 *
* *
*********************************************************/
void main()
{
unsigned char m;
unsigned long frq_num;
P3 = 0xff;
lcd_init();
lcd_pos(0x00); //设置显示位置为第一行
for (m = 0; m < 16; m++)
lcd_wdat(cdis1[m]);
//显示字符
lcd_pos(0x40); //设置显示位置为第二行
for (m = 0; m < 16; m++)
lcd_wdat(cdis2[m]);
//显示字符
TMOD = 0x51; //定时器0工作在定时方式
//定时器1工作在计数方式
TH0 = 0x4c; //50ms定时
TL0 = 0x00;
TH1 = 0x00; //计数初值
TL1 = 0x00;
ET0 = 1; //使能
tiMER0中断
ET1 = 1; //使能TIMER1中断
EA = 1; //允许中断
PT1 = 1; //定义TIMER1中断优先
TR0 = 1;
TR1 = 1;
while (1)
{
if (sec)
{
Hdata = TH1; //取计数值
Ldata = TL1;
frq_num = ((Count *65535+Hdata * 256+Ldata) *108 / 100);
TH1 = 0;
TL1 = 0;
sec = 0;
Count = 0;
TR1 = 1;
TR0 = 1;
}
temp = frq_num;
play();
}
}
/**********************************************************
* *
* Time0中断函数 *
* *
**********************************************************/
void Time0()interrupt 1
{
TH0 = 0x4c; //50ms定时
TL0 = 0x00;
msec++;
if (msec == 20)
//50*20=1S
{
TR0 = 0; //关闭TIMER0
TR1 = 0; //关闭TIMER1
msec = 0;
sec = 1; //置秒标记位
}
}
/**********************************************************
* *
* Time1中断函数 *
* *
**********************************************************/
void Time1()interrupt 3
{
Count++;
}
/*********************************************************/
一周热门 更多>