主题 : 帮我看一下这个代码 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 17673
精华: 0
发帖: 29
金钱: 145 两
威望: 29 点
贡献值: 0 点
综合积分: 58 分
注册时间: 2010-03-31
最后登录: 2011-02-24
楼主  发表于: 2010-04-11 14:20

 帮我看一下这个代码

管理提醒: 本帖被 kasim 从 QQ2440技术交流专区 移动到本区(2010-04-11)
#include "./include/def.h"
#include "./include/option.h"
#include "./include/2440addr.h"
#include "./include/2440lib.h"
#include "./include/2440slib.h"



#define SUB_BIT_WDT (0x01 << 13)

static int int_count;
static __irq void Timer0_Int(void);
void Timer0_Start(void);

static __irq void Watchdog_Int(void);
void Watchdog_Start(void);


void Main(void)
{
    char *mode;
    U8 key;
    U32 mpll_val = 0 ;
    
    MMU_Init();
    Port_Init();
    
    
    key = 14;
    mpll_val = (92<<12)|(1<<4)|(1);
    
    ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
    ChangeClockDivider(key, 12);
    
    Uart_Init( 0,115200 );
    Uart_Select(0);
    
    
        Uart_Printf("\n\n\n\n\n\n");
    Uart_Printf("                    从本行开始为定时器中断与看门狗测试\n");
    Uart_Printf("***************************************************************************\n");
    Uart_Printf("*              作者:soonn");
    Uart_Printf("*              部门:计算机07级04班\n");
    Uart_Printf("*              最后修改时间:2010.4.9\n");
    Uart_Printf("***************************************************************************\n");
    
    Timer0_Start();
    Watchdog_Start();

    while(1);

}

static __irq void Timer0_Int(void)
{
     Uart_Printf("********************Timer0Interrupt****************\n");
     rSRCPND = BIT_TIMER0;
     rINTPND = BIT_TIMER0;
}

void Timer0_Start(void)
  {
     int i;
     rTCFG0 = 0xFF;// 定时器0,1的预分频值为255
     rTCFG1 = 0x2; // 定时器0的时钟分割器采用1/8分频
     rTCNTB0 = 25600;
     rTCON = 0x06;
     for(i=0;i<1000;i++);
     rTCON = 0x09;
     pISR_TIMER0 = (unsigned int)Timer0_Int;
     rINTMSK &= (~BIT_TIMER0);
}



static __irq void Watchdog_Int(void)
{
        Uart_Printf("\nWatchdog interrupt %d times",++int_count);
        rSUBSRCPND = SUB_BIT_WDT;
        rSRCPND = BIT_WDT_AC97;
        rINTPND = BIT_WDT_AC97;
}

void Watchdog_Start(void)
{
      
        rWTCNT = 16000;
        rWTDAT = 16000;
        pISR_WDT_AC97 = (unsigned int)Watchdog_Int;
        rINTMSK &= (~BIT_WDT_AC97);
        rINTSUBMSK &= (~SUB_BIT_WDT);
        // 0xFF3C=不产生复位信号 0xFF3D=产生复位信号,约10秒后系统复位
        rWTCON = 0xFF3C;
}

我用的是Mini2440的开发板,这个程序在我的板子上不能进行中断,不知道是什么原因。那位大哥用相同的块子帮我试一下,看是我的板子有问题还是什么。
好像是定时器不能正常工作。
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2010-04-11 14:31
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 17673
精华: 0
发帖: 29
金钱: 145 两
威望: 29 点
贡献值: 0 点
综合积分: 58 分
注册时间: 2010-03-31
最后登录: 2011-02-24
2楼  发表于: 2010-04-11 15:16
谢谢版主,问题果然解决,还是自己动手好啊,要不然看懂了,也不一定能写得出来。
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2010-04-11 15:32
还是自己动手好啊,要不然看懂了,也不一定能写得出来

先看懂,然后再动手。
要感谢的话,多分享点经验就可以了。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."