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

QQ登錄

只需一步,快速開始

搜索
查看: 11040|回復(fù): 4
打印 上一主題 下一主題
收起左側(cè)

keil編譯報(bào)錯(cuò)error C202: undefined identifier

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:471297 發(fā)表于 2021-1-7 12:07 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
網(wǎng)上找來的代碼,我不懂修改,望大佬幫幫我吧
#include <AT89X51.h>
static unsigned int count; //計(jì)數(shù)
static int step_index; //步進(jìn)索引數(shù),值為0-7
static bit turn; //步進(jìn)電機(jī)轉(zhuǎn)動(dòng)方向
static bit stop_flag; //步進(jìn)電機(jī)停止標(biāo)志
static int speedleve1; //步進(jìn)電機(jī)轉(zhuǎn)速參數(shù),數(shù)值越大速度越慢,最小值為1,速度最快
static int spcount;    //步進(jìn)電機(jī)轉(zhuǎn)速參數(shù)計(jì)數(shù)
void delay(unsigned int endcount); //延時(shí)函數(shù),延時(shí)為 endcount*0.5毫秒
void gorun();          //步進(jìn)電機(jī)控制步進(jìn)函數(shù)
void main(void)
{
    count = 0;
    step_index = 0;
    spcount = 0;
    stop_flag = 0;
    P1_0 = 0;
    P1_1 = 0;
    P1_2 = 0;
    P1_3 = 0;
    EA = 1;             //允許CPU中斷  
    TMOD = 0x11; //設(shè)定時(shí)器0和1為16位模式1  
    ET0 = 1;           //定時(shí)器0中斷允許  
    TH0 = 0xFE;
    TL0 = 0x0C;   //設(shè)定時(shí)每隔0.5ms中斷一次
    TR0 = 1;         //開始計(jì)數(shù)
    turn = 0;
    speedlevel = 2;
    delay(10000);
    speedlevel = 1;
    do{
        speedlevel = 2;
        delay(10000);
        speedlevel = 1;
        delay(10000);
        stop_flag=1;
        delay(10000);
        stop_flag=0;
    }while(1);
}

//定時(shí)器0中斷處理  

void timeint(void) interrupt 1
{  
    TH0=0xFE;
    TL0=0x0C; //設(shè)定時(shí)每隔0.5ms中斷一次
    count++;
    spcount--;
    if(spcount<=0)
    {
       spcount = speedlevel;
       gorun();
    }
}
void delay(unsigned int endcount)
{
    count=0;
    do{}while(count<endcount);

}

void gorun()

{    if (stop_flag==1)
    {
       P1_0 = 0;
       P1_1 = 0;
       P1_2 = 0;
       P1_3 = 0;
       return;
}
switch(step_index)
{
case 0: //0
    P1_0 = 1;
    P1_1 = 0;
    P1_2 = 0;
    P1_3 = 0;
    break;
case 1: //0、1
    P1_0 = 1;
    P1_1 = 1;
    P1_2 = 0;
    P1_3 = 0;
    break;
case 2: //1
    P1_0 = 0;
    P1_1 = 1;
    P1_2 = 0;
    P1_3 = 0;
    break;
case 3: //1、2
    P1_0 = 0;
    P1_1 = 1;
    P1_2 = 1;
    P1_3 = 0;
    break;
case 4:  //2
    P1_0 = 0;
    P1_1 = 0;
    P1_2 = 1;
    P1_3 = 0;
    break;
case 5: //2、3
    P1_0 = 0;
    P1_1 = 0;
    P1_2 = 1;
    P1_3 = 1;
    break;
case 6: //3
    P1_0 = 0;
    P1_1 = 0;
    P1_2 = 0;
    P1_3 = 1;
    break;
case 7: //3、0
    P1_0 = 1;
    P1_1 = 0;
    P1_2 = 0;
    P1_3 = 1;
}
if (turn==0)
{
   step_index++;
   if (step_index>7)
     step_index=0;
}
else
{
   step_index--;
   if (step_index<0)
     step_index=7;
}
  }


報(bào)錯(cuò)提示
89C52.C(27): error C202: 'speedlevel': undefined identifier



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:105364 發(fā)表于 2021-1-7 15:44 | 只看該作者
static int speedleve1;是li,不是1吧
回復(fù)

使用道具 舉報(bào)

板凳
ID:752974 發(fā)表于 2021-1-7 15:47 | 只看該作者
變量的最后一個(gè)字符寫錯(cuò)了。
回復(fù)

使用道具 舉報(bào)

地板
ID:471297 發(fā)表于 2021-1-7 18:11 | 只看該作者
嗯,寫錯(cuò)了。謝謝
回復(fù)

使用道具 舉報(bào)

5#
ID:772513 發(fā)表于 2021-1-18 18:04 | 只看該作者
'speedlevel'沒有被定義吧,speedleve1寫錯(cuò)了,仔細(xì)對(duì)照一下
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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