STM32 CH573例程完整
单片机源程序如下:
- /***********************************************************************************
- CH375并行数据口:PF0~PF7 测试OK
- 控制端口:A0:PA8 CS:PA9 RD:PA10 WR:PC0 INT:PA12
- INT:复位完成后请求中断输出,低电平有效
- ACT#:完成USB配置后输出低电平,未配置的情况下输出高电平
- 复位完成后:25RST:低电平 26RST#:高电平 TXD:低电平并口输出
- INT#:复位完成后,为中断请求输出
- 检查错误:WR引脚一直为高电平,采用3.3V供电。测试成功。
- ***********************************************************************************/
- #include <stm32f10x_lib.h>
- #include "Nokia5110.h"
- #include "ILI9325.h"
- #include "W25X16.h"
- #include "ch375.h"
- #include "vs1003.h"
- #include "znfat.h"
- /*****************C语言深度解剖******************************/
- typedef struct weather
- {
- char i;
- int h[];
- }hell;
- int *s=(int*)0x80000004;
- int a[3];
- int b=sizeof(&a[0]);// sizeof(a)=12 sizeof(&a)=4
- // sizeof(a[0])=4 sizeof(&a[0])=4
- /*******
- #define x 3
- #define y 2*x
- #undef x
- #define x 2
- int z=y;
- #define sqr[n] '#n'
- #define xname[8] x##8//xname[8]就会被写成x8
- int *p;
- char *m;
- int q=sizeof(p);
- int q1=sizeof(unsigned char);
- int aa[5]={1,2,3,4,5};
- int *ptr= (int*)(&aa+1);
- ***************/
- /*****************C语言深度解剖******************************/
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -----------------data--------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- ErrorStatus HSEStartUpStatus;
- //=============================W25X16==========================================
- #define FLASH_WriteAddress 0x00000
- #define FLASH_ReadAddress FLASH_WriteAddress
- #define FLASH_SectorToErase FLASH_WriteAddress
- //#define sFLASH_ID 0xEF3015 //W25X16
- #define sFLASH_ID 0xEF4015 //W25Q16
- u8 ReturnValue;
- u32 DeviceID = 0;
- u32 FlashID = 0;
- //=========================================================================
- struct znFAT_Init_Arg Init_Arg_UDISK; //初始化FAT结构实体
- struct znFAT_Init_Arg *pArg; //初始化参数结构体实体
- struct FileInfoStruct FileInfo; //文件信息结构实体
- extern struct FileInfoStruct FileInfoHZK;//idata
- extern UINT8 znFAT_Buffer[512];
- //extern u32 conformflag=0;
- struct directory *rDir;
- u16 temp;
- u8 conformflag;
- u32 currentfile=0;
- unsigned char next=0;
- u8 fileBuf[512];
- extern u16 time;
- extern u32 lenth;
- extern u16 f_kbps;
- //static u16 playtime=0;
- u16 temp=0;
- //float course=0;
- int L;
- u32 Statusflag;
- u32 num;
- u32 FileSize;
- u8 VOL_VALUE=0x25; //读取数据长度
- u8 volup=0;
- unsigned char Dev_No=0;
- /* Private function prototypes -----------------------------------------------*/
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void NVIC_Configuration(void);
- void EXTI_Configuration(void);
- void SPI_Configuration(void);
- void EXTI9_5_IRQHandler(void);
- void Show_File_Message(void);
- //extern UINT8 FAT32Buffer[512];
- extern void Delay(vu32 nCount);
- /* Private functions ---------------------------------------------------------*/
- u8 machtype(u8 *type);
- u8 t[14] = "HZLIB";
- u16 ii;
- int main(void)
- {
- #ifdef DEBUG
- debug();
- #endif
-
- RCC_Configuration();
- GPIO_Configuration();
- LCD_GPIO_Configuration();
- EXTI_Configuration();
- NVIC_Configuration();
- SPI_Configuration();
- SPI_FLASH_Init();
- ili9320_Initializtion();//液晶初始化
- ili9320_Clear(Blue);
- DeviceID = SPI_FLASH_ReadDeviceID();
- FlashID = SPI_FLASH_ReadID();
- if (FlashID == sFLASH_ID)
- {
- ReturnValue = 1;
- }
- ili9320_PutChar(40,0,'U',Black,Blue);
- Lcd_WriteChineseString(3,0,Black,Blue,"盘读写实验");
- LCD_ShowNum(0,200,123456,Black,Blue);
- ili9320_PutString(40,16,t,Black,Blue);
- //VS1003Reset();
- //Sintest(120);
- do
- {
- Statusflag = CH375Init( ); /* 初始化CH375 ,成功返回0*/
- }
- while(Statusflag);
- /*********************等待U盘插入******************************************/
- while ( WaitInterrupt( ) != USB_INT_CONNECT ); /* U盘没有连接或者已经拔出 或等待U盘连接*/
- Delay(320000); /* 等待U盘进入正常工作状态*/
- do
- {
- Statusflag = InitDisk( ); /* 初始化磁盘 ,成功返回0*/
- }
- while(Statusflag);
- //LCD_Display(20,0,"ELAB MP3");
-
- /***************************************!FAT32OpenFile(&FileInfo, "\\test.txt",0)************************************/
- pArg=&Init_Arg_UDISK; //初始化参数结构体实体
- Dev_No=UDISK;
- znFAT_Init(); //初始化pArg
- /**************************************************************************/
- znFAT_Open_File(&FileInfoHZK, "\\HZLIB.bin",0,1);
- Show_File_Message();
-
- //if(machtype("MP3")||machtype("WMA"))
-
- while(!znFAT_Open_File(&FileInfo, "\\*.mp3",num,num+1)) //打开U盘根目录下所有目录中的第n个
- {
- //if(machtype("MP3"));
- num++;
- }
-
- while(1)
- {
- znFAT_Open_File(&FileInfo, "\\*.mp3",currentfile,num);
- FileSize=FileInfo.FileSize;
- //LCD_Display(0,1,FileInfo.FileName);
- //time=(FileSize/f_kbps)/125;//总时间
- // LCD_Display_Time(2, 5, time);
- // LCD_Write_Progress(2, 4,50); // 播放进度
- //XDCS_L;
- //VS1003_FlushBuffer();
- znFAT_Read_FileX(&FileInfo,0,FileInfo.FileSize, VS1003SendDat);
- //XDCS_H;
- // LCD_Display(0,1," ");
- // LCD_Display(0,2," ");
- currentfile++;
- //currentfile++;
- //conformflag=1;
-
- if(currentfile>=num)
- {
- currentfile=0;
- }
- }
- }
- /*******************************************************************************
- * Function Name : RCC_Configuration
- * Description : Configures the different system clocks.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void RCC_Configuration(void)
- {
- /* RCC system reset(for debug purpose) */
- RCC_DeInit();
- /* Enable HSE */
- RCC_HSEConfig(RCC_HSE_ON);
- /* Wait till HSE is ready */
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if(HSEStartUpStatus == SUCCESS)
- {
- /* Enable Prefetch Buffer */
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
- /* Flash 2 wait state */
- FLASH_SetLatency(FLASH_Latency_2);
-
- /* HCLK = SYSCLK */
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
-
- /* PCLK2 = HCLK */
- RCC_PCLK2Config(RCC_HCLK_Div1);
- /* PCLK1 = HCLK/2 */
- RCC_PCLK1Config(RCC_HCLK_Div2);
- /* PLLCLK = 8MHz * 9 = 72 MHz */
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- /* Enable PLL */
- RCC_PLLCmd(ENABLE);
- /* Wait till PLL is ready */
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
- {
- }
- /* Select PLL as system clock source */
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
- /* Wait till PLL is used as system clock source */
- while(RCC_GetSYSCLKSource() != 0x08)
- {
- }
- }
-
- // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LCD, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_CH375_Data, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_CH375_CTL, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_VS1003, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1, ENABLE);
- RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE);
- }
- /*******************************************************************************/
- void SPI_Configuration(void)
- {
- SPI_InitTypeDef SPI_InitStructure;
- /* SPI_MASTER configuration ------------------------------------------------*/
- SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
- SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
- SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
- SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//时钟悬空高
- SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//数据捕获于第二个时钟沿
- SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//内部 NSS 信号有 SSI位控制
- SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
- SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//定义了用于 CRC值计算的多项式 7
- SPI_InitStructure.SPI_CRCPolynomial = 7;//定义了用于 CRC值计算的多项式 7
- SPI_Init(SPI2, &SPI_InitStructure);
-
- SPI_Cmd(SPI2, ENABLE);
- }
- /*******************************************************************************
- * Function Name : GPIO_Configuration
- * Description : Configures GPIOs used.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void GPIO_Configuration(void)
- {
- /*************************LCD端口的初始化**************************************/
- /* GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIO_LCD, &GPIO_InitStructure); //GPIOC
- */
- /*************************CH375端口的初始化***************************************/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10
- |GPIO_Pin_11 ;
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIO_CH375_CTL, &GPIO_InitStructure); //GPIOA
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //wr
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // INT# 输入浮空
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIO_CH375_CTL, &GPIO_InitStructure);
- /*************************VS1003端口的初始化***************************************/
- /* GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIO_VS1003, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIO_VS1003, &GPIO_InitStructure);//GPIOB
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; // DREQ 输入上拉
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIO_VS1003, &GPIO_InitStructure);*/
- /*************************KEY端口的初始化***************************************/
- /*******************************************************************************
- * 引脚连接: KEY1 next program ................... PB5
- KEY1 last program ................... PB6
- KEY1 turn up vol ................... PB7
- KEY1 turn up vol ................... PB8
- *******************************************************************************/
- /* Configure Key GPIO Pin as input floating */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5);
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource7);
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);
- }
- /*******************************************************************************
- * Function Name : NVIC_Configuration
- * Description : Configures Vector Table base location.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- /*************************外部中断NVIC通道设置*******************************/
-
- /* Configure one bit for preemption priority */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
-
- /* Enable the EXTI9_5 Interrupt */
- // NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- EXTI->PR = 0x0007FFFF;
- NVIC_Init(&NVIC_InitStructure);
-
- }
- /*******************************************************************************
- * Function Name : EXTI_Configuration
- * Description : Configures Vector Table base location.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void EXTI_Configuration(void)
- {
- EXTI_DeInit();
- EXTI_InitStructure.EXTI_Line= EXTI_Line5 | EXTI_Line6 | EXTI_Line7 | EXTI_Line8;
- EXTI_InitStructure.EXTI_Mode= EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger= EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd= ENABLE;
- EXTI_Init( &EXTI_InitStructure );
- }
- /*******************************************************************************/
- u8 machtype(u8 *type)
- {
- u8 i;
- for(i=9;i<12;i++)
- if(FileInfo.FileName[i]==*type)
- type++;
- else
- break;
- if(i==12)
- return 1;
- else
- return 0;
- }
- /*******************************************************************************
- * Function Name : Delay
- * Description : Inserts a delay time.
- * Input : nCount: specifies the delay time length.
- * Output : None
- * Return : None
- *******************************************************************************/
- /*******************************************************************************/
- void Delay(vu32 nCount)
- {
- for(; nCount != 0; nCount--);
- }
- /*******************************************************************************/
- #ifdef DEBUG
- /*******************************************************************************
- * Function Name : assert_failed
- * Description : Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * Input : - file: pointer to the source file name
- * - line: assert_param error line source number
- * Output : None
- * Return : None
- *******************************************************************************/
- void assert_failed(u8* file, u32 line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- void Show_File_Message(void)
- {
-
- Lcd_WriteChineseString(0,2,Black,Blue,"文件名");
- ili9320_PutString(80,32,FileInfoHZK.FileName,Black,Blue);
- Lcd_WriteChineseString(0,3,Black,Blue,"文件开始簇号");
- LCD_ShowNum(176,3*16,FileInfoHZK.FileStartCluster,Black,Blue);
- Lcd_WriteChineseString(0,4,Black,Blue,"文件当前簇号");
- LCD_ShowNum(176,4*16,FileInfoHZK.FileCurCluster,Black,Blue);
- Lcd_WriteChineseString(0,5,Black,Blue,"文件的大小");
- LCD_ShowNum(176,5*16,FileInfoHZK.FileSize,Black,Blue);
- Lcd_WriteChineseString(0,6,Black,Blue,"文件的当前扇区");
- LCD_ShowNum(176,6*16,FileInfoHZK.FileCurSector,Black,Blue);
- Lcd_WriteChineseString(0,7,Black,Blue,"文件的下一簇号");
- LCD_ShowNum(176,7*16,FileInfoHZK.FileSize,Black,Blue);
- Lcd_WriteChineseString(0,8,Black,Blue,"文件在当前扇区中的位置");
- LCD_ShowNum(176,8*16,FileInfoHZK.FileCurPos,Black,Blue);
- Lcd_WriteChineseString(0,9,Black,Blue,"文件的当前偏移量");
- LCD_ShowNum(176,9*16,FileInfoHZK.FileCurOffset,Black,Blue);
- Lcd_WriteChineseString(0,10,Black,Blue,"文件的目录项所在的扇区");
- LCD_ShowNum(176,10*16,FileInfoHZK.Rec_Sec,Black,Blue);
- Lcd_WriteChineseString(0,11,Black,Blue,"文件目录项所在扇区位置");
- LCD_ShowNum(176,11*16,FileInfoHZK.nRec,Black,Blue);
- Lcd_WriteChineseString(0,12,Black,Blue,"文件属性");
- LCD_ShowNum(176,12*16,FileInfoHZK.FileAttr,Black,Blue);
- Lcd_WriteChineseString(0,13,Black,Blue,"文件的创建时间");
- LCD_ShowNum(176,13*16,FileInfoHZK.FileCreateTime.hour,Black,Blue);
- LCD_ShowNum(192,13*16,FileInfoHZK.FileCreateTime.min,Black,Blue);
- LCD_ShowNum(208,13*16,FileInfoHZK.FileCreateTime.sec,Black,Blue);
- Lcd_WriteChineseString(0,14,Black,Blue,"文件的创建日期");
- LCD_ShowNum(176,14*16,FileInfoHZK.FileCreateDate.year,Black,Blue);
- LCD_ShowNum(208,14*16,FileInfoHZK.FileCreateDate.month,Black,Blue);
- LCD_ShowNum(224,14*16,FileInfoHZK.FileCreateDate.day,Black,Blue);
- Lcd_WriteChineseString(0,15,Black,Blue,"文件的修改时间");
- LCD_ShowNum(176,15*16,FileInfoHZK.FileMTime.hour,Black,Blue);
- LCD_ShowNum(192,15*16,FileInfoHZK.FileMTime.min,Black,Blue);
- LCD_ShowNum(208,15*16,FileInfoHZK.FileMTime.sec,Black,Blue);
- Lcd_WriteChineseString(0,16,Black,Blue,"文件的修改日期");
- LCD_ShowNum(176,16*16,FileInfoHZK.FileMDate.year,Black,Blue);
- LCD_ShowNum(208,16*16,FileInfoHZK.FileMDate.month,Black,Blue);
- LCD_ShowNum(224,16*16,FileInfoHZK.FileMDate.day,Black,Blue);
- Lcd_WriteChineseString(0,17,Black,Blue,"文件的访问日期");
- LCD_ShowNum(176,17*16,FileInfoHZK.FileADate.year,Black,Blue);
- LCD_ShowNum(208,17*16,FileInfoHZK.FileADate.month,Black,Blue);
- LCD_ShowNum(224,17*16,FileInfoHZK.FileADate.day,Black,Blue);
- }
- /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
所有资料51hei提供下载:
STM32 CH573例程.7z
(159.95 KB, 下载次数: 5)
|