找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3651|回復(fù): 2
收起左側(cè)

幫忙看一下這個(gè)keil單片機(jī)程序編譯錯(cuò)誤,求幫助

[復(fù)制鏈接]
ID:202598 發(fā)表于 2018-8-7 11:32 | 顯示全部樓層 |閱讀模式
幫忙看一下哪里錯(cuò)了,單片機(jī)用的是stc89c52,下面是錯(cuò)誤代碼:
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位數(shù)據(jù),可變波特率
    AUXR |= 0x04;       //定時(shí)器2時(shí)鐘1為FOSC,即1T

    T2L=(65536-(11059200/4/115200));    //設(shè)置定時(shí)初值
    T2H=(65536-(11059200/4/115200))>>8; //設(shè)置定時(shí)初值

    AUXR |= 0x10;       //啟動(dòng)定時(shí)器2      
}


void Uart2SendByte(u8 ch)
{
    S2BUF = ch;                 //寫數(shù)據(jù)到UART2數(shù)據(jù)寄存器
    while(!(S2CON&S2TI));   
    S2CON&=~S2TI;
}


void Uart2SendStr(u8 *s)
{
IE2 = 0x00;
    while (*s)                  //檢測(cè)字符串結(jié)束標(biāo)志
    {
       Uart2SendByte(*s++);     //發(fā)送當(dāng)前字符
    }
IE2 = 0x01;
}

//串口2中斷
void Uart2() interrupt 8 using 1
{

        IE2 = 0x00;       //關(guān)閉串口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 發(fā)送AT 進(jìn)行握手
    while(1)
    {
     Uart2SendStr(esp_at);     //串口2對(duì)wifi模塊發(fā)送握手指令 即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);//清緩存數(shù)據(jù)
     RX_num=0;                 //接收計(jì)數(shù)變量清0

    while(1)
    {
     Uart2SendStr(esp_cwmode);     //串口2對(duì)wifi模塊工作模式進(jìn)行設(shè)置  
     if(Data_compare("OK")||Data_compare("no change"))break;
     delay1ms(600);
    }
     memset(RX_buffer, 0, tbuf);//清緩存數(shù)據(jù)
     RX_num=0;                 //接收計(jì)數(shù)變量清0




    while(1)
    {
     Uart2SendStr(esp_cwjap);      //串口2發(fā)送 指點(diǎn)wifi名 密碼 等待模塊連接
     if(Data_compare("OK"))break;
     delay1ms(3000);
    }
    memset(RX_buffer, 0, tbuf);//清緩存數(shù)據(jù)
    RX_num=0;                  //接收計(jì)數(shù)變量清0

    while(1)
    {
         Uart2SendStr(esp_DuoLianjie);              //設(shè)置多鏈接
         if(Data_compare("OK"))break;
         delay1ms(3000);
    }
    memset(RX_buffer, 0, tbuf);//清緩存數(shù)據(jù)
    RX_num=0;                  //接收計(jì)數(shù)變量清0


    while(1)
    {
         Uart2SendStr(esp_Port);                //設(shè)置端口號(hào)
         if(Data_compare("OK"))
         {
            delay1ms(3000);
            break;
         }
         delay1ms(3000);
    }
    Uart1SendStr("OK,Succeed esp_Port\r\n");   
    memset(RX_buffer, 0, tbuf);//清緩存數(shù)據(jù)
    RX_num=0;                  //接收計(jì)數(shù)變量清0
}

回復(fù)

使用道具 舉報(bào)

ID:360020 發(fā)表于 2018-8-7 14:38 | 顯示全部樓層
stc89c52的單片機(jī)根本沒有這些寄存器
附REG52.H
/*--------------------------------------------------------------------------
REG52.H

Header file for generic 80C52 and 80C32 microcontroller.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __REG52_H__
#define __REG52_H__

/*  BYTE Registers  */
sfr P0    = 0x80;
sfr P1    = 0x90;
sfr P2    = 0xA0;
sfr P3    = 0xB0;
sfr PSW   = 0xD0;
sfr ACC   = 0xE0;
sfr B     = 0xF0;
sfr SP    = 0x81;
sfr DPL   = 0x82;
sfr DPH   = 0x83;
sfr PCON  = 0x87;
sfr TCON  = 0x88;
sfr TMOD  = 0x89;
sfr TL0   = 0x8A;
sfr TL1   = 0x8B;
sfr TH0   = 0x8C;
sfr TH1   = 0x8D;
sfr IE    = 0xA8;
sfr IP    = 0xB8;
sfr SCON  = 0x98;
sfr SBUF  = 0x99;

/*  8052 Extensions  */
sfr T2CON  = 0xC8;
sfr RCAP2L = 0xCA;
sfr RCAP2H = 0xCB;
sfr TL2    = 0xCC;
sfr TH2    = 0xCD;


/*  BIT Registers  */
/*  PSW  */
sbit CY    = PSW^7;
sbit AC    = PSW^6;
sbit F0    = PSW^5;
sbit RS1   = PSW^4;
sbit RS0   = PSW^3;
sbit OV    = PSW^2;
sbit P     = PSW^0; //8052 only

/*  TCON  */
sbit TF1   = TCON^7;
sbit TR1   = TCON^6;
sbit TF0   = TCON^5;
sbit TR0   = TCON^4;
sbit IE1   = TCON^3;
sbit IT1   = TCON^2;
sbit IE0   = TCON^1;
sbit IT0   = TCON^0;

/*  IE  */
sbit EA    = IE^7;
sbit ET2   = IE^5; //8052 only
sbit ES    = IE^4;
sbit ET1   = IE^3;
sbit EX1   = IE^2;
sbit ET0   = IE^1;
sbit EX0   = IE^0;

/*  IP  */
sbit PT2   = IP^5;
sbit PS    = IP^4;
sbit PT1   = IP^3;
sbit PX1   = IP^2;
sbit PT0   = IP^1;
sbit PX0   = IP^0;

/*  P3  */
sbit RD    = P3^7;
sbit WR    = P3^6;
sbit T1    = P3^5;
sbit T0    = P3^4;
sbit INT1  = P3^3;
sbit INT0  = P3^2;
sbit TXD   = P3^1;
sbit RXD   = P3^0;

/*  SCON  */
sbit SM0   = SCON^7;
sbit SM1   = SCON^6;
sbit SM2   = SCON^5;
sbit REN   = SCON^4;
sbit TB8   = SCON^3;
sbit RB8   = SCON^2;
sbit TI    = SCON^1;
sbit RI    = SCON^0;

/*  P1  */
sbit T2EX  = P1^1; // 8052 only
sbit T2    = P1^0; // 8052 only
            
/*  T2CON  */
sbit TF2    = T2CON^7;
sbit EXF2   = T2CON^6;
sbit RCLK   = T2CON^5;
sbit TCLK   = T2CON^4;
sbit EXEN2  = T2CON^3;
sbit TR2    = T2CON^2;
sbit C_T2   = T2CON^1;
sbit CP_RL2 = T2CON^0;

#endif

評(píng)分

參與人數(shù) 1黑幣 +5 收起 理由
多德 + 5 回帖助人的獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

ID:1 發(fā)表于 2018-8-7 17:17 | 顯示全部樓層
不要重復(fù)發(fā)帖,此貼先轉(zhuǎn)到無人區(qū)了
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表