📄 02.htm
字号:
char
disk_error=0; //磁盘错误<BR><BR><BR>DPT
xdata dpt[4]; //磁盘分区表<BR>DBR xdata
dbr[4]; //DOS引导记录<BR><BR><BR>unsigned long int
xdata FAT_start_sector[4]; //FAT开始扇区<BR>unsigned
long int xdata
DATA_start_sector[4]; //数据开始扇区<BR><BR>unsigned char
mp3_file_exist=0;<BR><BR>unsigned char xdata
FAT_buffer[512]; //文件分配表FAT缓冲<BR><BR>////////////////////////////////////// 写扇区计数寄存器 ///////////////////////////////////////////<BR>void
write_IDE_sector_count(unsigned char
count)<BR>{<BR>write_IDE_8(IDE_Sector_Count,count);<BR>}<BR>/////////////////////////////////////////////////////////////////////////////////////////////////<BR><BR>///////////////////////////////// 读取一个FAT扇区,512字节保存在FAT_buffer[]中 ///////////////////////<BR>void
read_IDE_FAT_sector(unsigned long int LBA)<BR>{<BR>unsigned int
i;<BR>if(LBA>=(dpt[driver_number].start_sector+dpt[driver_number].total_sectors))return;<BR>write_IDE_LBA(LBA);<BR>write_IDE_sector_count(1);<BR>write_IDE_command(IDE_Read_Sectors);<BR>IDE_Address=IDE_Data;<BR>set_IDE_address();<BR>IDE_DATA_H=0xFF;<BR>IDE_DATA_L=0xFF;<BR>for(i=0;i<512;i++)<BR> {<BR> while(!IDE_IORDY);<BR> IDE_DIOR=0;<BR> FAT_buffer[i]=IDE_DATA_L;<BR> i++;<BR> FAT_buffer[i]=IDE_DATA_H;<BR> IDE_DIOR=1;<BR> }<BR>IDE_Address=IDE_Bus_Not_Use;<BR>set_IDE_address();<BR>IDE_DATA_L=0xFF;<BR>}<BR>///////////////////////////////////////////////////////////////////////////////////////////////<BR><BR>///////////////////////////////// 读取一个数据扇区,512字节保存在buffer[]中
//////////////////<BR>void read_IDE_sector(unsigned long int
LBA)<BR>{<BR>unsigned int
i;<BR>if(LBA>=(dpt[driver_number].start_sector+dpt[driver_number].total_sectors))return;<BR>write_IDE_LBA(LBA);<BR>write_IDE_sector_count(1);<BR>write_IDE_command(IDE_Read_Sectors);<BR>IDE_Address=IDE_Data;<BR>set_IDE_address();<BR>IDE_DATA_H=0xFF;<BR>IDE_DATA_L=0xFF;<BR>for(i=0;i<512;i++)<BR> {<BR> while(!IDE_IORDY);<BR> IDE_DIOR=0;<BR> buffer[i]=IDE_DATA_L;<BR> i++;<BR> buffer[i]=IDE_DATA_H; <BR> IDE_DIOR=1;<BR> }<BR>IDE_Address=IDE_Bus_Not_Use;<BR>set_IDE_address();<BR>IDE_DATA_L=0xFF;<BR>}<BR>///////////////////////////////////////////////////////////////////////////////////////////////<BR><BR>unsigned
int
play_count; //当前文件夹中播放曲号<BR><BR>///////////////////////////////////// 获取磁盘信息 /////////////////////////////////////////<BR>void
get_IDE_information(void)<BR>{<BR>unsigned int i;<BR>unsigned long
int
LBA=0;<BR>mp3_file_exist=0;<BR>LBA=0;<BR>read_IDE_sector(LBA);<BR>for(i=0;i<4;i++)<BR>{<BR> dpt[i].file_system_type=buffer[0x1C2+i*16]; //文件系统类型<BR> ((unsigned
char
*)&(dpt[i].start_sector))[3]=buffer[0x1C6+i*16];<BR> ((unsigned
char
*)&(dpt[i].start_sector))[2]=buffer[0x1C7+i*16];<BR> ((unsigned
char
*)&(dpt[i].start_sector))[1]=buffer[0x1C8+i*16];<BR> ((unsigned
char
*)&(dpt[i].start_sector))[0]=buffer[0x1C9+i*16]; //分区开始扇区<BR> ((unsigned
char
*)&(dpt[i].total_sectors))[3]=buffer[0x1CA+i*16];<BR> ((unsigned
char
*)&(dpt[i].total_sectors))[2]=buffer[0x1CB+i*16];<BR> ((unsigned
char
*)&(dpt[i].total_sectors))[1]=buffer[0x1CC+i*16];<BR> ((unsigned
char
*)&(dpt[i].total_sectors))[0]=buffer[0x1CD+i*16]; //分区总扇区<BR>}<BR><BR>if((buffer[510]!=0x55)||(buffer[511]!=0xAA))disk_error=1;<BR>LBA=dpt[0].start_sector; //C盘<BR>read_IDE_sector(LBA);<BR>DISK_CAPACITY[7]=buffer[0x0B];<BR>DISK_CAPACITY[6]=buffer[0x0C]; //每扇区字节数<BR>((unsigned
char
*)&(dbr[0].bytes_per_sectors))[0]=buffer[0x0C];<BR>((unsigned
char
*)&(dbr[0].bytes_per_sectors))[1]=buffer[0x0B]; //每扇区字节数<BR>dbr[0].sectors_per_cluster=buffer[0x0D]; //每簇扇区数<BR>((unsigned
char *)&(dbr[0].reserve_sectors))[1]=buffer[0x0E];<BR>((unsigned
char
*)&(dbr[0].reserve_sectors))[0]=buffer[0x0F]; //保留扇区数<BR>dbr[0].num_of_FAT=buffer[0x10]; //FAT副本数<BR>((unsigned
char *)&(dbr[0].FAT16_ROOT_num))[1]=buffer[0x11];<BR>((unsigned
char
*)&(dbr[0].FAT16_ROOT_num))[0]=buffer[0x12]; //FAT16文件系统的根目录数<BR>((unsigned
char *)&(dbr[0].small_sectors))[1]=buffer[0x13];<BR>((unsigned
char *)&(dbr[0].small_sectors))[0]=buffer[0x14];<BR>((unsigned
char
*)&(dbr[0].sectors_per_FAT16))[1]=buffer[0x16];<BR>((unsigned
char
*)&(dbr[0].sectors_per_FAT16))[0]=buffer[0x17];<BR>((unsigned
char *)&(dbr[0].hidden_sectors))[3]=buffer[0x1C];<BR>((unsigned
char *)&(dbr[0].hidden_sectors))[2]=buffer[0x1D];<BR>((unsigned
char *)&(dbr[0].hidden_sectors))[1]=buffer[0x1E];<BR>((unsigned
char *)&(dbr[0].hidden_sectors))[0]=buffer[0x1F];<BR>((unsigned
char *)&(dbr[0].large_sectors))[3]=buffer[0x20];<BR>((unsigned
char *)&(dbr[0].large_sectors))[2]=buffer[0x21];<BR>((unsigned
char *)&(dbr[0].large_sectors))[1]=buffer[0x22];<BR>((unsigned
char
*)&(dbr[0].large_sectors))[0]=buffer[0x23];<BR>DISK_CAPACITY[0]=buffer[0x23];<BR>DISK_CAPACITY[1]=buffer[0x22];<BR>DISK_CAPACITY[2]=buffer[0x21];<BR>DISK_CAPACITY[3]=buffer[0x20];<BR>((unsigned
char
*)&(dbr[0].sectors_per_FAT32))[3]=buffer[0x24];<BR>((unsigned
char
*)&(dbr[0].sectors_per_FAT32))[2]=buffer[0x25];<BR>((unsigned
char
*)&(dbr[0].sectors_per_FAT32))[1]=buffer[0x26];<BR>((unsigned
char
*)&(dbr[0].sectors_per_FAT32))[0]=buffer[0x27];<BR>((unsigned
char
*)&(dbr[0].root_cluster_num))[3]=buffer[0x2C];<BR>((unsigned
char
*)&(dbr[0].root_cluster_num))[2]=buffer[0x2D];<BR>((unsigned
char
*)&(dbr[0].root_cluster_num))[1]=buffer[0x2E];<BR>((unsigned
char
*)&(dbr[0].root_cluster_num))[0]=buffer[0x2F];<BR>if((buffer[510]!=0x55)||(buffer[511]!=0xAA))disk_error=2;<BR>FAT_start_sector[0]=dpt[0].start_sector+dbr[0].reserve_sectors;<BR>DATA_start_sector[0]=FAT_start_sector[0]+(dbr[0].num_of_FAT)*(dbr[0].sectors_per_FAT32);<BR>LBA=DATA_start_sector[0];<BR>driver_number=C_;<BR>current_dir.first_cluster_number=dbr[0].root_cluster_num;<BR>play_count=1;<BR>item_count=1;<BR>get_nst_item();<BR>}<BR>////////////////////////////////////////////////////////////////////////////////////////////////////////////<BR><BR>/*void
read_IDE_buffer(void)<BR>{<BR>write_IDE_command(IDE_Read_Buffer);<BR>}*/<BR><BR>/*void
write_IDE_buffer(void)<BR>{<BR>write_IDE_command(IDE_Write_Buffer);<BR>}*/<BR><BR>/*<BR>void
write_IDE_sector(unsigned long int LBA)<BR>{<BR>unsigned int
i;<BR>write_IDE_LBA(LBA);<BR>write_IDE_sector_count(1);<BR>write_IDE_command(IDE_Write_Sectors);<BR>IDE_Address=IDE_Data;<BR>set_IDE_address();<BR>for(i=0;i<512;i++)<BR> {<BR> while(!IDE_IORDY);<BR> IDE_DIOW=0;<BR> IDE_DATA_L=buffer[i];<BR> i++;<BR> IDE_DATA_H=buffer[i];<BR> IDE_DIOW=1;<BR> }<BR>wait_IDE_busy();<BR>IDE_Address=IDE_Bus_Not_Use;<BR>set_IDE_address();<BR>}<BR>*/<BR><BR>///////////////////////////////////////////// IDE
初始化 /////////////////////////////////////////<BR>void
IDE_initial(void)<BR>{<BR>unsigned char
i;<BR>reset_IDE();<BR>for(i=2;i<200;i++)dir_name[i]=0x2020;<BR>do<BR> {<BR> write_IDE_8(IDE_Drive_Head,0xE0);<BR> read_IDE_status();<BR> }while(IDE_BSY);<BR>wait_IDE_busy();<BR>write_IDE_8(IDE_Device_Control,0xFA);//没有中断模式f<BR>dir_name[0]='C'+0xA380;<BR>((unsigned
char *)dir_name)[2]=':';<BR>((unsigned char
*)dir_name)[3]='\\';<BR>folder_length=4;<BR>dir_length=folder_length;<BR>not_root_dir=0;<BR>get_IDE_information();<BR>}<BR>///////////////////////////////////////////////////////////////////////////////////////////////////////<BR><BR><BR><BR><BR>/*<BR> Initial.c
file<BR> Created by Computer-lov. Date:
2005.3.19<BR> Last edited date:
2005.5.31<BR> Copyright (c) 2005
Computer-lov<BR> version 1.1<BR>*/<BR><BR>#include
"Initial.h"<BR>#include "IDE.h"<BR>#include
"AT89C51SND1C.H"<BR>#include "keyboard.h"<BR>#include
"hardware.h"<BR>#include
"LCD.H"<BR><BR>//////////////////////////////////////////////////<BR>void
PLL_initial(void) //PLL初始化<BR>{<BR>//
PLLRDIV=0x02; //使用16M晶振,产生192M频率<BR>//
PLLNDIV=0x00;<BR>PLLRDIV=(0x5F)>>2;
//使用20M晶振,产生192M频率<BR>PLLNDIV=0x09;<BR>PLLCON=0xC8; //复位PLL<BR>PLLCON=0xC2; //使能PLL<BR>CKCON=0x01;<BR>while(!PLOCK); //等待PLL锁定<BR>}<BR>//////////////////////////////////////////////////<BR><BR>//////////////////////////////////////////////////<BR>void
RAM_initial(void) //RAM初始化<BR>{<BR>AUXR=0x0C; //禁止外部RAM,使用内部2KRAM<BR>}<BR>//////////////////////////////////////////////////<BR><BR>//////////////////////////////////////////////////<BR>void
interrupt_initial(void) //中断初始化<BR>{<BR>EA=0;<BR>EAUD=0;<BR>EMP3=0;<BR>ES=0;<BR>ET1=0;<BR>EX1=0;<BR>ET0=0;<BR>EX0=0;<BR><BR>IEN1=0x10;
//允许键盘中断<BR><BR>IPH0=0x00;
//优先级设置为默认<BR>IPH1=0x00;<BR>IPL0=0x00;<BR>IPL1=0x00;<BR>EA=1;<BR>}<BR>//////////////////////////////////////////////////<BR><BR>/*void
timer_initial(void)<BR>{<BR><BR>}*/<BR><BR><BR>//////////////////////////////////////////////////<BR>void
MP3_decoder_initial(void) //MP3解码器初始化<BR>{<BR>MP3CON=0x3F;<BR>MP3CLK=0x05; //MP3解码时钟为32MHz<BR>MP3_decoder_disen();
//先停止MP3解码器<BR>}<BR>//////////////////////////////////////////////////<BR><BR>//////////////////////////////////////////////////<BR>void
DAC_initial(void) //DAC初始化<BR>{<BR>AUDCON0=0x72; //
256Fs<BR>// AUDCON0=0x73;
//384Fs<BR>AUDCON1=0x00;<BR>}<BR>//////////////////////////////////////////////////<BR><BR>//////////////////////////////////////////////////<BR>void
keyboard_initial(void) //键盘初始化<BR>{<BR>KBCON=0x00; //低电平触发,允许中断<BR>KBSTA=0x80; //允许键盘从休眠模式唤醒<BR>}<BR>//////////////////////////////////////////////////<BR>void
USB_initial(void)<BR>{<BR>USBCLK = 0x03;<BR>USBCON = USBCON |
0x40;<BR>USBIEN =
0x00;<BR>}<BR>//////////////////////////////////////////////////<BR>void
system_initial(void) //系统开机初始化<BR>{<BR>IDE_DATA_L=IDE_Bus_Not_Use;<BR>IDE_ALE=1;<BR>IDE_ALE=0; //IDE数据总线初始化为高阻状态<BR>LCD_initial();<BR>PLL_initial();<BR>USB_initial();<BR>MP3_decoder_initial();<BR>RAM_initial();<BR>DAC_initial();<BR>keyboard_initial();<BR>IDE_initial();<BR>interrupt_initial();<BR>}<BR>//////////////////////////////////////////////////<BR><BR><BR><BR><BR>/*
keyboard.c file <BR> Created by Computer-lov. Date:
2005.3.19<BR> Last edited date:
2005.5.31<BR> Copyright (c) 2005
Computer-lov<BR> version 1.1<BR>*/<BR><BR>#include
"keyboard.h"<BR>#include
"AT89C51SND1C.H"<BR><BR>//////////////////////////////////////////////////<BR>unsigned
char key=0;<BR><BR><BR>void ISR_keyboard(void) interrupt
11 //键盘中断处理<BR>{<BR>unsigned char
key_press_status;<BR>key_press_status=KBSTA; //保存按键状态<BR>if(key)return; //如果上一次按键未处理,等待处理完后,再响应新的按键<BR>if(key_press_status
&
0x01){key=KEY_UP;} //散转<BR>if(key_press_status
& 0x02){key=KEY_FUN;}<BR>if(key_press_status &
0x04){key=KEY_DOWN;}<BR>if(key_press_status &
0x08){key=KEY_OK;}<BR>}<BR>//////////////////////////////////////////////////<BR><BR><BR><BR>/*
LCD.C File<BR> Created by Computer-lov. Date:
2005.3.19<BR> Last edited date:
2005.5.31<BR> Copyright (c) 2005
Computer-lov<BR> version 1.1<BR>*/<BR><BR>#include
"AT89C51SND1C.H"<BR>#include "hardware.h"<BR>#include
"LCD.H"<BR>#include "file_system.h"<BR>#include
"unicode.h"<BR><BR>unsigned char
black; //是否反显<BR><BR>////////////////////////// 等待LCD忙碌 ////////////////////////////////////////////////////////<BR>void
wait_LCD_busy(void)<BR>{<BR>do<BR> {<BR> LCD_DATA=0xFF;<BR> LCD_EN=0;<BR> LCD_RS=0;<BR> LCD_RW=1;<BR> LCD_EN=1;<BR> }while(LCD_DATA&0x80);<BR>}<BR>////////////////////////////////////////////////////////////////////////////////////////////////<BR><BR>//////////////////////////////////////// 写一个字节显示数据 ///////////////////////////////<BR>void
write_LCD_data(unsigned char
lcd_data)<BR>{<BR>wait_LCD_busy();<BR>LCD_RS=1;<BR>LCD_RW=0;<BR>LCD_EN=1;<BR>LCD_DATA=lcd_data;<BR>LCD_EN=0;<BR>LCD_DATA=0xFF;<BR>}<BR>//////////////////////////////////////////////////////////////////////////////////////////////<BR><BR>///////////////////////////////////////////////////////////////////////////////////////////////<BR>/*unsigned
char read_LCD_data(void)<BR>{<BR>unsigned char
read_data;<BR>wait_LCD_busy();<BR>LCD_DATA=0xFF;<BR>LCD_RS=1;<BR>LCD_RW=1;<BR>LCD_EN=1;<BR>read_data=LCD_DATA;<BR>LCD_EN=0;<BR>return
read_data;<BR>}*/<BR>////////////////////////////////////////////////////////////////////////////////////////////////<BR><BR>/////////////////////////// 写LCD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -