新手请教,51判断不了负数
新手想实验一个数的正负判断,但负数判断总是不对,代码如下#include "reg52.h"
sbit LED1=P2^0; //将P2.0管脚定义为LED1
sbit LED2=P2^1;
sbit LED3=P2^2;
typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;
char CSC=3-5;
void main()
{
if (CSC>0)
{
LED1=0; //LED1端口设置为低电平
}
else if (CSC==0)
{
LED2=0; //LED2端口设置为低电平
}
else
{
LED3=0; //LED3端口设置为低电平
}
}
CSC为正或零时,对应LED正常,但是CSC为负数时,LED3无法点亮,感觉IF循环都没进去,大佬看看哪出的问题。
大佬们,谁看见啦? 我这个就没有问题了
#include "reg52.h"
sbit LED1=P2^0; //将P2.0管脚定义为LED1
sbit LED2=P2^1;
sbit LED3=P2^2;
typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;
char CSC=3-5;
void main()
{
if (CSC>0)
{
LED1=0; //LED1端口设置为低电平
}
else if (CSC==0)
{
LED2=0; //LED2端口设置为低电平
}
else
{
LED3=0; //LED3端口设置为低电平
}
while(1);//我加的
}
本帖最后由 zwbrabbit 于 2024-2-21 15:42 编辑
加了while(1)确实可以了。但是为什么。。。。
页:
[1]