这就是我想要弄清楚的,我有一个 MC9S08AW60。它有两个计时器,我正在尝试配置或仅检查计时器的滴答声,即,我只想检查溢出标志何时更改。代码的基本设计是:
PTFDD = 0xFF;
int j,ch_nbr;
// LED mask values:
#define mLED0 0x01
#define mLED1 0x02
#define mLED2 0x04
#define mLED3 0x08
#define mLED4 0x10
#define mLED5 0x20
#define mLED6 0x40
#define mLED7 0x80
void main()
{
While(j>0){
ch_nbr++;
if (ch_nbr == 8) ch_nbr = 0;
if (ch_nbr == 0) PTFD = mLED0; // Turn LED0 on, other LEDs off
if (ch_nbr == 1) PTFD = mLED1; // Turn LED1 on, other LEDs off
if (ch_nbr == 2) PTFD = mLED2; // Turn LED2 on, other LEDs off
if (ch_nbr == 3) PTFD = mLED3; // Turn LED3 on, other LEDs off
if (ch_nbr == 4) PTFD = mLED4; // Turn LED4 on, other LEDs off
if (ch_nbr == 5) PTFD = mLED5; // Turn LED5 on, other LEDs off
if (ch_nbr == 6) PTFD = mLED6; // Turn LED6 on, other LEDs off
if (ch_nbr == 7) PTFD = mLED7; // Turn LED7 on, other LEDs off
Mydelay();
}
}
void Mydelay(int *j)
{
if (TPM1SC_TOF == 0) j=0;
else j=1;
return j;
}
这个想法是检查值“j”是否同时决定 LED 是否应该亮起!这段代码不起作用。自从我使用 C 编程以来已经有一段时间了。我有点动摇,需要一些帮助。一个适当的解释会很好。请考虑 MCU 数据表的以下链接:http: //cache.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08AW60.pdf
是否可以替换以下函数而不是现有的 Mydelay:
int Mydelay(int& j)
{
if(TPM1SC_TOF == 0) j=0;
else j=1;
return j;
}
void main()
{
PTFDD = 0xFF;
int j,ch_nbr;
// LED mask values:
#define mLED0 0x01
#define mLED1 0x02
#define mLED2 0x04
#define mLED3 0x08
#define mLED4 0x10
#define mLED5 0x20
#define mLED6 0x40
#define mLED7 0x80
While(j==1)
{
ch_nbr++;
if (ch_nbr == 8) ch_nbr = 0;
if (ch_nbr == 0) PTFD = mLED0; // Turn LED0 on, other LEDs off
if (ch_nbr == 1) PTFD = mLED1; // Turn LED1 on, other LEDs off
if (ch_nbr == 2) PTFD = mLED2; // Turn LED2 on, other LEDs off
if (ch_nbr == 3) PTFD = mLED3; // Turn LED3 on, other LEDs off
if (ch_nbr == 4) PTFD = mLED4; // Turn LED4 on, other LEDs off
if (ch_nbr == 5) PTFD = mLED5; // Turn LED5 on, other LEDs off
if (ch_nbr == 6) PTFD = mLED6; // Turn LED6 on, other LEDs off
if (ch_nbr == 7) PTFD = mLED7; // Turn LED7 on, other LEDs off
}
Mydelay();
}