uClinux的应用程序写成以下形式,就像没有前后台程序一样,能不能正常运行?请指教。
#define DO_L 262
#define DOJ_L 277
#define RE_L 294
#define REJ_L 311
#define MI_L 330
#define FA_L 349
#define FAJ_L 370
#define SO_L 393
#define SOJ_L 415
#define LA_L 440
#define LAJ_L 466
#define SI_L 494
#define DO 523
#define DOJ 554
#define RE 587
#define REJ 622
#define MI 659
#define FA 698
#define FAJ 740
#define SO 785
#define SOJ 831
#define LA 880
#define LAJ 932
#define SI 988
#define DO_H 1047
#define DOJ_H 1109
#define RE_H 1174
#define REJ_H 1245
#define MI_H 1318
#define FA_H 1379
#define FAJ_H 1480
#define SO_H 1568
#define SOJ_H 1661
#define LA_H 1760
#define LAK_H 1865
#define SI_H 1976
#define rPCONE (*(volatile unsigned *)0x1d2002
#define rPDATE (*(volatile unsigned *)0x1d2002c)
#define rPUPE (*(volatile unsigned *)0x1d20030)
#define rTCFG0 (*(volatile unsigned *)0x1d50000)
#define rTCFG1 (*(volatile unsigned *)0x1d50004)
#define rTCON (*(volatile unsigned *)0x1d5000
#define rTCNTB0 (*(volatile unsigned *)0x1d5000c)
#define rTCMPB0 (*(volatile unsigned *)0x1d50010)
#define rTCNTO0 (*(volatile unsigned *)0x1d50014)
#define rTCNTB1 (*(volatile unsigned *)0x1d5001
#define rTCMPB1 (*(volatile unsigned *)0x1d5001c)
#define rTCNTO1 (*(volatile unsigned *)0x1d50020)
#define rTCNTB2 (*(volatile unsigned *)0x1d50024)
#define rTCMPB2 (*(volatile unsigned *)0x1d5002
#define rTCNTO2 (*(volatile unsigned *)0x1d5002c)
#define rWTCON (*(volatile unsigned *)0x1d30000)
#define rWTDAT (*(volatile unsigned *)0x1d30004)
#define rWTCNT (*(volatile unsigned *)0x1d3000
typedef struct sct_music{
U8 count;
U16 frq[120];
U8 JiePai[120];
}STC_MUSIC;
STC_MUSIC const music1={
46,//音符个数
{//频率
MI,SO,LA,LA,SO,LA,MI,RE,MI,SO,LA,LA,SO,LA,MI,MI,SO,LA,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4,1, 2, 1, 1, 2, 2, 4,4,4,2,2, 2, 2, 2,
2, 2, 2, 2, 2, 1, 1,2, 2, 2, 2, 2, 4, 2,2,2,2, 1,2,2,2,2,2,2,4, 4, 4, 1, 1, 2, 2,
2, 2, 4, 4, 2, 2, 2, 4, 2, 1, 4, 4, 2, 2, 2, 2, 4, 4, 4,
4
}
};
static int delayLoopCount=400;
void Delay(int time)
// time=0: adjust the Delay function by WatchDog timer.
// time>0: the number of loop time
// 100us resolution.
{
int i,adjust=0;
if(time==0)
{
time=200;
adjust=1;
delayLoopCount=400;
rWTCON=((MCLK/1000000-1)<<|(2<<3); // 1M/64,Watch-dog,nRESET,interrupt disable
rWTDAT=0xffff;
rWTCNT=0xffff;
rWTCON=((MCLK/1000000-1)<<|(2<<3)|(1<<5); // 1M/64,Watch-dog enable,nRESET,interrupt disable
}
for(;time>0;time--)
for(i=0;i<delayLoopCount;i++);
if(adjust==1)
{
rWTCON=((MCLK/1000000-1)<<|(2<<3);
i=0xffff-rWTCNT; // 1count/16us?????????
delayLoopCount=8000000/(i*64); //400*100/(i*64/200)
}
}
void SetBeepPwm(unsigned short Freq, unsigned char HiRatio)
{
if(HiRatio>100)
HiRatio = 100;
rTCON &= 0xffff0fff; // clear manual update bit, stop Timer2
rTCFG0 &= 0xffff00ff; // set Timer 2&3 prescaler 0
rTCFG1 &= 0xfffff0ff; // set Timer 2 MUX 1/16
rTCFG1 |= 0x00000300;
rTCNTB2 = MCLK/(Freq*16); //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
rTCMPB2 = (rTCNTB2*(100-HiRatio))/100; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
rTCON |= 0x00002000; // manual update
rTCON &= 0xffff0fff; // clear manal update bit
rTCON |= 0x0000d000; // auto reload, inverter on, start Timer 2
}
void StopBeepPwm(void)
{
rTCON &= ~0x1000;
}
void Music(U8 num)
{
U8 i;
U8 k;
rPDATE = 0x157; //Beep = 10
rPCONE = 0x596b; // tout2
rPUPE = 0xff;
for(i=0;i<music1.count;i++)
{
SetBeepPwm(music1.frq, 50);
Delay(music1.JiePai*3000); }
StopBeepPwm();
}
int Main(int argc, char **argv[])
{
while(1){
if(k>0&&k<5)
{
Music(k);
}
}
} |