歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

S3C2440定時器的使用

S3C2440定時器的使用

#include "mytimer.h"
#include "lhg_def.h"
#include "uart.h"
#include "lhg_def.h"
#include "2440addr.h"

//Timer input clock Frequency = PCLK / {prescaler value+1} / {divider value}
//PCLK=50Mhz
//prescaler : 0~255
#define prescaler234 99
//divider : 1/2,1/4,1/8,1/16 選擇為(0,1,2,3)
#define divider4 2
//定時器設置為62500HZ


void __irq timer4ISP(void) //中斷函數
{
  rSRCPND |= rSRCPND|(0x1<<14);
  rINTPND |= rINTPND|(0x1<<14);
 
  Uart_Printf("now in timer4 interrupt~~ ");
}

void mytimer_init(void)//初始化定時器
{
   Uart_Printf("timer4 init/r/n");
  //設置中斷入口
  pISR_TIMER4 = (U32)timer4ISP;
  rTCFG0 &=~(0xff<<8);
  rTCFG0 |= prescaler234<<8;
  rTCFG1 &=~(0xf<<16);
  rTCFG1 |= divider4<<16;
  rTCNTB4 = 62500;//16位的 count buffer register
  //rTCNTO4 = //16位的 count observation value for Time 4
  rTCON |= (1<<22)|(1<<21)|(1<<20);//自動裝載,啟動定時器
  rTCON &= ~0x200000 ;   //定時器4開始工作
  //關於中斷
  rSRCPND |= rSRCPND|(0x1<<14);
  rINTPND |= rINTPND|(0x1<<14);
  rINTMSK &= ~(0x1<<14);
}

Copyright © Linux教程網 All Rights Reserved