【发布时间】:2011-12-22 04:06:57
【问题描述】:
我正在编写一个非常简单的应用程序,它允许人们改变温度。温度显示采用 LEDS(BCD 格式)
我在Keil C51中写了如下代码:
#include< REG51.h>
sbit select = P1^7;
sbit up = P1^0;
sbit down = P1^1;
int data room = 24;
void main()
{ int prog;
P2 &=0x00;
P1 |=0x83;
prog = 0;
while (1)
{
if(select == 1)
prog++;
if(prog == 1)
{
if(up == 1)
room++;
if(down == 1)
room--;
P2 = room;
}
}
}
然后我遵从了这个并获得了 Intel hex 文件,然后我尝试使用 Edsim 进行模拟。
根据 C 代码,当 prog=1 以及按下 up(p1.0) 或 down(p1.1) 时 temp 应该会发生变化,但在模拟中它只会在两者都 select(p1.7) 时发生变化并按下上/下!
为什么会这样?
【问题讨论】: