幫忙看一下哪里錯了,單片機用的是stc89c52,下面是錯誤代碼:
compiling mian.c...
MIAN.C(45): error C202: 'P0M0': undefined identifier
MIAN.C(46): error C202: 'P0M1': undefined identifier
MIAN.C(48): error C202: 'P1M0': undefined identifier
MIAN.C(49): error C202: 'P1M1': undefined identifier
MIAN.C(51): error C202: 'P2M0': undefined identifier
MIAN.C(52): error C202: 'P2M1': undefined identifier
MIAN.C(54): error C202: 'P3M0': undefined identifier
MIAN.C(55): error C202: 'P3M1': undefined identifier
MIAN.C(57): error C202: 'P4M0': undefined identifier
MIAN.C(58): error C202: 'P4M1': undefined identifier
MIAN.C(63): error C202: 'S2CON': undefined identifier
MIAN.C(64): error C202: 'AUXR': undefined identifier
MIAN.C(66): error C202: 'T2L': undefined identifier
MIAN.C(67): error C202: 'T2H': undefined identifier
MIAN.C(69): error C202: 'AUXR': undefined identifier
MIAN.C(75): error C202: 'S2BUF': undefined identifier
MIAN.C(76): error C202: 'S2CON': undefined identifier
MIAN.C(77): error C202: 'S2CON': undefined identifier
MIAN.C(83): error C202: 'IE2': undefined identifier
MIAN.C(88): error C202: 'IE2': undefined identifier
MIAN.C(95): error C202: 'IE2': undefined identifier
MIAN.C(96): error C202: 'S2CON': undefined identifier
MIAN.C(98): error C202: 'S2CON': undefined identifier
MIAN.C(99): error C202: 'S2BUF': undefined identifier
MIAN.C(103): error C202: 'S2CON': undefined identifier
MIAN.C(105): error C202: 'S2CON': undefined identifier
MIAN.C(107): error C202: 'IE2': undefined identifier
mian.c - 27 Error(s), 0 Warning(s).
源程序:
/**********類型定義**************/
#include "reg52.h"
#include <String.h>
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
#define code const
#define tbuf 50
/***********IO定義***************/
sbit LED=P2^4;
u8 xdata RX_buffer[tbuf];
u8 RX_num;
u8 code esp_at[]="AT\r\n";
u8 code esp_cwmode[]="AT+CWMODE=1\r\n";
u8 code esp_cwjap[]="AT+CWJAP=\"NXP\",\"123456789\"\r\n";
u8 code esp_cifsr[]="AT+CIFSR\r\n";
u8 code esp_cipsta[]="AT+CIPSTART=\"TCP\",\"192.168.0.149\",6000\r\n";
u8 code esp_cipsend[]="AT+CIPSEND=5\r\n";
u8 code esp_DuoLianjie []="AT+CIPMUX=1\r\n";
u8 code esp_Port []="AT+CIPSERVER=1,3122\r\n";
u8 code esp_IP []="AT+CIFSR\r\n";
u8 code esp_Woshou []=":test";
u8 code esp_test_LED []=":LED";
u8 code esp_LED_ON []=":LED ON";
u8 code esp_LED_OFF []=":LED OFF";
u8 code esp_Rst []="AT+RST\r\n";
u8 code esp_DATA []="AT+CIPSEND=1024\r\n";
u8 Data_compare(u8 *p)
{
if(strstr(RX_buffer,p)!=NULL)
return 1;
else
return 0;
}
void IO_init(void)
{
P0M0 = 0X00;
P0M1 = 0X00;
P1M0 = 0X00;
P1M1 = 0X00;
P2M0 = 0X00;
P2M1 = 0X00;
P3M0 = 0X00;
P3M1 = 0X00;
P4M0 = 0X00;
P4M1 = 0X00;
}
void UartInit(void)
{
S2CON = 0x50; //8位數據,可變波特率
AUXR |= 0x04; //定時器2時鐘1為FOSC,即1T
T2L=(65536-(11059200/4/115200)); //設置定時初值
T2H=(65536-(11059200/4/115200))>>8; //設置定時初值
AUXR |= 0x10; //啟動定時器2
}
void Uart2SendByte(u8 ch)
{
S2BUF = ch; //寫數據到UART2數據寄存器
while(!(S2CON&S2TI));
S2CON&=~S2TI;
}
void Uart2SendStr(u8 *s)
{
IE2 = 0x00;
while (*s) //檢測字符串結束標志
{
Uart2SendByte(*s++); //發送當前字符
}
IE2 = 0x01;
}
//串口2中斷
void Uart2() interrupt 8 using 1
{
IE2 = 0x00; //關閉串口2中斷
if (S2CON & S2RI)
{
S2CON &= ~S2RI;
RX_buffer[RX_num] = S2BUF;
RX_num++;
if(RX_num>tbuf) RX_num = 0;
}
if (S2CON & S2TI)
{
S2CON &= ~S2TI;
}
IE2 = 0x01; //開啟串口2中斷
}
mian()
{
// 1 發送AT 進行握手
while(1)
{
Uart2SendStr(esp_at); //串口2對wifi模塊發送握手指令 即AT
if(Data_compare("OK"))break;
else Uart1SendStr("ERROR1,some problems with ESP8266 \r\n");
delay1ms(600);
}
Uart1SendStr("OK,mcu connection success with ESP8266! \r\n");
memset(RX_buffer, 0, tbuf);//清緩存數據
RX_num=0; //接收計數變量清0
while(1)
{
Uart2SendStr(esp_cwmode); //串口2對wifi模塊工作模式進行設置
if(Data_compare("OK")||Data_compare("no change"))break;
delay1ms(600);
}
memset(RX_buffer, 0, tbuf);//清緩存數據
RX_num=0; //接收計數變量清0
while(1)
{
Uart2SendStr(esp_cwjap); //串口2發送 指點wifi名 密碼 等待模塊連接
if(Data_compare("OK"))break;
delay1ms(3000);
}
memset(RX_buffer, 0, tbuf);//清緩存數據
RX_num=0; //接收計數變量清0
while(1)
{
Uart2SendStr(esp_DuoLianjie); //設置多鏈接
if(Data_compare("OK"))break;
delay1ms(3000);
}
memset(RX_buffer, 0, tbuf);//清緩存數據
RX_num=0; //接收計數變量清0
while(1)
{
Uart2SendStr(esp_Port); //設置端口號
if(Data_compare("OK"))
{
delay1ms(3000);
break;
}
delay1ms(3000);
}
Uart1SendStr("OK,Succeed esp_Port\r\n");
memset(RX_buffer, 0, tbuf);//清緩存數據
RX_num=0; //接收計數變量清0
}
|