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

📄 target.c

📁 给大家提供一个在inram/exram中调试的示例,在周公的lpc2200上调试过.
💻 C
字号:
#define		LPCEB2000_I
#define		Target_C
/**********************************************************************************************
*File:		target.c
*Author:	Embest w.h.xie	2005.03.17
*Desc:		cortrol code
*History:	
*		
*comment:
**********************************************************************************************/

/*------------------------------------------------------------------------------------------*/
/*								include files												*/
/*------------------------------------------------------------------------------------------*/

#include   "LPC_api.h"
#include   "target.h"

/*------------------------------------------------------------------------------------------*/
/*	 							global variable define										*/
/*------------------------------------------------------------------------------------------*/
							  
// led show variable 0-F
const   uint32 lLedDisp[17] = {	LED_CHAR_0, LED_CHAR_1, LED_CHAR_2, LED_CHAR_3,
								LED_CHAR_4, LED_CHAR_5, LED_CHAR_6, LED_CHAR_7,
								LED_CHAR_8, LED_CHAR_9, LED_CHAR_A, LED_CHAR_B,
								LED_CHAR_C, LED_CHAR_D, LED_CHAR_E, LED_CHAR_F,
								LED_DEC}; 

/*********************************************************************************************
* name:		time_dly
* func:		display code
* para:		dly			--in, delay value
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void  time_dly(uint32  dly)
{  
	uint32  i;

	for(; dly>0; dly--) 
		for(i=0; i<100; i++);
}

/*********************************************************************************************
* name:		led_init
* func:		init the led control port and init the display buffer
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void  led_init(void)
{
	uint8	i;
	
	PINSEL0 &= 0x000FFFFF;	
	PINSEL1 &= 0xFFFFFF00;

	// choose led control port and data port set out
	IODIR0 |= LED_BIT_CON;
	IODIR0 |= LED_SEG_CON;
	IODIR0 |= LED_OUT_CON;
	IODIR0 |= LED_CON;

	IOCLR0 =  LED_BIT_CON | LED_SEG_CON | LED_CON;	

	// init Led value
	szLedLast  = 8;
	szLedBase  = 0;
	szLedIndex = 0;	
	szLedpoint = 0;
	for (i=0; i<szLedLast ; i++) {
		szLedChr[i] = 0x10;
	}

	// init Led show order
	szLedOrd[0] = 1 << 0;
	szLedOrd[1] = 1 << 1;
	szLedOrd[2] = 1 << 2;
	szLedOrd[3] = 1 << 3;
   
	szLedOrd[4] = 1 << 4;
	szLedOrd[5] = 1 << 5;
	szLedOrd[6] = 1 << 6;
	szLedOrd[7] = 1 << 7;
}

/*********************************************************************************************
* name:		led_show
* func:		Led show out
* para:		szLedBit	--	in, Led show bit
*			szLedchar	--	in, Led show data
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void  led_show(uint32 szshowBit, uint32 szshowchar)
{
	// Led bit cortrol
	IOSET0 = LED_BIT_CON;
	IOSET0 = LED_OUT_CON;
	IOCLR0 = LED_BIT_CON;

	// Led segment cortrol
	IOSET0 = LED_SEG_CON;
	IOCLR0 = LED_OUT_CON;
	IOSET0 = szshowchar;
	IOCLR0 = LED_SEG_CON;

	// Led bit cortrol
	IOSET0 = LED_BIT_CON;
	IOSET0 = LED_OUT_CON;
	IOCLR0 = szshowBit;
	IOCLR0 = LED_BIT_CON;
}
/*********************************************************************************************
* name:		led_brush
* func:		led_brush fun
* para:		none
* ret:		none
* modify:
* comment:	
*********************************************************************************************/
void led_brush(void)
{
	uint32	lPrint = 0;

	// count show Led bit
	szLedIndex += 1;
	if (szLedIndex > szLedLast)  szLedIndex = szLedBase;

	// account show Led char
	if (szLedpoint & (1 << szLedIndex))
		lPrint = lLedDisp[szLedChr[szLedIndex]] | LED_DP;
	else
		lPrint = lLedDisp[szLedChr[szLedIndex]];

	// refurbish show LED
	led_show((szLedOrd[szLedIndex] << 10), lPrint);
}

/*********************************************************************************************
* name:		GPIO0_init
* func:		init P0.0-P0.31
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void  GPIO0_init(void)
{
	PINSEL0 = 0x00000000;
	PINSEL1 = 0x00000000;
}

/*********************************************************************************************
* name:		key_init
* func:		init key P1.16-P1.23
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void  key_init(void)
{
	PINSEL2 &= ~0x08;

	IODIR1  &= ~KEY_COL;
	IODIR1  |= KEY_ROW;
	IOCLR1  = KEY_ROW;
}

/*********************************************************************************************
* name:		get_key
* func:		get a key no
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
uint8 get_key(void)
{
	uint8   i, ucKeyIn, ucKeyNo;

	ucKeyIn = (IOPIN1 >> 16) & 0x0F ;							// scan key port
	   
	if (ucKeyIn != 0x0F) {
		time_dly(5);											// delay and dithering
		ucKeyIn = (IOPIN1 >> 16) & 0x0F ;
		 
		if (ucKeyIn != 0x0F) {
			// scan row
			for (i=4 ; i>0 ; i--) {
				if (!(ucKeyIn & (0x10 >> i))) break;			   
			}  
			ucKeyNo = 4 - i ;									// save the row
			
			// scan col
			for (i=0 ; i<4 ; i++) {
				IOSET1 = 0x0F << 20;
				IOCLR1 = 0x01 << (i + 20);
				ucKeyIn = (IOPIN1 >> 16) & 0x0F;
				if (ucKeyIn != 0x0f) break;			   
			}
			
			IOCLR1 = 0x0F << 20;								// save the COL
				
			ucKeyNo += 4 * i;									// count the key value
			
			if (i < 4) {
				return(ucKeyNo);
			}
		}
	}
	
	return(0xff);
}

⌨️ 快捷键说明

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