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

📄 control.c

📁 LPC2294 测试程序 YL_LPC229X_Test_Data的目录说明
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "def.h"
#include "config.h"
#include "board.h"
#include "utils.h"


#define IN_TARGET
extern char Image$$RO$$Limit[];
extern char Image$$RO$$Base[];
extern char Image$$RW$$Limit[];
extern char Image$$RW$$Base[];
extern char Image$$ZI$$Limit[];
extern char Image$$ZI$$Base[];

void ShowBootInfo( void )
{
	puts( "\n ***************************************\n");
	puts( "*                                       *\n" );
	puts( "*    Test for YL-LPC2292 Board V1.00    *\n" );
	puts( "*        Http://www.uCdragon.com        *\n" );
	puts( "*                                       *\n" );
	puts( " ***************************************\n" );
	/*    printf( "  Image$$RO$$Base  = 0x%x\n", Image$$RO$$Base );
		printf( "  Image$$RO$$Limit = 0x%x\n", Image$$RO$$Limit );
		printf( "  Image$$RW$$Base  = 0x%x\n", Image$$RW$$Base );
		printf( "  Image$$RW$$Limit = 0x%x\n", Image$$RW$$Limit );
		printf( "  Image$$ZI$$Base  = 0x%x\n", Image$$ZI$$Base );
		printf( "  Image$$ZI$$Limit = 0x%x\n", Image$$ZI$$Limit );*/
}

void TargetResetInit( void )
{
#ifdef __DEBUG    
	MEMMAP = 0x3;   				//remap
	//中断向量重新映射,它位于用户外部Flash的起始地址;
#endif

#ifdef __OUT_CHIP    
	MEMMAP = 0x3;   				//remap
	//中断向量重新映射,它位于用户外部Flash的起始地址;
#endif

#ifdef __IN_CHIP	
	MEMMAP = 0x1;   				//remap
	//中断向量不重新映射,它位于内部Flash的起始地址;
#endif

	/* 设置系统各部分时钟 */
	PLLCON = 1;
#if (Fpclk / (Fcclk / 4)) == 1
	VPBDIV = 0;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
	VPBDIV = 2;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
	VPBDIV = 1;
#endif

#if (Fcco / Fcclk) == 2
	PLLCFG = ( ( Fcclk / Fosc ) - 1 ) | ( 0 << 5 );
#endif
#if (Fcco / Fcclk) == 4
	PLLCFG = ( ( Fcclk / Fosc ) - 1 ) | ( 1 << 5 );
#endif
#if (Fcco / Fcclk) == 8
	PLLCFG = ( ( Fcclk / Fosc ) - 1 ) | ( 2 << 5 );
#endif
#if (Fcco / Fcclk) == 16
	PLLCFG = ( ( Fcclk / Fosc ) - 1 ) | ( 3 << 5 );
#endif
	PLLFEED = 0xaa;
	PLLFEED = 0x55;
	while ( ( PLLSTAT & ( 1 << 10 ) ) == 0 );
	PLLCON = 3;
	PLLFEED = 0xaa;
	PLLFEED = 0x55;

	/* 设置存储器加速模块 */
	MAMCR = 0;
#if Fcclk < 20000000
	MAMTIM = 1;
#else
#if Fcclk < 40000000
	MAMTIM = 2;
#else
	MAMTIM = 3;
#endif
#endif
	MAMCR = 2;

	/* 初始化VIC */
	VICIntEnClr = 0xffffffff;
	VICVectAddr = 0;
	VICIntSelect = 0;

	/* 添加自己的代码 */
}

