📄 main.c
字号:
}
void DispMemInfo()
{
ClearLcdRam(0x40);
WriteEn("Memory Info",3,15);
WriteEn("64M Byte",1,20);
}
void SysIni(void)
{
XBYTE[0x0a] |= 0x20;
XBYTE[CLKGATE_CTRL_L] = 0x0f8;
XBYTE[CLKGATE_CTRL_M] = 0x32;
Write(CLKGATE_CTRL_H,0x8d);
//XBYTE[EGPIO_SEL]=XBYTE[EGPIO_SEL]|0X10;//gpio04,31pin,not used
//XBYTE[EGPIO_CTRL]=XBYTE[EGPIO_CTRL]|0X10;
//XBYTE[EGPIO_OUT]=XBYTE[EGPIO_OUT]&0Xef; //reset DAC and ADC
//_nop_();_nop_();
//XBYTE[EGPIO_OUT]=XBYTE[EGPIO_OUT]|0X10; //reset DAC and ADC
XBYTE[EGPIO_SEL] |=0x03;//gpio00,01
XBYTE[EGPIO_CTRL] |=0x03;//all out put pin
XBYTE[EGPIO_SEL+3] |=0x88;//gpio27,gpio31
XBYTE[EGPIO_CTRL+3] |=0x88;//all out put pin
XBYTE[EGPIO_SEL+1]=XBYTE[EGPIO_SEL+1]|0X10;//gpio12,34pin,smc_wp,
XBYTE[EGPIO_CTRL+1]=XBYTE[EGPIO_CTRL+1]|0X10;
XBYTE[EGPIO_OUT+1]=XBYTE[EGPIO_OUT+1]&0Xef;
//WP=0;
XBYTE[EGPIO_SEL+2]=XBYTE[EGPIO_SEL+2]|0X80;//gpio23
XBYTE[EGPIO_CTRL+2]=XBYTE[EGPIO_CTRL+2]|0X80;
XBYTE[EGPIO_OUT+2]=XBYTE[EGPIO_OUT+2]&0X7f;//disable battle detect
XBYTE[EGPIO_SEL+3]=XBYTE[EGPIO_SEL+3]|0X46;
XBYTE[EGPIO_CTRL+3]=XBYTE[EGPIO_CTRL+3]|0X06;
XBYTE[EGPIO_OUT+3]=XBYTE[EGPIO_OUT+3]|0x02;//power on
XBYTE[EGPIO_CTRL+3]=XBYTE[EGPIO_CTRL+3]&0Xbf; //mmc_dect
MemoryRw;
SmcRead(3199);
McuRw;
/*RepMode = 0;
Volumn = 0;
BackLight= 1;
EqMode = 1;*/
//Volumn = XBYTE[0x1001];
RepMode = XBYTE[0x1000];
Vol= XBYTE[0x1001];
BackLight = XBYTE[0x1002];
EqMode = XBYTE[0x1003];
Write(CLK_SEL,0x03);//Actual Freq MCU=24M,DSP=48M
}
//-----------------------------------
//interrupt initial
//input none
//output none
void IntrIni(void)
{
IE = 0x03;
TMOD=0x01; //set timing mode
TH0=0xf8;
TL0=0x00; //set 1ms time
TR0=1; //open time0 interrupt
ET1=1; //open T0 interrupt
EX0=1; //int0 enable
Key = 1;
EX1=0;
IT0=0; //int0 is level trige
IP = 0x01; //set priority
Write(MCU_IER_L,0x08); //music ram empty,idma interrupt enable
Write(MCU_IER_H,0); //card interrupt enable
IE = 0X83; //open all interrupt
P1 &= 0xF0;
}///////////////////////////////////////////////////////////////////////////////
void intr0() interrupt 0 using 2 //int0 all local device interrupt
{
ET0=0;
if(XBYTE[MCU_ISR]&DATA_INT)
{
if (Playing|Recing)
DataRequestFg=1;
XBYTE[MCU_ISR]= DATA_INT;//CLEAR INT FLAG
}
ET0=1;
}
void intr1() interrupt 1 using 3 //1ms timer interupt
{
#ifdef OSC12
TH0=0xfc;
TL0=0x18; //set 1ms time
#else
TH0=0xf8;
TL0=0x00; //set 1ms time
#endif
TR0 = 1; //open time0 interrupt
if(KeyTimer<2000)KeyTimer++;
if (Ms1Count) Ms1Count--;
else
{
if((!Command)&&((Playing !=0)||(Recing!=0)))
{
Command=TIME_SECOND;
Ms1Count=200;
}
}
if(MenuItem!=0)
if(MenuConTime!=3000)MenuConTime++;
if(VolumnCh)
if(VolumnConTime!=1000)VolumnConTime++;
if(BkMode)
if(BackLightTime!=0)
BackLightTime--;
if(CloseFlg)
if(CloseTime !=0)
CloseTime--;
if(BattTestTime!=1000)BattTestTime++;
}
//////////////////////////////////////////////////////////////////////////////
/*void intr2() interrupt 2 using 3 //int1 keyboard interrupt
{
IntEntry=1;
}*/
//=============================================================================
//input:index file number
//input : FileType 1: mp3 2: pcm
//return : file name length
//=============================================================================
/*void GetFileName(char *FileBuf,unsigned char Index,unsigned char FileType)
{
xdata unsigned char Count,N = 0;
GetFcb(&FcbTable,Index,FileType,RepFirstCluster);
LogicA.Cluster=FcbTable.FctAddr.Cluster;
LogicA.Sector=FcbTable.FctAddr.Sector;
MemoryRw;
ReadLogicPage(&LogicA);
McuRw;
for (Count = 0;Count<8;Count++)
{
FileBuf[N] = XBYTE[0x1000+Count+FcbTable.FctAddr.Number];
if (FileBuf[N] != 0x20) N++;
}
FileBuf[N] = FileBuf[N+1] = '\0';
}
*/
//=============================================================================
//=============================================================================
//follow is about display
//--------------FontChange--------------
//input:ASCII char
//output: china font
unsigned char FontChange(unsigned char FC)
{
data unsigned char WC;
if ((FC>=0x30)||(FC<=0x39))
{
WC = 16 + (FC -0x30);
}
else if((FC>=0x41)||(FC<=0x5A))
{
WC = 32 + (FC -0x41);
}
return WC;
}
//=============================================================================
void InitDac(void)
{
//reset pin:59,gpio27
//ms gpio31,pin 62
//scl gpio00,89 pin
//sda,90,gpio01
//gpio27,59pin,net:aud_reset
XBYTE[EGPIO_OUT+3] &=~0x08;// reset pin:59,gpio27
XBYTE[EGPIO_OUT+3] |=0x08;//reset 1770 power on
}
void write_1770(char ADDR,char cmd)
{
unsigned char i;
unsigned char j;
i = 0x80;
XBYTE[EGPIO_OUT+3] &= ~0x80;//ms gpio31,pin62,
for(j = 0;j<8;j++)
{
XBYTE[EGPIO_OUT] &= ~0x01;
if(ADDR&i)
XBYTE[EGPIO_OUT ] |= 0x02;//gpio01
else
XBYTE[EGPIO_OUT] &= ~0x02;
XBYTE[EGPIO_OUT] |= 0x01;//gpio00
i >>= 1;
}
i = 0x80;
for(j = 0;j<8;j++)
{
XBYTE[EGPIO_OUT] &= ~0x01;
if(cmd&i)
XBYTE[EGPIO_OUT ] |= 0x02;//gpio01
else
XBYTE[EGPIO_OUT] &= ~0x02;
XBYTE[EGPIO_OUT] |= 0x01;//gpio00
i >>= 1;
}
XBYTE[EGPIO_OUT+3] |= 0x80;//ms gpio31,pin62,
}
#if 0
void PlayAB()
{
unsigned short i;
SendCmd(STOP);
for(i=0;i<0xffff;i++); //waiting DSP init value
PlayFile.CurrentClustor = RepA.CurrentClustor;
PlayFile.Pointer = RepA.Pointer;
Command = PLAY;
SendCmd(0x2100+MinA);
SendCmd(0x2200+SecA);
DataRequestFg = 0;
PlayFileEndF = 0;
currAbLen = 2;
InitStateFg = 1;
}
#endif
void KeyJob()
{
xdata struct File Feq;
xdata unsigned char i;
if(Recing)
{
if(NewKey != KEY_PLAY)
return;
}
switch (NewKey)
{
case KEY_PLAY:
if(Recing)
{
SendCmd(STOP);
ProcDspData();
Fclose(&PlayFile);
XBYTE[EGPIO_OUT+2]=XBYTE[EGPIO_OUT+2]|0X80;//gpio23
Recing = 0;
Playing = 0;
Command = 0;
CurrOpenFileNo = TotalFile;
PlayInitial(CurrOpenFileNo);
DmBufPage = 0;
IdmaRw = 0;
//break;
}
if(TotalFile == 0)break;
if((MenuItem!=0)||(VolumnCh!=0))
ClearLcdRam(0x70);
if(Playing == 0)
{
InitStateFg = 1;
WorkState = PLAYMODE;
MenuItem = 0;
VolumnCh = 0;
Playing = 1;
OpenPlayFile = 0;
//zls
LoadDspPm(GD);
//LoadDspPm("GD.NEW");
}
else if(Playing == 1)
{
Playing = 2;
MenuItem = 0;
VolumnCh = 0;
}
else if(Playing == 2)
{
Playing = 1;
MenuItem = 0;
VolumnCh = 0;
}
PlayInitial(CurrOpenFileNo);
Command = PLAY;
break;
case KEY_MODE:
/*if(Playing)
{
WorkState = STOPMODE;
Playing = 0;
}*/
MenuReq = 1;
VolumnCh = 0;
break;
case KEY_VOLUME_UP:
case KEY_VOLUME_UP1:
Vol+=6;
case KEY_VOLUME_DOWN:
case KEY_VOLUME_DOWN1:
if(Vol>=15)
Vol-=3;
else
Vol=15;
if(Vol>=63)Vol = 63;
if(Vol<15){
write_1770(1,0);
write_1770(2,0);
Vol=15;
}else{
write_1770(1,Vol);
write_1770(2,Vol);
}
VolumnConTime = 0;
VolumnDispReq = 1;
MenuItem = 0;
VolumnCh = 1;
break;
case KEY_NEXT: //down next song
if(MenuItem !=0)break;
if (CurrOpenFileNo< TotalFile)
CurrOpenFileNo++;
else
CurrOpenFileNo=1;
goto proc;
case KEY_PREV: //up last song
if(MenuItem !=0)break;
if (CurrOpenFileNo>1)
CurrOpenFileNo--;
else
CurrOpenFileNo=TotalFile;
proc:
SendCmd(STOP);
//BattTest();
PlayFileEndF = 0;
OpenPlayFile=0;
Playing = 0;
ClearLcdRam(0x70);
PlayInitial(CurrOpenFileNo);
break;
case KEY_POWER_OFF:
PowerOff();
break;
default :
break;
}
if(BackLight!=0)
{
BackLightTime = BackLight*1000;
BkMode = 1;
//Bk = 1;
BK_ON;
}
if(MenuItem!=0)
{
MenuReq = 1;
MenuKey = NewKey;
}
}
///////////////////////////////////////////////////////////////////////////////
//function name:DoCommand
//input: command
//output:none
/////////////////////////////////////////////////////////////////////////////
void ProcCommand(unsigned short Command)
{
xdata unsigned char i;
switch(Command)
{
case PLAY:
if (InitStateFg)
{
InitStateFg = 0;
if (!ProcPlay())
{
Command = 0;
Playing = 0;
PlayInitial(CurrOpenFileNo);
return;
}
DataRequestFg = 0;
PlayFileEndF = 0;
DmBufPage=0;
for(i=0;i<2;i++)
{
if(Fread((char xdata *)0x1000,512,&PlayFile)!=2)
{
Playing = 0;
Command = 0;
PlayFileEndF = 1;
}else{
DownloadDsp(&PlayFile,256,0x4000+i*0x100,0);
}
}
}
break;
}
if(Command)
{
SendCmd(Command);
switch(Command)
{
case TIME_SECOND:
TimeDispSFg = 1;
CurrTime.Second=XBYTE[HIBOX0];
SendCmd(TIME_MINUTE);
TimeDispMFg = 1;
CurrTime.Minute=XBYTE[HIBOX0];
break;
}
}
}
//////////////////////////////////////////////////////////////////////////////
void ProcLoadState(unsigned char LoadResult)
{
if(LoadResult)
{
InitDac(); //I2c config DAC
XBYTE[0X100] = 0;
XBYTE[0X101] = 0X99;
XBYTE[0X102] = 0X67;
XBYTE[0X103] = 0;
}
else
{
ClearLcdRam(0);
}
}
//////////////////////////////////////////////////////////////////////////////
/*Get data from SMC*/
//global variable:data_count=0;
void Get_Data(unsigned char* DispBuff,unsigned char String_Len,unsigned char Width,bit reload)
{
unsigned char FontQ,FontW;
unsigned long Offset;
unsigned char Length;
unsigned short H,L;
static unsigned char DataPos;
unsigned char ChLength;
unsigned char Count,Count1;
unsigned char buff_len;
Length = 216/Width;
ChLength = String_Len;
if(StringLength >= Length)
buff_len = Length;
else buff_len = StringLength;
if(!reload)
{
if(String_Len>=Length)
ChLength = Length;
DataPos = 0;
}else{
for(Count = 0;Count <216;Count+=24)
{
for(Count1 = 0;Count1 <24;Count1++)
{
buffer[Count+Count1] = buffer[Count+24+Count1];
}
}
}
while(ChLength)
{
if(DispBuff[DataPos]<0xa0)
{
FontQ = 3+0xa0;
FontW = FontChange(DispBuff[DataPos])+0xa0;
DataPos++;
}else{
FontQ = DispBuff[DataPos];
DataPos++;
FontW = DispBuff[DataPos];
DataPos++;
}
H = 94*(FontQ-0xa0-1);
L = FontW-0xa0-1;
Offset = (unsigned long)(H+L)<<5;
MemoryRw;
SmcRead(80*32+(Offset>>9));
McuRw;
Length=Width*2;
for(Count = 0;Count < Length;Count++)
{
buffer[((buff_len-ChLength)/2) * Length + Count] = XBYTE[0x1000 + Count + (unsigned int)(Offset&0x1ff)];
}
ChLength-=2;
}
}
/*display word after get_data return 1*/
/*waddr assign start display column*/
/*Length set display width*/
/*Page indicate the start locate of display*/
bit ProcWordDisp(char *String,unsigned char Page,unsigned char Column,unsigned char Width,bit Mode)
{
unsigned char Ctemp = 0;
unsigned char Length;
unsigned char Length1;
unsigned char Colu;
unsigned char len;
len = 224/Width;
if(Mode == 1)
{
conserve = 0xff;
conserve1 = 0xf0;
}else
{
conserve = 0;
conserve1 = 0;
}
Length = StringLength - DispLength;
if(StringLength==0)
{
//strcpy(DispBuff,String);
while(String[StringLength]!=0)
{
if((String[StringLength]<0xa0))
{
StringLength++;
Ctemp++;
}else StringLength++;
}
StringLength= StringLength+Ctemp;
CurrLrcLength = StringLength;
DispLength = 0;
buff_addr = 0;
if(StringLength>=len+2)
Length = len+2;
else Length = StringLength;
Get_Data(String,StringLength,Width,0);
}
Length1 = Length;
if(Length>=len)
{
Length = len;
if(DispLength!=0)
Get_Data(String,2,Width,1);
}else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -