keil中,这段语句怎么更简洁的表达switch(music_num){case 0:M(song1[i][0],song1[i][1],music_pause|music_stop);IO_vWritePort(P5,0x07); if(music_stop) i=0;else if(music_pause);else if(song1[i][0]==ED) i=0;else {i++;IO_vWritePort(P5,0x06);}brea
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 13:32:12
keil中,这段语句怎么更简洁的表达switch(music_num){case 0:M(song1[i][0],song1[i][1],music_pause|music_stop);IO_vWritePort(P5,0x07); if(music_stop) i=0;else if(music_pause);else if(song1[i][0]==ED) i=0;else {i++;IO_vWritePort(P5,0x06);}brea
keil中,这段语句怎么更简洁的表达
switch(music_num)
{
case 0:
M(song1[i][0],song1[i][1],music_pause|music_stop);
IO_vWritePort(P5,0x07);
if(music_stop) i=0;
else if(music_pause);
else if(song1[i][0]==ED) i=0;
else {i++;IO_vWritePort(P5,0x06);}
break;
case 1:
M(song2[i][0],song2[i][1],music_pause|music_stop);
IO_vWritePort(P5,0x0B);
if(music_stop) i=0;
else if(music_pause);
else if(song2[i][0]==ED) i=0;
else {i++;IO_vWritePort(P5,0x0A);}
break;
case 2:
M(song3[i][0],song3[i][1],music_pause|music_stop);
IO_vWritePort(P5,0x0D);
if(music_stop) i=0;
else if(music_pause);
else if(song3[i][0]==ED) i=0;
else {i++;IO_vWritePort(P5,0x0C);}
break;
default:break;
}
能不能用一个
M(song3[i][0],song3[i][1],music_pause|music_stop);
IO_vWritePort(P5,0x0D);
if(music_stop) i=0;
else if(music_pause);
else if(song3[i][0]==ED) i=0;
else {i++;IO_vWritePort(P5,0x0C);}
这样的语句,用指针来简洁的表达?
keil中,这段语句怎么更简洁的表达switch(music_num){case 0:M(song1[i][0],song1[i][1],music_pause|music_stop);IO_vWritePort(P5,0x07); if(music_stop) i=0;else if(music_pause);else if(song1[i][0]==ED) i=0;else {i++;IO_vWritePort(P5,0x06);}brea
可以把这些部分放在一个函数里,参数传递song常数数组的指针,IO_vWritePort的第二个参数两次,返回i的改变
不知道你的单片机是什么类型的,如果是51,处理指针是弱项,最好加存储空间指定,看看会不会精简一点,不过不管怎么说,维护起来会变得更简单些了
typedef unsigned char u_char;
u_char SongPro(u_char *pSong,u_char bIndex,u_char bPortStat1,u_char bPortStat2)
{
M(pSong[0],pSong[1],music_pause|music_stop);
IO_vWritePort(P5,bPortStat1);
if(music_stop) bIndex=0;
else if(music_pause);
else if(pSong[0]==ED) bIndex=0;
else {bIndex++;IO_vWritePort(P5,bPortStat2);}
return bIndex;
}
switch(music_num)
{
case 0:
i = SongPro(song1[i],i,0x07,0x06);
break;
case 1:
i = SongPro(song2[i],i,0x0b,0x0a);
break;
case 2:
i = SongPro(song3[i],i,0x0d,0x0c);
break;
default:
break;
}