#include <reg51.h>
#define LED P1^1
#define KEY_ON P1^6
#define KEY_OFF P1^7
void main(void)
{
KEY_ON = 1; //开关亮输出高电平,接通就变为低电平
KEY_OFF = 1; //开关灭输出高电平,接通就变为低电平
while(1)
{
if(KEY_ON==0) LED = 1;
if(KEY_OFF==0) LED = 0;
}
}
//就是这一小段程序 编译提示:
compiling LED_ONOFF.c…
LED_ONOFF.C(9): error C141: syntax error near ‘=’
LED_ONOFF.C(10): error C141: syntax error near ‘=’
LED_ONOFF.C(13): error C141: syntax error near ‘=’
LED_ONOFF.C(14): error C141: syntax error near ‘=’
Target not created
#define是宏定义语句
想做的是位操作,应该改将#define LED P1^1
#define KEY_ON P1^6
#define KEY_OFF P1^7
改为
sbit LED = P1^1;
sbit KEY_ON = P1^6;
sbit KEY_OFF = P1^7;
这样文中的“=”就不违法了