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

📄 config.c.bak

📁 LPC2146 的USB 开发
💻 BAK
字号:
#include "lpc2136config.h"
#include "type.h"

extern volatile uint8 usart0_signal_flags;  						//	串口0的通讯标识

extern IRQ_UART0(void);


__inline void interrupt_config(void)
{
	IRQEnable();						//	使能IRQ中断
	VICIntSelect=0x00000000;			//	设置所有的通道为IRQ中断
	VICVectCntl0=0x20|06;				//	UART0分配到IRQ slot0,即最高优先级
	VICVectAddr0=(uint32)IRQ_UART0;		//	设置UART0向量地址
	VICIntEnable=1<<06;					//	使能UART0
}	

__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做调试口
}

__inline void timer_config()
{
    T0CTCR=0X00000000;		//	定时器模式
    T0PR=0x00000000;		//	不再分频
    T0TCR=0x00000001;		//	使能定时器0
    
    T1CTCR=0X00000000;		//	定时器模式
    T1PR=0x00000229;		//	11.0592*5=55.296MHz,10us时基
    T1TCR=0x00000001;		//	使能定时器1
}    
    
void config_system(void)
{	
	port_config();
	interrupt_config();		//	中断初始化
	usart0_config();		//	串口初始化
	pwm_config();			//	PWM初始化
	timer_config();			//	定时器初始化
}	

⌨️ 快捷键说明

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