微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > LPC2132 调试记

LPC2132 调试记

时间:11-10 来源:互联网 点击:

volatile unsigned TV:32;//32位定时值

unsigned long data;//作为参数被传入定时器处理函数

void (*function)(unsigned long);//callback

volatile unsigned TR:1;//起停标志,0-停止运行,1-开始运行

volatile unsigned TF:1;//溢出标志,0-未溢出,1-溢出

}Timer[TIMER_N];

/*

利用定时器T0模拟多个软件定时器

原创作者:21icbbs LPC900,2005-08

更改:May Wong 2008-6-13 (LPC2131)

特点:

只占用一个硬件定时器T0,就可以扩展出多达数十个以上的软件定时器

软件定时器基本定时单位是5ms,定时范围很宽:0.01~163.84s

软件定时器数量可以按需要设定,

利用定时器T0的自动重装特性,能够实现所有软件定时器的精确定时

所有软件定时器都工作在32位倒计时方式,用TR和TF位控制,使用极为方便

第0号定时器专门用于Delay()函数,其它定时器可供用户程序自由使用

*/

/*

函数:TimerOn()

功能:启动定时器

参数:

t:定时器初值,取值0~4294967295

t>0时,定时(0.01*t)s

t=0时,定时163.84s

unsigned long data:作为参数被传入定时器处理函数

 void (*function)(unsigned long): callback function

return:-1(error)else定时器序号

*/

int TimerOn(unsigned int t,unsigned long funpara,void(*function)(unsigned long))

{

unsigned int i;

INT32U da_year,da_mon,da_day,ti_hour,ti_min,ti_sec;/*test start time*/

for (i = 1; i < TIMER_N;i++)

{

if (Timer[i].TR == 0)

{

//Timer[i].TR = 0;

Timer[i].TF = 0;

Timer[i].TV = t;

Timer[i].TR = 1;

Timer[i].function = function;

Timer[i].data = funpara;

break;

}

}

if (i == TIMER_N)

return -1;

else

returni;

}

/*

函数:TimerOff()

功能:关闭定时器

参数:

n:定时器序号

*/

void TimerOff(unsigned char n)

{

Timer[n].TR = 0;

Timer[n].TF = 0;

}

/*

函数:Delay()

功能:延时0.01~163.84s

参数:

t:延时参数,取值0~16383

t>0时,延时(0.01*t)s

t=0时,延时163.84s

*/

void Delay(unsigned int t)

{

Timer[0].TR = 0;

Timer[0].TF = 0;

Timer[0].TV = t;

Timer[0].TR = 1;

// TimerOn(t,NULL,NULL);

for (;;)

{

//PCON |= 0x01;

T0TCR |= 0x01;/*reset*/

if (Timer[0].TF)

{

TimerOff(0);

break;

}

}

}

/*********************************************************************************************************

** Function name:Timer0_Exception

**

** Descriptions:Timer0 interrupt service function

**

** input parameters:None

** Returned value:None

**

** Used global variables:None

** Calling modules:None

**

**------------------------------------------------------------------------------------------------------

********************************************************************************************************/

/*

函数:Timer0_Exception()

功能:定时器中断服务函数,每(Fcclk / 4) * 1/ 200中断1次

*/

void Timer0_Exception(void)

{

//unsigned char i;

unsigned int i;

//TF2 = 0;

for ( i=0; i

{

//beep();//beep ok

if (Timer[i].TR)

{

if ( --Timer[i].TV == 0 )

{

UART0Putch(0);

Timer[i].TF = 1;

TimerOff(i);

(Timer[i].function)(Timer[i].data);

UART0Putch(0);

//beep();

//UART0Putch(0);

}

}

}

T0IR = 0x01;/* match tunnel 1 intrrupt flag清除中断标*/

VICVectAddr = 0;//interrupt close通知中断控制器中断结束

OSTimeTick();

}

/*********************************************************************************************************

** Function name:Timer0Init

**

** Descriptions:Initialize the Time0

**

** input parameters:None

** Returned value:None

**

** Used global variables:None

** Calling modules:None

**-------------------------------------------------------------------------------------------------------

** Modified by:

** Modified date:

**------------------------------------------------------------------------------------------------------

********************************************************************************************************/

void Timer0Init(void)

{

unsigned int x;

unsigned char i;

for ( i=0; i

{

Timer[i].TR = 0;

Timer[i].TF = 0;

Timer[i].TV = 0;

}

T0IR = 0xffffffff;/*timer intrrupt register1 reset*/

T0PR= 0;/*时钟不分频*/

T0TC = 0;/*counter*/

T0TCR = 0x01;/*counter control reginster 1

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top