www.pudn.com > lpc2146USB.rar > config.c


#include "lpc2136config.h" 
#include "type.h" 
 
extern volatile uint8 usart0_signal_flags;  						//	串口0的通讯标识 
 
extern IRQ_UART0(void); 
 
extern T0isr (void); 
extern Usb_Exception(void); 
 
__inline void interrupt_config(void) 
{ 
	IRQEnable();							//	使能IRQ中断 
	VICIntSelect=0x00000000;				//	设置所有的通道为IRQ中断 
	VICVectCntl0=0x20|06;					//	UART0分配到IRQ slot0,即最高优先级 
	VICVectAddr0=(uint32)IRQ_UART0;			//	设置UART0向量地址 
	 
	VICVectCntl3=(0x20|22); 
	VICVectAddr3=(uint32)Usb_Exception; 
	//VICIntEnable|=1<<22; 
	 
	VICVectAddr4 = (uint32)T0isr; 			//  Set the timer ISR vector address 
	VICVectCntl4 = 0x20|04;					//0x00000024;	//  Set channel	 
	VICIntEnable = 0x00400050;				//  Enable the interrupt 
 
}	 
 
__inline void usart0_config(void) 
{ 
    uint32 Fdiv; 
    U0LCR=0x83;               			/* 8 bits, no Parity, 1 Stop bit    */ 
    Fdiv=(Fpclk/16)/115200 ;			/*baud rate */ 
    U0DLM=Fdiv/256;							 
    U0DLL=Fdiv%256;	 
    U0LCR=0x03;               			/* DLAB = 0                         */ 
    U0FCR=0x07;							/* Enable and reset */ 
	U0IER=0x01;							//	允许RBR中断,即接收中断 
	usart0_signal_flags=0;				//	清空标志 
} 
/* 
__inline void  EnableIRQ(void) 
{   
	int  tmp; 
	__asm 
   	{ 
   		MRS	tmp, CPSR 
      	BIC   tmp, tmp, #0x80 
      	MSR   CPSR_c, tmp  
   	} 
} 
*/ 
__inline void pwm_config(void) 
{ 
	PWMTCR=0x00000002;			/* Counter Reset */  
	PWMPR=27;					/* count frequency:Fpclk */ 
    PWMMCR=0x00;				 	//不使用中断 
    PWMMR0=1000;				/* set PWM cycle */ 
    PWMMR5=350; 
    PWMLER=0x20; 
    PWMPCR=0x2000; 
    PWMTCR=0x00000009;			/* counter enable, PWM enable */ 
} 
 
__inline void port_config(void) 
{ 
	IODIR=0x00B00C04;		//	0000 0000   
							//	1011 0000  		P022 P020 P019	输出 
							//	0000 1100		P011 P010		输出 
							//	0000 0100 		P002			输出 
	 
	IO1DIR=0x00000000;		//	目前全做输入 
	 
	PINSEL0=0x80001505;		//	1000 0000	EINT2=P015	 
							//	0000 0000 
							//	0001 0101	SPI0=P006 P005 P004 
							//	0000 0101	RxD0=P001 TxD0=P002   
     
    PINSEL1=0x120804aa;		//	0001 0010	AD03=P030 CAP02=P028 
    						//	0000 1000	DAC=P025 
    						//	0000 0100	PWM5=P021 
    						//	1010 1010	SPI1=P019 P018 P017 MAT02=P016 
     
    PINSEL2=0x00000004;		//	P131--P126做调试口 
} 
 
 
/*============================================================ 
* 
* 函 数 名:timer_config 
* 
* 参  数:Null 
* 
* 功能描述: 
* 
*    Timer0初始化函数,设置T0定时产生中断,若T0PR=0x00,则可以改变T0MR0来决定 
*		中断产生的间隔;若T0MR0为固定值1,则可以修改T0PR的值,来决定中断产生的间隔; 
*		 
*		T0PR value     time			OR		T0MR0		Time      
*		 
*		0x00000229     10us;		||		Fpclk		1s 
*		0x0000159a     100us		||		Fpclk/10	100ms		 
*		0x0000d804     1000us		||		Fpclk/100	10ms 
*		0x00087028     10ms			||		Fpclk/1000	1ms 
*		0x00546190     100ms		|| 
*		0x034bcfa0     1s			|| 
* 
* 返 回 值:Null 
* 
* 作  者:Sha zq	日期:2007/03/016 
* 
============================================================*/ 
__inline void timer_config() 
{	 
	T0TC   = 0x00000000;			/* 定时器设置为0*/ 
	T0PR   = 0x00000000;			/* 时钟不分频=00*/ 
	T0MCR  = 0x00000003;			/* 设置T0MR0匹配后复位T0TC,并产生中断标志	*/ 
	T0MR0  = Fpclk/10;				/* 10毫秒定时	*/ 
	T0TCR = 0x00000003;									 
	T0TCR  = 0x00000001;			/* 启动定时器	*/ 
  
    T1CTCR=0X00000000;				//	定时器模式 
    T1PR=0x00000229;				//	11.0592*5=55.296MHz,10us时基;T1PR = 时基*系统工作频率 
    T1TCR=0x00000001;				//	使能定时器1 
 }      
  
 
void config_system(void) 
{	 
	port_config(); 
	interrupt_config();		//	中断初始化 
	usart0_config();		//	串口初始化 
	pwm_config();			//	PWM初始化 
	timer_config();			//	定时器初始化 
}