0

我有一些通用的标题,我在其中声明它(在std.h):

static volatile unsigned int timestamp;

我有中断,我增加它(在main.c):

void ISR_Pit(void) {
    unsigned int status;
    /// Read the PIT status register
    status = PIT_GetStatus() & AT91C_PITC_PITS;
    if (status != 0) {
        /// 1 = The Periodic Interval timer has reached PIV since the last read of PIT_PIVR.
        /// Read the PIVR to acknowledge interrupt and get number of ticks
        ///Returns the number of occurrences of periodic intervals since the last read of PIT_PIVR.
        timestamp += (PIT_GetPIVR() >> 20);
        //printf(" --> TIMERING :: %u \n\r", timestamp);
        }
    }

在另一个模块中,我有必须使用它的程序(在meta.c):

void Wait(unsigned long delay) {
    volatile unsigned int start = timestamp;
    unsigned int elapsed;
    do {
        elapsed = timestamp;
        elapsed -= start;
        //printf(" --> TIMERING :: %u \n\r", timestamp);
        }
    while (elapsed < delay);
    }

首先printf显示正确增加timestamp,但等待printf总是显示0。为什么?

4

1 回答 1

4

您将变量声明为static,这意味着它在包含它的文件中是本地的。timestampin与 inmain.c不同meta.c

你可以通过这样声明来解决这个timestamp问题main.c

volatile unsigned int timestamp = 0;

meta.c就像这样:

extern volatile unsigned int timestamp;
于 2012-12-21T10:57:58.483 回答