⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.bak

📁 nec16位单片机读U盘播放MP3源码
💻 BAK
字号:
#pragma sfr
#pragma NOP
#pragma DI
#pragma EI
#pragma access
#include <string.h>
#include "Common.h"
#include "Define.h"
#include "Ch375.h"
#include "Fat.h"
#include "Hpi.h"

extern unsigned char DBUF[512];
extern SYS_INFO_BLOCK  DeviceInfo;
extern FILE_INFO ThisFile;
extern FREE_FAT_INFO  FreeFat;
extern unsigned char  showFilename[32][11];
extern CH_RSP_BLOCK  CHRspBlock;

sreg XXGFLAGS  bXXGFlags;
unsigned int S2_count;
extern unsigned char Mp3Files;
extern unsigned char  FileReadOver   ;
extern unsigned char play_mode; 
extern unsigned char keyvld;
extern unsigned char *pShowfile;
extern unsigned char Index_song;
void main(void);
void Cpu_init(void);
extern void Key_init(void);
void Flash_chip_init(void);
void Delay_50ms(void);
void Delay_1ms(void);
void Ic2201_init(void);
void ReadUdisk(void);
void mInitSTDIO(void);
void ReadUdisk(void);
void show( char st[]);
void mShow(unsigned int showLen,unsigned  char *pShow);
extern void Key_hd(void);
extern void Key_prc(void);
extern void CH375_CMD_PORT_d_out( INT8 d_out );
extern void CH375_DAT_PORT_d_out( INT8 d_out );
extern INT8 CH375_DAT_PORT_in( );
void Cpu_init(void)
{
 //hardware initial
  OSMS=0x01;          //not devide
  //OSMS=0x00;   
  PCC=0x00;
  MM=0x17;
  IMS=0x0C6;
  MK0L=0x0ff;        //mask interrupt
  PUOL=0x6E;
  PUOH=0x10;
  P0=0x31;
  PM0=0x0c7;
  ADIS=0;
  ADM=0x01;
  P1=0x0F0;
  PM1=0x81;
  P2=0x0bf;
  PM2=0x3F;
  P3=0x80;
  PM3=0x00;
  P4=0x0FF;
  KRM=0x02;
  P5=0x00;
  PM5=0;
  P6=0x00;
  PM6=0;
  P12=0x0ff;
  PM12=0x0F8;
////////////////
// 2-wire serial I/O  set
  CSIMK0 = 1 ;
  CSIIF0 = 0 ;
  CSIM0= 0x1b;           //stop operation   serial clock is set in TCL3
  TCL3 = 0x87 ;          //serial clock is fx/4(1.25M)
  SBIC = 0x01;           //2-wire serial I/O mode MSB 
  SINT = 0x00;
//INTP1 interrupt set
  PMK1 = 1;              //disable INTP1
  PIF1 = 0;              //clear interrupt flag
  INTM0 = 0x10;          //rising edge
  PPR1 = 1;              //high priority level

  }
 /******************************/
/******************************/
/*void Flash_chip_init(void)
{
	FLASH_RESET = 0 ;
	Delay_50ms();           //flash chip reset delay
	FLASH_RESET = 1 ;
	FLASH_OE = 1 ;
	FLASH_CE = 1 ;
	
	mp3data_address.flash_addr = START_ADDRESS ;
	return;
}*/

void Ic2201_init(void)
{
      MA8201_RESET = 0 ;                                 //reset
      Delay_50ms();
      MA8201_RESET = 1 ;
      Delay_50ms();
      return;
}

void Send_usbData(unsigned char data)
{
  while(!DREQ){;}
  SBIC = 0x01;
  CSIMK0 = 0 ;
  CSIE0 = 1 ;
  BSYNC = 1 ;
  SIO0 = data;           
  BSYNC = 0 ;

}
void Delay_50ms(void)
{
	unsigned char i,j;
	for(i = 0;i<100;i++)
	    for(j=0;j<100;j++)
	     NOP();
	return;
}

void Delay_1ms(void)
{
	unsigned char i,j;
	for(i = 0;i<2;i++)
	    for(j=0;j<100;j++)
	     NOP();
	return;
}

