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

📄 main.c

📁 SmartARM2400系列开发板全套资料
💻 C
字号:
/****************************************Copyright (c)****************************************************
**                         Guangzhou ZHIYUAN electronics Co.,LTD.                               
**                                     
**                               http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**--------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
*********************************************************************************************************/
#include "main.h"

#define	 BEEP1  1 << 30					                                /*  P3.30引脚控制蜂鸣器         */
#define  SDRAM_ADDR		0xA0000000  	                                /*  SDRAM起始地址,Bank0         */


/*********************************************************************************************************

* Function name :    DelayNS
* Descriptions :     长软件延时
* input parameters : idly	延时参数,值越大,延时越久
* output parameters :无
* Returned value :   无
* Created By :       
* Created Date :     2007-9-18
**-------------------------------------------------------------------------------------------------------
* Modified by : 
* Modified dete :
*********************************************************************************************************/
void  DelayNS(uint32  idly)
{  
    uint32  i;
    for(; idly>0; idly--){
        for(i=0; i<5000; i++);
    }
}


/*********************************************************************************************************

* Function name :    SDRAMInit
* Descriptions :     初始化SDRAM
* input parameters : 无
* output parameters :无
* Returned value :   无
* Created By :       zhangmingjie
* Created Date :     2007-9-18
**-------------------------------------------------------------------------------------------------------
* Modified by : 
* Modified dete :
*********************************************************************************************************/
void  SDRAM_Init( void )
{  
    uint32  i,dummy;
    
    PINSEL6  = 0x55555555;                                              /* D0--D15                      */
    PINSEL8  = 0x15555555;                                              /* A0--A14                      */
    
    PINSEL9 |= 0x00040000;                                              /* nWE                          */
    
    PINSEL5  = 0x05010115;                                              /* nCAS,nRAS,nDYCS0,nCKEOUT0,   */
                                                                        /* DQMOUT0,DQMOUT1              */ 
    
    EMCControl = 0x01;                                                  /* 禁止镜像                     */ 
    
    
    EMCDynamictRP   = 1;                                                /*  tRP  2cclk	                */
	EMCDynamictRAS  = 2;		                                        /*	tRAS 3cclk		            */
	EMCDynamictSREX = 1;		                                        /*	tSREX 3cclk		            */
	EMCDynamictAPR  = 0;		                                        /*	tAPR  1cclk		            */
	EMCDynamictDAL  = 3;		                                        /*	TDAL  4cclk		            */
	EMCDynamictWR   = 2;		                                        /*	tWR  3cclk		            */
	EMCDynamictRC   = 3;		                                        /*	tRC   4cclk		            */
	EMCDynamictRFC  = 3;		                                        /*	tRFC  4cclk		            */
	EMCDynamictXSR  = 1;		                                        /*	tXSR   2cclk	            */
	EMCDynamictRRD  = 0;		                                        /*	tRRD   1cclk	            */
	EMCDynamictMRD  = 2;	                                            /*	tMRD  3cclk		            */
		

	EMCDynamicReadConfig =1;		                                    /* Command delayed strategy     */

  /* 
   *  Default setting, RAS latency 3 CCLKs, CAS latenty 3 CCLKs. 
   */
    EMCDynamicRASCAS0  = 0x00000303;

  /* 
   *  256MB, 16Mx16, 4 banks, row=13, column=9 
   */
    EMCDynamicConfig0 = 0x00000680;
    DelayNS(2);

  /* 
   *  Mem clock enable, CLKOUT runs, send command: NOP 
   */
    EMCDynamicControl = 0x00000183;
    DelayNS(2);
    
  /* 
   *  Send command: PRECHARGE-ALL, shortest possible refresh period 
   */
    EMCDynamicControl = 0x00000103;
    DelayNS(2);

  /* 
   *  set 32 CCLKs between SDRAM refresh cycles 
   */
    EMCDynamicRefresh  = 0x00000002;
    for(i = 0; i < 0x80; i++);	                                        /* wait 128 AHB clock cycles    */
    
  /* 
   *  set 28 x 16CCLKs=448CCLK=7us between SDRAM refresh cycles
   */
    EMCDynamicRefresh  = 28;
    
  /* 
   *  To set mode register in SDRAM, enter mode by issue
   *  MODE command, after finishing, bailout and back to NORMAL mode.   
   *  Mem clock enable, CLKOUT runs, send command: MODE 
   */
    EMCDynamicControl = 0x00000083;
    dummy=*((volatile uint32 *)(0xa0033000));
    EMCDynamicControl = 0x00000000;	                                    /* Send command: NORMAL         */
    EMCDynamicConfig0 |= 0x00080000;	                                /* Enable buffer                */
    DelayNS(2);
}

/********************************************************************************************************
* Function name :    main
* Descriptions :     主函数
* input parameters : 无
* output parameters :无
* Returned value :   0
* Created By :       zhangmingjie
* Created Date :     2007-9-18
**-------------------------------------------------------------------------------------------------------
* Modified by : 
* Modified date :
*********************************************************************************************************/
int  main(void)
{  
    uint32  i;
    uint32  iErr = 0;
   
    volatile uint8  *piAddr;

    PINSEL7 = 0x00000000;			                                    /*  管脚选择GPIO                */   
    FIO3DIR  = BEEP1; 				                                    /*  设置为输出                  */ 
    FIO3SET = BEEP1;	
    			
    SDRAM_Init();                                                       /*  初始话SDRAM接口             */ 
    piAddr = (volatile uint8  *)SDRAM_ADDR + 0;
    
    for( i = 0; i < 256; i++ ){
        *piAddr = (uint8)i; 
        piAddr += 1;
    }
    
    piAddr = (volatile uint8  *)SDRAM_ADDR + 0;

    for( i = 0; i < 256; i++){    
        if( *(piAddr++) != i ){
        iErr = 1;
        break;
        };
        iErr = 0;
    }
    
    if( 0 == iErr ){  
        FIO3CLR = BEEP1;				                                   
        DelayNS(1000);
        FIO3SET = BEEP1;				
        DelayNS(1000);
    }
    else{  
        while(1){  
            FIO3CLR = BEEP1;			
            DelayNS(100);
            FIO3SET = BEEP1;			
            DelayNS(100);
        }
    }  
    
    while(1);
    return(0);
}

/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

⌨️ 快捷键说明

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