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

📄 target.c

📁 在LPC2132的ARM处理器上
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			target.c
** Last modified Date:	2004-09-17
** Last Version:		1.0
** Descriptions:		header file of the specific codes for LPC2100 target boards
**						Every project should include a copy of this file, user may modify it as needed
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-02-02
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Chenmingji
** Modified date:		2004-09-17
** Version:				1.01
** Descriptions:		Renewed the template, added more compiler supports 
**
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version:	
** Descriptions: 
**
********************************************************************************************************/

#define IN_TARGET
#include "config.h"

/*********************************************************************************************************
** Function name:			IRQ_Exception
**
** Descriptions:			interrupt exceptional handler , change it as needed
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void IRQ_Exception(void)
{
    while(1);                   // change it to your code  这一句替换为自己的代码
}

/*********************************************************************************************************
** Function name:			FIQ_Exception
**
** Descriptions:			Fast interrupt exceptional handler , change it as needed
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void FIQ_Exception(void)
{
    while(1);                   // change it to your code  这一句替换为自己的代码
}
/*********************************************************************************************************
** Function name:			Timer0_Exception
**
** Descriptions:			Timer0 interrupt service function
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Timer0_Exception(void)
{
    T0IR = 0x01;
    VICVectAddr = 0;            //interrupt close 通知中断控制器中断结束
    OSTimeTick();
}

/********************************************************************************************************/
uint16 Deal_ADData(void)
{
	uint32	ADC_Data;
	
	ADCR |= 1 << 24;					// 进行一次转换
	while ((ADDR & 0x80000000) == 0);	// 等待转换结束
	
	ADC_Data = ADDR;					// 读取ADC结果
	
	ADCR &= ~(1 << 24);					// 停止转换
		
	ADC_Data = (ADC_Data >> 6) & 0x3ff;
	
	return	(uint16)ADC_Data;
	
}

/********************************************************************************************************/
void Send_DAData(int16	Data)
{
	Data &= 0x03ff;
	Data = (Data << 6);
		
	DACR = Data;
}

uint8  test_data;
uint16  buf[10];
uint8 	novoice_flag;
uint8 	novoice_count;
/********************************************************************************************************/
void Timer1_Exception(void)
{	
	uint16  data, temp, max, min;
	
	OS_ENTER_CRITICAL();
	
    T1IR = 0x01;
    
    data = Deal_ADData();
    Send_DAData(data);
    
#if 0    
	IOCLR = 0x80000000;				/* 设置P0.31输出为0*/		    
    buf[0] = Deal_ADData();
    buf[1] = Deal_ADData();
    buf[2] = Deal_ADData();
    buf[3] = Deal_ADData();
    buf[4] = Deal_ADData();
		
	max = buf[0];
	if (max < buf[1])
		max = buf[1];
	if (max < buf[2])
		max = buf[2];
	if (max < buf[3])
		max = buf[3];
	if (max < buf[4])
		max = buf[4];
	
	min = buf[0];	
	if (min > buf[1])
		min = buf[1];
	if (min > buf[2])
		min = buf[2];
	if (min > buf[3])
		min = buf[3];
	if (min > buf[4])
		min = buf[4];
		
    temp = (buf[0] + buf[1] + buf[2] + buf[3] + buf[4] - max - min) / 3;

#if 1    
    if ((temp > 0x258) || (temp < 0x1e8)){
    	novoice_flag = 0x00;			//静噪关闭
    	novoice_count = 0x00;
    }
    else if (novoice_count >= 128)
    		novoice_flag = 0x01;		//静噪开启
    	else novoice_count += 0x01;
    
    if (novoice_flag == 0x00)	
    	Send_DAData(temp);
    else Send_DAData(0x230);
#endif

    IOSET = 0x80000000;				/* 设置P0.31输出为1*/
        
	switch(Voice_Status)
	{
		case 0x01:
			data = Deal_ADData();
			Voice_Buf[voice_index][pack_count++] = data; 
			if (pack_count >= 132){
		
				voice_index ^= 0x01;
				pack_count = 0x00;
		
				if (voice_page_count < 1024){
			
					if((test_data & 0x01) == 0x00)
						IOCLR |= PIC_COMU_LED;					/* 设置P0.10输出为0 D22 亮*/
					else IO0SET |= PIC_COMU_LED;				/* 设置P0.10输出为1 D22 灭*/
	
					test_data += 0x01;
					voice_page_count += 0x01;
					OSMboxPost(VoiceMbox, &voice_page_count);
				}
			
			}                
            break; 
        
        case 0x02:
        	data = Voice_Buf[voice_index][pack_count++];
            Send_DAData(data);
            if (pack_count >= 132){
		
				voice_index ^= 0x01;
				pack_count = 0x00;
		
				if (voice_page_count < 1024){
			
					if((test_data & 0x01) == 0x00)
						IOCLR |= PIC_COMU_LED;					/* 设置P0.10输出为0 D22 亮*/
					else IO0SET |= PIC_COMU_LED;				/* 设置P0.10输出为1 D22 灭*/
	
					test_data += 0x01;
					voice_page_count += 0x01;
					OSMboxPost(VoiceMbox, &voice_page_count);
				}
			
			}             
            break;
                             		
        default:
            break;
	}
#endif
				
	VICVectAddr = 0;            				//interrupt close 通知中断控制器中断结束
	OS_EXIT_CRITICAL();
	
}
/*********************************************************************************************************
** Function name:			Timer0Init
**
** Descriptions:			Initialize the Time0
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Timer0Init(void)
{
    T0IR = 0xffffffff;
    T0TC = 0;
    T0TCR = 0x01;
    T0MCR = 0x03;
    T0MR0 = (Fpclk / OS_TICKS_PER_SEC);
 }
 
/********************************************************************************************************/ 
void Timer1Init(void)
{
    T1IR = 0xffffffff;
    T1TC = 0;
    T1TCR = 0x01;
    T1MCR = 0x03;
    T1MR0 = (Fpclk / 8000);   
    
    novoice_count = 0x00;
    novoice_flag = 0x01;
 }
 
/********************************************************************************************************/
void ADInit(void)
{
	PINSEL1 |= (1 << 28);			// P0.30连接到AIN3功能
	PINSEL1 |= (1 << 19);			// P0.25连接到DA功能
	
    ADCR = (1 << 3)						|	// SEL=8,选择通道3
		((Fpclk / 1000000 - 1) << 8)	|	// CLKDIV=Fpclk/1000000-1,转换时钟为1MHz
		(0 << 16)						|	// BURST=0,软件控制转换操作
		(0 << 17)						|	// CLKS=0, 使用11clock转换
		(1 << 21)						|  	// PDN=1,正常工作模式
		(0 << 22)						|  	// TEST1:0=00,正常工作模式
		(0 << 24)						|	// START=0,不启动ADC转换
		(0 << 27);						 	// 直接启动ADC转换时,此位无效
			
}

/*********************************************************************************************************
** Function name:			VICInit
**
** Descriptions:			Initialize the Interrupt Vevtor Controller
**
** input parameters:		None
** Returned value:			None
**         
** Used global variables:	None
** Calling modules:			None
**
** Created by:				Chenmingji
** Created Date:			2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

⌨️ 快捷键说明

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