如果把Key_State_Value定义成INT16U,在仿真时串口输出的是0,1,2,3,4. 这个是我想要的,只是不明白为什么定义成INT8U型就不行呢
完整的程序如下:
#include
#include
#define INT8U unsigned char
#define INT16U unsigned int
sbit Key1 = P1^0;
sbit Key2 = P1^1;
sbit Key3 = P1^2;
sbit Key4 = P1^3;
sbit Key5 = P1^4;
INT8U Key_State_Value;
int main(void)
{
SCON = 0x52;
TMOD = 0x20;
TCON = 0x59;
TH1 = 0x0f3;
while(1)
{
if(Key1 == 0)
Key_State_Value = 0;
if(Key2 == 0)
Key_State_Value = 1;
if(Key3 == 0)
Key_State_Value = 2;
if(Key4 == 0)
Key_State_Value = 3;
if(Key5 == 0)
Key_State_Value = 4;
printf("%d\n",Key_State_Value);
}
return 0;
}