www.pudn.com > huoniu-for_128M(NAND)-FLASH).zip > main.c, change:2012-09-19,size:4981b


 
#include "main.h" 
#include "SD_driver.h" 
#include "fsmc_nand.h"   
#include <stdio.h> 
 
 
/* Private typedef -----------------------------------------------------------*/ 
/* Private define ------------------------------------------------------------*/ 
#define BUFFER_SIZE         512    //数据缓存区大小为512个字节 
/* Private macro -------------------------------------------------------------*/ 
/* Private variables ---------------------------------------------------------*/ 
static vu32 TimingDelay = 0;  
u8 TxBuffer[BUFFER_SIZE], RxBuffer[BUFFER_SIZE];  //发送和接收数据缓冲区 
vu32 WriteReadStatus = 0; 
u32 j = 0; 
/* Extern variables ----------------------------------------------------------*/ 
/* Private function prototypes -----------------------------------------------*/ 
/* Private functions ---------------------------------------------------------*/ 
extern void usart1(void); 
extern void Usart1_SendData(u8 *DatBuf, u32 len); 
void Fill_Buffer(u8 *pBuffer, u16 BufferLenght, u32 Offset); 
void DelayXms(unsigned int x); 
/******************************************************************************* 
* Function Name  : main. 
* Description    : Main routine. 
* Input          : None. 
* Output         : None. 
* Return         : None. 
*******************************************************************************/ 
int main(void) 
{ 
 //	u8  ID_Code[5]={0,0,0,0,0}; 
	 
	GPIO_InitTypeDef GPIO_InitStructure; 
 	//还有一个USB开关 
  	/* Enable the SDIO AHB Clock */ 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE); 
 
 /*  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; 
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
	GPIO_Init(GPIOC, &GPIO_InitStructure);   
    GPIO_ResetBits(GPIOC,GPIO_Pin_8);	//打开SD卡*/ 
    
  	System_Init(); 
  	/* Configure the systick */     
  	SysTick_Config(); 
  
   	//读FLASH ID -------------------------- 
 
  //	FlashReadId(ID_Code); 
  	//-------------------------------------------------------- 
  	while (bDeviceState != CONFIGURED);	  //等待USB枚举成功 
  	while (1) 
  	{} 
} 
 
 
/******************************************************************************* 
* Function name : Fill_Buffer 
* Description   : Fill the buffer 
* Input         : - pBuffer: pointer on the Buffer to fill 
*                 - BufferSize: size of the buffer to fill 
*                 - Offset: first value to fill on the Buffer 
* Output param  : None 
*******************************************************************************/ 
void Fill_Buffer(u8 *pBuffer, u16 BufferLenght, u32 Offset) 
{ 
  u16 IndexTmp = 0; 
 
  /* Put in global buffer same values */ 
  for (IndexTmp = 0; IndexTmp < BufferLenght; IndexTmp++ ) 
  { 
    pBuffer[IndexTmp] = IndexTmp + Offset; 
  } 
} 
 
 
/*****************   延时x毫秒函数 ***********/ 
void DelayXms(unsigned int x)                
{ 
 unsigned int i,j; 
 for(i=0;i<x;i++) 
 for(j=0;j<5150;j++); 
} 
 
/******************************************************************************* 
* Function Name  : SysTick_Config 
* Description    : Configure a SysTick Base time to 10 ms. 
* Input          : None 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
 void SysTick_Config(void) 
{ 
  /* Configure HCLK clock as SysTick clock source */ 
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);	//设置SysTick时钟为AHB时钟 
  
  /* SysTick interrupt each 100 Hz with HCLK equal to 72MHz */ 
  SysTick_SetReload(720000);   //设置重装值 
 
  /* Enable the SysTick Interrupt */ 
  SysTick_ITConfig(ENABLE); 
} 
 
/******************************************************************************* 
* Function Name  : Delay 
* Description    : Inserts a delay time. 
* Input          : nCount: specifies the delay time length (time base 10 ms). 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
void Delay(u32 nCount) 
{ 
  TimingDelay = nCount; 
 
  /* Enable the SysTick Counter */ 
  SysTick_CounterCmd(SysTick_Counter_Enable); 
   
  while(TimingDelay != 0) 
  { 
  } 
 
  /* Disable the SysTick Counter */ 
  SysTick_CounterCmd(SysTick_Counter_Disable); 
 
  /* Clear the SysTick Counter */ 
  SysTick_CounterCmd(SysTick_Counter_Clear); 
} 
 
/******************************************************************************* 
* Function Name  : Decrement_TimingDelay 
* Description    : Decrements the TimingDelay variable. 
* Input          : None 
* Output         : TimingDelay 
* Return         : None 
*******************************************************************************/ 
void Decrement_TimingDelay(void) 
{ 
  if (TimingDelay != 0x00) 
  { 
    TimingDelay--; 
  } 
} 
 
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/