void PortInit( void )
{
	//*** 32bit PORT 0 P0.0--P0.15 GROUP function configuration_____________gongjun
	//Ports  :  P0.15    P0.14    P0.13    P0.12	P0.11    P0.10    P0.09    P0.08
	//Signal :  RI  	 CD 	  DTR     DSR      CTS  	RTS 	 RXD1     TXD1 
	//Binary :  01  	 01 	  01	   01   	01  	 01 	  01	   01
	//______________________________________________________________________________
	//Ports  :  P0.07    P0.06    P0.05    P0.04	P0.03    P0.02    P0.01    P0.00
	//Signal :  GPIO	 GPIO     GPIO     GPIO 	GPIO	 GPIO     RXD0     TXD0 
	//Binary :  00  	 00 	  00	   00   	00  	 00 	  01	   01
	//******************************************************************************
	PINSEL0 = ( 0x5555 << 16 ) | ( 0x0005 )  ;		// 设置P0.0--P0.15引脚功能

	//*** 32bit PORT 0 P0.0--P0.31 GROUP direction configuration_____________gongjun
	//Ports  :  P0.31    P0.30    P0.29    P0.28	P0.27    P0.26    P0.25    P0.24
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P0.23    P0.22    P0.21    P0.20	P0.19    P0.18    P0.17    P0.16
	//Signal :  I   	 I  	  o 	   I		o   	 I  	  I 	   I
	//Binary :  0   	 0  	  1 	   0		1   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P0.15    P0.14    P0.13    P0.12	P0.11    P0.10    P0.09    P0.08
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P0.07    P0.06    P0.05    P0.04	P0.03    P0.02    P0.01    P0.00
	//Signal :  I   	 o  	  o 	   o		I   	 o  	  I 	   o
	//Binary :  0   	 1  	  1 	   1		0   	 1  	  0 	   1
	//******************************************************************************
	IO0DIR = ( 0x00 << 24 ) | ( 0x28 << 16 ) | ( 0x00 << 8 ) | ( 0x75 )  ;		// 设置P0引脚方向

	//*** 32bit PORT 0 P0.16--P0.31 GROUP function configuration_____________gongjun
	//Ports  :  P0.31    P0.30    P0.29    P0.28	P0.27    P0.26    P0.25    P0.24
	//Signal :  GPIO	 GPIO     AIN2     AIN1 	AIN0	 GPIO     RD1      TD2 
	//Binary :  00  	 00 	  01	   01   	01  	 00 	  01	   01
	//______________________________________________________________________________
	//Ports  :  P0.23    P0.22    P0.21    P0.20	P0.19    P0.18    P0.17    P0.16
	//Signal :  RD2 	GPIO	 PWM5     GPIO     GPIO 	GPIO	 GPIO     GPIO 
	//Binary :  01  	 00 	  01	   00   	00  	 00 	  00	   00
	//******************************************************************************
	PINSEL1 = ( 0x0545 << 16 ) | ( 0x0400 )  ;		// 设置P0.16--P0.31引脚功能

	//*** 32bit PORT 1, PORT 2, PORT 3 GROUP function configuration__________gongjun
	//Ports  :  RESERVER P3.22:2  P3.1
	//Signal :  GPIO	 ADDR2:23 ADDR1 
	//Binary :  00  	 111	   1
	//______________________________________________________________________________
	//Ports  :  P3.00    P2.31    P2.30    P2.29:28 RESERVER P3.24
	//Signal :  ADDR0   GPIO	 GPIO     GPIO     GPIO 	CS3 
	//Binary :  1   	0   	 0  	  0 	   00   	01
	//______________________________________________________________________________
	//Ports  :  P3.25    P3.23    RESERVER P3.26	RESERVER RESERVER P3.27
	//Signal :  CS2 	 ADDR23   GPIO     CS1  	GPIO	 GPIO     nWE 
	//Binary :  01  	 1  	  0 	   1		0   	 0  	  1
	//______________________________________________________________________________
	//Ports  :  P3.28    P3.29    P1.2.3   P1.25:16 P1.31:26 RESERVER RESERVER
	//Signal :  GPIO	 GPIO     GPIO     DEBUG	GPIO	 GPIO     GPIO
	//Binary :  0   	 0  	  01	   1		0   	 0  	  0
	//******************************************************************************
	PINSEL2 = ( 0xf << 24 ) | ( 0x81 << 16 ) | ( 0x69 << 8 ) | ( 0x1c )  ;		// 设置P1-P2-P3引脚功能

	//*** 32bit PORT 0 P1.00--P1.31 GROUP direction configuration_____________gongjun
	//Ports  :  P1.31    P1.30    P1.29    P1.28	P1.27    P1.26    P1.25    P1.24
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   o
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   1
	//______________________________________________________________________________
	//Ports  :  P1.23    P1.22    P1.21    P1.20	P1.19    P1.18    P1.17    P1.16
	//Signal :  o   	 o  	  o 	   I		I   	 o  	  o 	   I
	//Binary :  1   	 1  	  1 	   0		0   	 1  	  1 	   0
	//______________________________________________________________________________
	//Ports  :  P1.15    P1.14    P1.13    P1.12	P1.11    P1.10    P1.09    P1.08
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P1.07    P1.06    P1.05    P1.04	P1.03    P1.02    P1.01    P1.00
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//******************************************************************************
	IO1DIR = ( 0x01 << 24 ) | ( 0xe6 << 16 ) | ( 0x00 << 8 ) | ( 0x00 ) ;		// 设置P1引脚方向

	//*** 32bit PORT 2 GROUP direction configuration_____________gongjun
	//Ports  :  P2.31    P2.30    P2.29    P2.28	P2.27    P2.26    P2.25    P2.24
	//Signal :  o   	 o  	  o 	   o		o   	 I  	  I 	   I
	//Binary :  1   	 1  	  1 	   1		1   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P2.23    P2.22    P2.21    P2.20	P2.19    P2.18    P2.17    P2.16
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P2.15    P2.14    P2.13    P2.12	P2.11    P2.10    P2.09    P2.08
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P2.07    P2.06    P2.05    P2.04	P2.03    P2.02    P2.01    P2.00
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//******************************************************************************
	IO2DIR = ( 0xf8 << 24 ) | ( 0x00 << 16 ) | ( 0x00 << 8 ) | ( 0x00 )  ;		// 设置P2引脚方向

	//*** 32bit PORT 3 GROUP direction configuration_____________gongjun
	//Ports  :  P3.31    P3.30    P3.29    P3.28	P3.27    P3.26    P3.25    P3.24
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P3.23    P3.22    P3.21    P3.20	P3.19    P3.18    P3.17    P3.16
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P3.15    P3.14    P3.13    P3.12	P3.11    P3.10    P3.09    P3.08
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//______________________________________________________________________________
	//Ports  :  P3.07    P3.06    P3.05    P3.04	P3.03    P3.02    P3.01    P3.00
	//Signal :  I   	 I  	  I 	   I		I   	 I  	  I 	   I
	//Binary :  0   	 0  	  0 	   0		0   	 0  	  0 	   0
	//******************************************************************************
	IO3DIR = ( 0x00 << 24 ) | ( 0x00 << 16 ) | ( 0x00 << 8 ) | ( 0x00 )  ;		// 设置P3引脚方向
}