void show( char st[])
{
	unsigned int i;
	i=0;
	STIF=0;
	TXS=0;
  	while(i<strlen(st))
  	{
  	while(!STIF);
  	STIF=0;
	TXS=st[i];
	i++;
  	Delay_50ms();
  	}	
}
void mShow(unsigned int showLen,unsigned  char *pShow)
{
	unsigned char showData;
	unsigned int i;
	TXS=0;
	for(i=0;i<showLen;i++)
	{     
		showData=*pShow;
		while(!STIF);
		STIF=0;
		TXS=showData;
		pShow++;
	}			
}
void main(void)
{
  Cpu_init();
  mInitSTDIO();
  P1.5=1;
  P1.6=0;
  Key_init();
  Ic2201_init();
  //Flash_chip_init();
  
/*********time1 time 10ms  *************/

  TMMK1=1     ;       /*mask timer 1 interrupt*/
  TMIF1=0     ;
  TCL1 = 0x0d ;      /*  19.5khz */
  CR10= 195 ;		/*  Timer 10 msec */
  TCE1 = 1 ;          /*start counter*/
  DI();
  P3.7=0;
  show(" start:\n");
  SBIC = 0x01;
  CSIMK0 = 0 ;
  CSIE0 = 1 ;	
  ReadUdisk();
}


void ReadData(void)
{
	#define RspBlockReadFile CHRspBlock.RspBlock.Rsp_ReadFile
	unsigned int Readlen,i;
	unsigned long len;
	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
	{
	CHRspBlock.errcode=ERC_NODEVICE;
	return ;
	}
	if(!ThisFile.bFileOpen)
	{
	CHRspBlock.errcode=ERC_FILENOTOPENED;
	return ;
	}
	ThisFile.bFileOpen=0;
	len=ThisFile.LengthInByte;
	while(len>0)
	{
   		/*if(TMIF1 == 1 )
	    	{
	        	TMIF1 = 0;   
			if(S2_count!=0)
	        	{
	        		if(S2_count<2000)S2_count++;
	        	}
	       	Key_hd();
	        	Key_prc();
	    	}
		if(play_mode==PLAY)
		{*/	
			//if((keyvld==S1_KEY) || (keyvld==S4_KEY))return;
			if (BUFFER_LENGTH>len)Readlen=len;
			Delay_1ms();
			Delay_1ms();
			Delay_1ms();
			Delay_1ms();
			Delay_1ms();
			Delay_1ms();
			Delay_1ms();
			Delay_1ms();
			if(RBC_Send(ThisFile.SectorPointer,1));
			else
			{
			   	show(" err1 \n");
				return ;
			}
		 	len=len-Readlen;
			 ThisFile.SectorofCluster+=1;
			 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
			 {
			   	ThisFile.SectorofCluster=0;
			 	ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
			 	if(ThisFile.ClusterPointer>0xffef)
			 	{
			   		show(" err2 \n");
					return ;
			 	}
			 	ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
			   }
			   else ThisFile.SectorPointer=ThisFile.SectorPointer+1;
		}
	  //else if (play_mode==STOP)return;
	//}
	ThisFile.bFileOpen=1;
	return ;
	#undef RspBlockReadFile
}

void ReadUdisk(void)
{
	unsigned char retStatus;
	show(" start read usb device :\n");
	retStatus=mCH375Init( );
	if(retStatus==0) show(" 375 initial ok \n");
	retStatus = mWaitInterrupt( ); 
	P3.7=1;
	if( retStatus != USB_INT_CONNECT )show(" no usb device connect! \n");
	else
	{
		show(" usb device connect ok! \n");
		retStatus=EnumMassDev();
		if(retStatus)show(" enummassDEV success:\n");
		//retStatus=GetCapacity();
		//if(retStatus)show(" getcapacity success:\n");
		retStatus=List();
		if(retStatus)
		{
			show(" list file success: \n");
			Index_song=0;
			pShowfile=showFilename[Index_song];
			Test_Lamp=0;
			while(1)
			{
				pShowfile=showFilename[Index_song];
				if(Index_song>=Mp3Files)Index_song=0;
				else Index_song++;
				retStatus=OpenFile( pShowfile);
				if (retStatus)
				{
				show(" openfile success: \n");
				ReadData();
				}				
			}
			while(1)
			{
				retStatus=OpenFile( pShowfile);
				if (retStatus)
				{
				show(" openfile success: \n");
				ReadData();
				}
				 if(keyvld == NOKEY)
				 {
				Index_song++;
				if(Index_song>=Mp3Files)Index_song=0;
				pShowfile=showFilename[Index_song];
				 }
				while(play_mode!=PLAY)
				{
			   		if(TMIF1 == 1 )
				    	{
				        	TMIF1 = 0;   
				        	if(S2_count!=0)
				        	{
				        		if(S2_count<2000)S2_count++;
				        	}
				       	Key_hd();
				        	Key_prc();
				    	}
   				}
			}
		}
	}
}

void mInitSTDIO(void )
{
	CSIM2=0x00;
	ASIM=0x89;                //8_data;1_stop;0_crc
	BRGC=0x8a;               //MCS=1;9600baud
	//BRGC=0x7a; 
	SIPS=0x00;
	PM7.0=1;
	PM7.1=0;
    P7.1=1;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -