fsyhrb
驱动牛犊
驱动牛犊
  • 注册日期2002-03-13
  • 最后登录2005-06-08
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1405回复:2

谁能给一个tsm320vc33的c语言例程

楼主#
更多 发布于:2003-05-07 10:23
最好有定时器中断处理的和外部寄存器操作的,谢了
fsyhrb
驱动牛犊
驱动牛犊
  • 注册日期2002-03-13
  • 最后登录2005-06-08
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-05-07 10:24
我的email:fsyhrb@sina.com
lyingying
驱动牛犊
驱动牛犊
  • 注册日期2003-03-20
  • 最后登录2007-09-12
  • 粉丝0
  • 关注0
  • 积分60分
  • 威望6点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-05-11 11:51
=== timer.h====
#ifndef _C3X_TIMER_h
#define _C3X_TIMER_h


#define C33_MIPS  (40000000)                                  
                                  
typedef struct TIMER_CTRL
{
   unsigned int ulTimerCtrl;
   unsigned int ulDummy1[3];
   unsigned int ulTimerCount;
   unsigned int ulDummy2[3];
   unsigned int ulTimerPeriod;
   unsigned int ulDummy3[3];
} TimerCtrl;

extern  TimerCtrl  structTimerCtrl[]; /* timer 0 and timer 1, located at 0x808020 */

extern  void timerInit(TimerCtrl *ptrTimerCtrl);
extern  void timerSetup(TimerCtrl *ptrTimerCtrl, unsigned int ulPeriod);  /* period in ms*/
extern  void StartTimer(TimerCtrl *ptrTimerCtrl);
extern  void StopTimer(TimerCtrl *ptrTimerCtrl);
extern  void c_int08();  /*  interrupt for timer 0 */
extern  void c_int09();  /*  interrupt for timer 1 */
                                  
#endif /*  #ifndef _C3X_TIMER_h */


===== timer.c =======

#include \"timer.h\"


TimerCtrl  structTimerCtrl[2];

/* the following two counters, or any other globals,
   should not be difined in timer file. Otherwise, they
   will be allocated in the peripheral area and will
   overwrite IO registers.\\
  
   work around: define them in other files and use extern
   in this file to reference them*/
  
extern unsigned int ulTimer0Count;
extern unsigned int ulTimer1Count;  
                      
void timerInit(TimerCtrl *ptrTimerCtrl)
{          
  disable_interrupt();
  ptrTimerCtrl->ulTimerCtrl = 0x241;
  ptrTimerCtrl->ulTimerCount = 0;
  ptrTimerCtrl->ulTimerPeriod = 0;
  enable_interrupt();
}


/* period in ms */
void timerSetup(TimerCtrl *ptrTimerCtrl, unsigned int ulPeriod)
{
  disable_interrupt();

  /* calculation of period:
     ulPeriod is in ms, convert to s
    
     ulPeriod*1e-3 / (1/ (C33_MIPS/2))=C33_MIPS*ulPeriod/2/1000*/
  ptrTimerCtrl->ulTimerPeriod = C33_MIPS*ulPeriod/2/1000;
  enable_interrupt();
}

void StartTimer(TimerCtrl *ptrTimerCtrl)
{          
  disable_interrupt();
  ptrTimerCtrl->ulTimerCtrl = 0x2C1;
  enable_interrupt();
}
                      
void StopTimer(TimerCtrl *ptrTimerCtrl)
{          
  disable_interrupt();
  ptrTimerCtrl->ulTimerCtrl = 0x241;
  enable_interrupt();
}

#pragma INTERRUPT(_c_int08)
void c_int08()
{
   asm(\" NOP \");  
   ulTimer0Count++;
}

#pragma INTERRUPT(_c_int08)
void c_int09()
{
   asm(\" NOP \");  
   ulTimer1Count++;
}
游客

返回顶部