📄 main.c
字号:
#include "dp8051.h"
#include "config.h"
#include "absacc.h"
#include "constant.h"
#include "variable.h"
#include "function.h"
#include "sdhost.h"
#include "sssmp3_regs.h"
#include "fat.h"
#include "mp3_appl.h"
//***********************************************
//***********************************************
/************************************************
函 数 名: InitTimer0()
功 能:初始化Timer0
说 明:
调 用:
全局变量:
入口参数:无
出口参数:无
返 回 值:无
************************************************/
void InitTimer0(void)
{
TMOD = ((TMOD & 0xF0) | 0x01);
TH0 = 0xD8;//0x3C;//CPU_CLK=12MHz, 12/12=1us,Mason@1019
TL0 = 0xF0;//0xB0;//count-up to 0xffff and then Interrupt in every 50 ms
ET0 = 1;
TR0 = 1;
}
/************************************************
函 数 名: InitPort()
功 能:初始化port
说 明:
调 用:
全局变量:
入口参数:无
出口参数:无
返 回 值:无
************************************************/
void InitPort(void)
{
SDSPITIMER = SD_MODE;// enable SD Card reader mode
P3DIR = 0xE0;
#if TX_DEBUG
P1DIR = BIT5;
#else
P1DIR = 0x00;
#endif
IO_PORT1_0 = 0x10;
IO_PORT1_1 = 0x10;
IO_PORT1_2 = 0x10;
IO_PORT1_3 = 0x10;
IO_PORT1_4 = 0x10;
#if !TX_DEBUG
IO_PORT1_5 = 0x10;
#endif
IO_PORT1_6 = 0x10;
IO_PORT1_7 = 0x10;
}
/************************************************
函 数 名: LedFlash()
功 能:LED闪烁
说 明:
调 用:
全局变量:
入口参数:闪烁间隔时间
出口参数:无
返 回 值:无
************************************************/
void LedFlash(U8 Led_time)
{
U8 xdata i = 0;
P1_1 = 0;
P1DIR |= BIT1;
Timer0_Flag = 0;
InitTimer0();
EA = 1;
while(1)
{
if(Timer0_Flag)
{
Timer0_Flag = 0;
if(++i >= Led_time)
{
i = 0;
P1_1 ^= 1;
}
}
}
}
/************************************************
函 数 名: CharToLong()
功 能:
说 明:
调 用:
全局变量:
入口参数:
出口参数:无
返 回 值:无
************************************************/
U32 CharToLong(U8 xdata *p)
{
U32 i = 0;
i = (U32)*p++;
i += (U32)*p++ << 8;
i += (U32)*p++ << 16;
i += (U32)*p << 24;
return i;
}
/************************************************
函 数 名: LongToChar()
功 能:
说 明:
调 用:
全局变量:
入口参数:
出口参数:无
返 回 值:无
************************************************/
#if TX_DEBUG
void LongToChar(U8 xdata *p, U32 shuju)
{
*p++ = (U8)shuju;
*p++ = (U8)(shuju >> 8);
*p++ = (U8)(shuju >> 16);
*p = (U8)(shuju >> 24);
}
#endif
/************************************************
函 数 名: IntToChar()
功 能:
说 明:
调 用:
全局变量:
入口参数:
出口参数:无
返 回 值:无
************************************************/
#if TX_DEBUG
void IntToChar(U8 xdata *p, U16 shuju)
{
*p++ = (U8)shuju;
*p = (U8)(shuju >> 8);
}
#endif
/************************************************
函 数 名: main()
功 能:主函数
说 明:
调 用:
全局变量:
入口参数:无
出口参数:无
返 回 值:无
************************************************/
void main(void)
{
//U32 idata address = 0x100000L,j;
//far U8 *p;
U8 data i;
WTST = 0;// Program Wait States ,for testing Ex_ROM
CKCON = 3;// XDATA Wait States
InitPort();
#if TX_DEBUG
I2STXRX = TXD_PIN_EN;//enable TX
InitUart();
#endif
MP3_PrevInit();
CLASS_D_VOL_CTL = 0x22;
MP3_VOLUME = 0;
//InitTimer0();
i = 0;
if(i)
{
if(!check_nor_flash())
{
#if TX_DEBUG
SendChar(0x90);
#endif
LedFlash(5);
}
if(!check_sram())
{
#if TX_DEBUG
SendChar(0x91);
#endif
LedFlash(5);
}
//***********************************************
//***********************************************
//*p = 0;
//if(*p)
{
DMA_write_sector(0, 0x06);
}
}
// SD_CD = 1;
// P1DIR &= ~BIT7;
// if(!SD_CD)
{
SD_SysInit();
if(InitFat())
{
//非FAT格式
LedFlash(50);
}
else
{
#if TX_DEBUG
CreateFile();
SendChar(0xD5);
#endif
if(CFatData.fFAT32)
FileData.dwCurCluNo = 0;
FileData.wCurFDBNo = 0;
if(!Forward())
{
//无MP3文件
LedFlash(50);
}
}
}
/* else
{
#if TX_DEBUG
SendChar(0x95);
#endif
//未插SD卡
LedFlash(50);
}*/
varAl.CardDetected = 1;
varAl.SystemFlag = 0;
mp3_play_status = MP3_IDEL;
Timer0_Flag = 0;
InitTimer0();
EA = 1;
allow_mp3_play = 1;
while(1)
{
if(MP3_ISR_Flag)
{
MP3_ISR_Flag = 0;
MP3_deal();
}
if(Timer0_Flag)
{
Timer0_Flag = 0;
#if KEY
GetKey();
#endif
}
#if KEY
if(varAl.SysKey != NO_VALUE)
{
KeyDeal();
varAl.SysKey = NO_VALUE;
}
#endif
MP3_Play_Task();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -