📄 task._c
字号:
//ICC-AVR application builder : 2005-11-12 17:11:59
// Target : M16
// Crystal: 8.0000Mhz
// copyright:鲁军波(endylu)
#include <iom16v.h>
#include <macros.h>
#include "main.h"
extern uint8 timer1_over;
extern uint8 key_value;
extern uint8 set_volume;
extern uint8 MP3_all_number;
extern uint8 MP3_current_number;
extern uint8 play_state;
extern MP3_INFO mp3_info;
extern FAT_INFO fat_info;
extern uint32 CHINALIB_point;
extern uint32 UNICODE_point;
extern uint8 buffer[512];
//extern const uint8 BassTrebleTable[48];
uint8 SONG_state=song_over;
uint8 secperclus; //对下面显示歌词的时间有关
uint8 disp_state=5;
uint8 STA013_INIT=1;
//=======================================================================
void SONG_task(void)
{
static uint32 new_Sec;
static uint16 bytepersec;
static uint16 file_Clus_allnumber;
static uint16 file_Clus_sendnumber;
uint32 FAT_Clus;
uint8 doing;
static uint8 doing1;
switch(SONG_state)
{
case song_stop:
{
break;
}
case song_start:
{
file_Clus_allnumber=((mp3_info.DIR_Filesize[0]>>1)+((int)(mp3_info.DIR_Filesize[1])<<7))/(fat_info.BPB_SecPerClus)+1; //多少簇
new_Sec=(((long)(mp3_info.DIR_FstClusL[1])<<8)+(mp3_info.DIR_FstClusL[0])-2)*fat_info.BPB_SecPerClus+fat_info.FirstDateSecter; //簇的头扇区号
file_Clus_sendnumber=0;
SONG_state=song_read_sector;
secperclus=fat_info.BPB_SecPerClus;
break;
}
case song_find_newsec:
{
FAT_Clus=((long)(fat_info.Relative+fat_info.BPB_RsvdSecCnt+mp3_info.DIR_FstClusL[1])<<9)+((int)mp3_info.DIR_FstClusL[0]<<1);
SD_read_sector2(FAT_Clus,mp3_info.DIR_FstClusL,2);
new_Sec=((long)(mp3_info.DIR_FstClusL[1])<<8)+mp3_info.DIR_FstClusL[0];
if(new_Sec>=0xfff8)
SONG_state=song_over;
else
{new_Sec=(new_Sec-2)*(fat_info.BPB_SecPerClus)+fat_info.FirstDateSecter; //簇的头扇区号
doing=((long)file_Clus_sendnumber*80)/file_Clus_allnumber;
if(doing1!=doing)
{
LCD_set_XY(doing+1,4);
LCD_write_byte(0x5d,1);
doing1=doing;
}
file_Clus_sendnumber++;
SONG_state=song_read_sector;
secperclus=fat_info.BPB_SecPerClus; //每簇多少扇区
}
break;
}
case song_read_sector:
{
if(secperclus--)
{
SD_start_read(new_Sec++);
SD_get_date(buffer,512);
SONG_state=song_send_frame;
bytepersec=0;
}
else
SONG_state=song_find_newsec;
break;
}
case song_send_frame:
{
STA013_Enable();
while(sta_Demand()) //每次连续请求6ms,隔20ms才又来请求
{
Write_Byte_SD(*(buffer+bytepersec++));
if(bytepersec==512)
{SONG_state=song_read_sector;
break;
}
}
STA013_Disable();
break;
}
case song_over:
{
doing1=0;
MP3_current_number++;
if(MP3_current_number>MP3_all_number)
MP3_current_number=1;
GEPAI();
JINGDU();
ASCII(buffer,MP3_current_number);
LCD_write_String(8,5,2,buffer,0);
MP3_Directory(MP3_current_number);
if(mp3_info.Name_number==0)
if((UNICODE_point>0)&(CHINALIB_point>0))
LCD_write_String(6,2,8,buffer,0);
if((MP3_current_number==1)|(play_state==0))
{SONG_state=song_stop;
if(play_state!=2)
{play_state=0;
LCD_write_tubiao(0,5,0);
}
}
else
{SONG_state=song_start;
}
disp_state=5;
break;
}
}
}
//=======================================================================
void KBOD_task(void)
{
if(key_value!=0)
{
switch(key_value)
{
case volume_add:
{
if(set_volume<8)
{set_volume++;
}
LCD_set_XY(59,5);
key_value=set_volume*3;
while(key_value--)
{
LCD_write_byte(0x5A,1);
}
sta_SetVolume(59+set_volume*5,1);
key_value=0;
break;
}
case volume_sub:
{
if (set_volume>1)
{set_volume--;
}
LCD_set_XY(59+set_volume*3,5);
key_value=3;
while(key_value--)
{
LCD_write_byte(0x42,1);
}
sta_SetVolume(59+set_volume*5,1);
key_value=0;
break;
}
case next:
{
sta_StartDecoder();
if(play_state==2)
sta_PauseDecoder();
sta_SetVolume(59+set_volume*5,1);
SONG_state=song_over;
key_value=0;
disp_state=5;
break;
}
case back:
{
if(MP3_current_number==1)
MP3_current_number=MP3_all_number-1;
else
MP3_current_number=MP3_current_number-2;
sta_StartDecoder();
if(play_state==2)
sta_PauseDecoder();
sta_SetVolume(59+set_volume*5,1);
SONG_state=song_over;
key_value=0;
disp_state=5;
break;
}
case play:
{
key_value=0;
play_state++;
switch(play_state)
{
case 1: //播放
{
if(STA013_INIT)
{sta_Init();
sta_StartDecoder();
sta_SetVolume(59+set_volume*5,1);
STA013_INIT--;
}
SONG_state=song_start;
LCD_write_tubiao(0,5,1);
break;
}
case 2: //暂停
{
sta_PauseDecoder();
LCD_write_tubiao(0,5,2);
break;
}
case 3: //继续
{
play_state=1;
sta_ResumeDecoder();
LCD_write_tubiao(0,5,1);
break;
}
}
break;
}
}
}
}
//=======================================================================
void DISP_task(void)
{
static uint8 disp_point;
static uint16 disp_number;
static uint16 disp_i;
static uint8 disp_j;
static uint8 buffer_h[72];
static uint8 buffer_l[72];
static uint8 piont_24_code[24];
uint8 n;
uint8 m;
if(mp3_info.Name_number)
{
if(timer1_over)
{
timer1_over=0;
switch(disp_state)
{case 0:
{
for(n=0;n<mp3_info.Name_number;n++)
{
if(mp3_info.NAME[n]<0x0060)
disp_number+=6;
else
disp_number+=12;
}
disp_state=1;
break;
}
case 1:
{
if(disp_i>=disp_number)
{
buffer_h[disp_point]=0;
buffer_l[disp_point]=0;
}
else
{
if((disp_i%6)==0)
{
for(m=0,n=0;n<disp_i;)
{
if(mp3_info.NAME[m++]<0x0060)
n+=6;
else
n+=12;
}
if(n==disp_i)
{Abtain_code(m,piont_24_code);
disp_j=0;
}
}
buffer_h[disp_point]=piont_24_code[disp_j];
buffer_l[disp_point]=piont_24_code[disp_j+12];
}
disp_j++;
disp_state=3;
break;
}
case 3:
{
LCD_set_XY(6,2);
for (n=0; n<72; n++)
{
if(++disp_point>71)
{disp_point=0;
}
LCD_write_byte(buffer_h[disp_point],1);
}
LCD_set_XY(6,3);
for (n=0; n<72; n++)
{
if(++disp_point>71)
{disp_point=0;
}
LCD_write_byte(buffer_l[disp_point],1);
}
if(++disp_point>71)
disp_point=0;
disp_state=4;
break;
}
case 4:
{
if(++disp_i==(72+disp_number))
disp_i=0;
disp_state=1;
break;
}
case 5:
{
for(n=0;n<72;n++)
{
buffer_h[n]=0;
buffer_l[n]=0;
}
disp_point=0;
disp_number=0;
disp_i=0;
disp_j=0;
disp_state=0;
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -