ARM定时器

time.h

#ifndef _S3C2451_TIMER_H
#define _S3C2451_TIMER_H
#include "typedef.h"
typedef struct{
                U32 TCFG0;
	              U32 TCFG1;
	              U32 TCON;
	   
	              U32 TCNTB0;
								U32 TCMPB0;
								U32 TCNTO0;
								
								U32 TCNTB1;
								U32 TCMPB1;
								U32 TCNTO1;
								
								U32 TCNTB2;
								U32 TCMPB2;
								U32 TCNTO2;
								
								U32 TCNTB3;
								U32 TCMPB3;
								U32 TCNTO3;
								
								U32 TCNTB4;
								U32 TCNTO4;   
                  }volatile *TIM_MemMapPtr;
#define TIM_BASE_PTR        ((TIM_MemMapPtr)0x51000000)
									
typedef enum{
	            time_ch0=0,
	            time_ch1,
	            time_ch2,
	            time_ch3,
	            time_ch4

               }TIM_typedef;

typedef struct{
                unsigned int TIM_Scale;
                unsigned int TIM_Prescale;
	              unsigned int TIM_Countval;
	              unsigned int TIM_Compareval;
                      }TIM_basetypedef;

extern void TIM_init(TIM_typedef timx,TIM_basetypedef tim_basetypedef);
extern void TIM_Interrupt_init(TIM_typedef timx,U32 addr);
extern U16 TIM_getcount(TIM_typedef timx);

#endif
timer.c

#include "s3c2451_timer.h"
#include "s3c2451_vector.h"

 void TIM_init(TIM_typedef timx,TIM_basetypedef tim_basetypedef)
 { 
	 TIM_BASE_PTR->TCFG0 &=~0xff;
	 TIM_BASE_PTR->TCFG0 |=199;
	 
	 TIM_BASE_PTR->TCFG1 &=~0X0F;
	 TIM_BASE_PTR->TCFG1 |=0X2;
	 
	 TIM_BASE_PTR->TCNTB0=41250;
	 TIM_BASE_PTR->TCMPB0=20625;
	 TIM_BASE_PTR->TCON  |=(1<<3);
	 TIM_BASE_PTR->TCON  |=(1<<1);
	 TIM_BASE_PTR->TCON  |=(1<<0);
	 
	 TIM_BASE_PTR->TCON  &=~(1<<1);


 }
 
 U16 TIM_getcount(TIM_typedef timx)
 {
   return TIM_BASE_PTR->TCNTO0;

}

void TIM_Interrupt_init(TIM_typedef timx,U32 addr)
{ 
	if(timx==time_ch0)
	{
      pISR_TIMER0=addr;
  }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值