標(biāo)題:
使用中斷,蜂鳴器實(shí)現(xiàn)音樂(lè)功能,為什么我的FrepSelect的值在數(shù)組中無(wú)法改變
[打印本頁(yè)]
作者:
1322804412
時(shí)間:
2022-12-18 13:14
標(biāo)題:
使用中斷,蜂鳴器實(shí)現(xiàn)音樂(lè)功能,為什么我的FrepSelect的值在數(shù)組中無(wú)法改變
#include <REGX51.H>
#include "Timer0.h"
void delay (int m);
sbit Beep=P3^6;
unsigned int code FrepTable[]={
63628,63731,63835,63928,64021,64103,64185,64260,64331,64400,64463,64528,
64580,64633,64684,64732,64777,64820,64860,64898,64934,64968,65000,65030,
65058,65085,65110,65134,65157,65178,65198,65217,65235,65252,65268,65283};
unsigned char Music[]={12,12,19,19,21,21,19,17,17,16,16,14,14,12};
unsigned int FrepSelect;
void main()
{
Timer0Init();
while(1)
{[url=]U[/url]
FrepSelect++;
delay(500);
}
}
void Timer0_Routine() interrupt 1
{
TL0=FrepTable[FrepSelect]%256;
TH0=FrepTable[FrepSelect]/256;
Beep=!Beep;
}
void delay (int m)
{
unsigned char i,j;
for (i=0;i<m;i++)
for (j=0;j<253;j++);
}
作者:
人中狼
時(shí)間:
2022-12-18 22:20
FrepSelect沒(méi)賦初值
作者:
wulin
時(shí)間:
2022-12-19 07:48
延時(shí)函數(shù)使用的數(shù)據(jù)類型不當(dāng),一旦實(shí)參m大于255就導(dǎo)致永遠(yuǎn)出不了for (i=0;i<m;i++)循環(huán)。
#include <REG51.H>
//#include "Timer0.h"
void delay (int m);
sbit Beep=P3^6;
unsigned int code FrepTable[]={
63628,63731,63835,63928,64021,64103,64185,64260,64331,64400,64463,64528,
64580,64633,64684,64732,64777,64820,64860,64898,64934,64968,65000,65030,
65058,65085,65110,65134,65157,65178,65198,65217,65235,65252,65268,65283};
unsigned char Music[]={12,12,19,19,21,21,19,17,17,16,16,14,14,12};
unsigned int FrepSelect;
void Timer0Init(void)
{
TMOD = 0x01;
TH0 = 0;
TL0 = 0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main()
{
Timer0Init();
while(1)
{//[url=]U[/url]
FrepSelect++;
delay(500);
}
}
void Timer0_Routine() interrupt 1
{
TL0=FrepTable[FrepSelect]%256;
TH0=FrepTable[FrepSelect]/256;
Beep=~Beep;
}
void delay (int m)
{
int i,j;
for (i=0;i<m;i++)
for (j=0;j<253;j++);
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1