/****************************************************************************
【功能说明】SRAM测试
****************************************************************************/
#define	USER_SRAM	( SIZE_512K - SIZE_128K )
void SRAM_Test( void )
{
	#define ADDRESS_ADD	0x10000
//#define ADDRESS_ADD	0x0

	U32 i, j ;
	U32 memError = 0 ;
	U32 start_adr, end_adr ;
	U32 value ;

	start_adr = SRAM_BASE + ADDRESS_ADD ;
	end_adr = SRAM_BASE + USER_SRAM ;
	value = 0xccaa5533 ;

	printf( "\nMemory Test(0x%xh--0x%xh) : WR\n" , start_adr , end_adr ) ;

	for ( i = start_adr; i < end_adr; i += 4 )
	{
		*( ( volatile unsigned * ) i ) = value ;
		if ( ( i % 0x10000 ) == 0 )
			SerialTxChar( '.' ) ;
	}

	printf( "\nMemory Test(0x%xh--0x%xh) : RD\n" , start_adr , end_adr ) ;

	for ( i = start_adr; i < end_adr; i += 4 )
	{
		j = *( ( volatile unsigned * ) i ) ;
		if ( j != value )
		{
			memError = 1 ;
			break ;
		}

		if ( ( i % 0x10000 ) == 0 )
			SerialTxChar( '.' ) ;
	}

	if ( memError == 0 )
		printf( "\n\nRAM Test is OK!\n" );
	else
	{
		printf( "\n\nMemory Test is FAIL!\n" ) ;
		printf( "  Write the memory address (0x%xh) with data (0x%xh)\n" , i ,
			i ) ;
		printf( "  But read the memory is 0x%xh!\n" , j ) ;
	}

}
/****************************************************************************
* 名称:PWM5_Set( U32 CYCLE_DATA, U32 DUTY_CYCLE_DATA )
* 功能:使用PWM5输出占空比可调的PWM波形。
* 参数说明:CYCLE_DATA表示PWM的周期是多少,范围是1--100000,对应于10us;
			DUTY_CYCLE_DATA占空比是多少,范围是1--100000,对应于0.001% - 100%
****************************************************************************/
void PWM5_Set( U32 CYCLE_DATA , U32 DUTY_CYCLE_DATA )
{
	PWMTCR = 0x02;				// 停止定时器,PWM禁止,复位定时器
	PWMPR = 0x00;				// 不分频,计数频率为Fpclk
	PWMMCR = 0x02;				// 设置PWMMR0匹配时复位PWMTC
	PWMMR0 = CYCLE_DATA * ( Fpclk / 100000 );		// 设置PWM周期
	PWMMR5 = DUTY_CYCLE_DATA * ( Fpclk / 100000 );		// 设置PWM占空比

	PWMLER = 0x21;				// PWMMR0、PWMMR5锁存
	PWMPCR = 0x2000;				// 允许PWM5输出,单边PWM
	PWMTCR = 0x09;				// 启动定时器,PWM使能
}

void PWM5_Stop( void )
{
	PWMMCR = PWMMCR | ( 1 << 17 ) ;
}		//停止PWM5

/****************************************************************************
【功能说明】PWM模式控制蜂鸣器
****************************************************************************/
void Beep( U32 time )
{
	PWM5_Set( 100 , 50 ) ;
	Delay( time ) ;
	PWM5_Stop() ;
}

/****************************************************************************
【功能说明】PWM模式控制蜂鸣器测试
****************************************************************************/

/****************************************************************************
【功能说明】PWM模式控制蜂鸣器测试
****************************************************************************/
void PWM5_Beep_Test(void)
{
	U16 CYCLE = 100;

	printf( "PWM5 Test( Beep ) !\n\n" ) ;
	printf( "Press +/- to increase/reduce the frequency of beep !\n" ) ;
	printf( "Press 'ESC' to Exit this test program !\n\n" );

	PWM5_Set( CYCLE , ( CYCLE / 2 ) ) ;

	while ( 1 )
	{
		U8 key;		

		key = getch();
		putch( key );

		if ( key == '+' )
			if ( CYCLE > 0 )
				CYCLE -- ;
		if ( key == '-' )
			if ( CYCLE < 10000 )
				CYCLE ++ ;

		if ( key == ESC_KEY )

⌨️ 快捷键说明

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