S3C2440的定时器实验

S3C2440的定时器1实验,用LED灯做测试,学习,参考。。。。。。。

程序代码:

 

#include "2440addr.h"

static char flag=0;
int bit=1<<11;

void  ClearPending (int bit)
{
  rSRCPND|=bit;  // TIME1
  rINTPND|=bit;   //TIME1

}


static void  __irq  time1_ISR(void)
{
    ClearPending (bit);
    flag++;
   if(flag==10)   //5s
   {
    rGPBDAT&=~((1<<5)|(1<<6)|(1<<8)|(1<<10));  //打开所有的灯
   }
   else if(flag==20)  //10s
   {
     rGPBDAT|=((1<<5)|(1<<6)|(1<<8)|(1<<10));//关闭所有的灯
     flag=0;
   }

}

void led_init()
{
 rGPBCON=0x555554;  //端口0配置为输入,其他均为输出
 rGPBUP=0x000000;   //开上拉
 rGPBDAT|=((1<<5)|(1<<6)|(1<<8)|(1<<10));//熄灭所有的灯
// rGPBDAT&=(0<<0);   //关闭蜂鸣器
 
}

void interrupt_init()
{
 pISR_TIMER1=(unsigned)time1_ISR;
 rSRCPND|=(1<<11);  // TIME1
 rINTPND|=(1<<11);   //TIME1
 rINTMSK&=~(1<<11);   //TIME1开中断


}

void time_init(void)
{
  rTCFG0=0x0000ff;   //定时器1的255分频
  rTCFG1=0xff0fff0f;//定时器1和DMA通道清0,即定时器1为1/2分频,DMA关闭
  rTCNTB1=0xbebc;   //定时器1赋初值,定时0.5s
  rTCON&=0xfff0ff;  //定时器1无手动更新,关闭变相,自动加载,定时器1启动
  rTCON|=0xfff9ff;
 
 }


 int ISMain(void)
{

  led_init();
  interrupt_init();
  time_init();
  while(1);

}

posted @ 2013-03-16 21:49  天涯海角路  阅读(92)  评论(0)    收藏  举报