标题: 不明白的单片机程序的小问题?为什么写P0=com;就没有错误,而写DataPort=com;就报错? [打印本页]

作者: SXP210624    时间: 2020-6-3 11:14
标题: 不明白的单片机程序的小问题?为什么写P0=com;就没有错误,而写DataPort=com;就报错?
#include "reg52.h"
#define DataPort P0;
#define com 0x30;

void main(void)
{
        DataPort = com;  //Keil编译不通过
        P0 = com;        //Keil编译通过
        while(1);
}
为什么写P0=com;就没有错误,而写DataPort=com;就报错?

作者: gujp312365    时间: 2020-6-3 11:56
宏定义不能加分号,你加了就相当于P0;=COM;当然要报错
作者: gujp312365    时间: 2020-6-3 11:57
宏定义不能加分号,初学者常犯的错误,加了就相当于DataPort = com;   // P0; = com; 当然报错




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1