请问这个程序为什么在mplab里运行不了

请问各位为什么一直报错,需要软件设置哪里或者程序改哪里吗,下面第三张图是要求

#include <pic.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define _XTAL_FREQ 8000000 
int i, j, k, n;                 
const char TopMessage[]  = "Brillancy ";
const char TopMessage1[]  = "Dusky";
const char TopMessage2[]  = "Dim ";
char BotMessage[10];   
#define E  RC4
#define RS RC5
#define Buzzer RA2
#define HIGH 1
#define LOW 0
#define        DN                        RA5        //Motor rise                 2        DN
#define        UP                        RA0        //Motor decline                13  UP
#define        MOTA                RC5        //Motor Forward                5
#define        MOTB                RC4        //Motor Reversal        6
__CONFIG(0x3004);//(0X30C4);
#define T0_40MS 100    // 定义 TMR0 延时10MS 的时间常数
#define T1_100MS 40536
const int Twentyms = 1250;      
const int Fivems = 300;             
const int TwoHundredus = 10;     
int ADCState = 0;              
int ADCValue = 0;
int Dlay = 63;
int a;
int result;               
LCDWrite(int LCDData, int RSValue)
{
    PORTC = (LCDData >> 4) & 0x0F;
    RS = RSValue;
    E = 1;  E = 0;                 
    PORTC = LCDData & 0x0F;
    RS = RSValue;
    E = 1;  E = 0;                  

    if ((0 == (LCDData & 0xFC)) && (0 == RSValue))
        n = Fivems;               
    else
        n = TwoHundredus;

    for (k = 0; k < n; k++);       

}   

bit rise;        //Reverse flag bit
bit tmrl;        //Reverse flag bit
bit tmrh;        //Reverse flag bit

unsigned int num;  //Total pulse number
unsigned int cnnt; //pulse counting
unsigned int timerl; //TMR1Pulse rises along the time
unsigned int timerh; //TMR1Pulse drops along the time
unsigned int cnnt_timer;//TMR1Pulse total time
unsigned int cnnt_tmr2;        //TMR2Pulse total time

unsigned int signal_key();
unsigned int getkey() ;
void Delay_MS(unsigned int t);
void initial()
{
        TRISA=0x3D;//3D;RA2=1,
        TRISC=0X0E;
        OPTION=0x87;//RA2Internal interrupt time source
       
        INTCON=0xF0;//Peripheral interruptions allow
        CMCON0 = 0X07;
        ANSEL = 0;

//       TMR0=T0_40MS; / / Start the TMR0, which comes with an oscillator, with a frequency division ratio of 1:256

        T1CON=0X22;//2Start the TMR1 with the oscillator, divide the frequency ratio of 1:4, close TRM1ON=0;
        TMR1H=T1_100MS>>8;//0X80;         //Set the initial value
        TMR1L==T1_100MS;//0X00;
        TMR1IE=1;         //TMR1中interrupt enable;interrupt enabling 断允许

        T2CON=0x63;  //The TMR2 prefrequency division coefficient is 1:16, and the rear frequency division coefficient is 1:13, and the start of the work is turned off by TRM2ON=0;
        PR2=239;   //Overflow value of TMR2, overflow when TMR2 is for this value + 1
        TMR2IE=1;         //The TMR1 interruption allowed for 50MS


        cnnt=0;
        cnnt_timer=0;
        num=10;
}
void Delay_MS(unsigned int t)
{
        unsigned int a,b;
        for(a=t;a>0;a--)
        for(b=110;b>0;b--);
}
void Forward()
{
        rise=1;
    MOTB=1;       
        MOTA=0;
        signal_key();
}
void Reversal()
{
        rise=0;
        MOTB=0;
        MOTA=1;
        signal_key();
}
void Stop()
{
        MOTA=0;
        MOTB=0;
}
unsigned int getkey()
{


        if(!UP)
        {
                while(!UP)
                {
                        if(cnnt==num){Stop();break;}
                        Forward();
                }
        }       
       
        if(!DN)
        {
                while(!DN)
                {               
                        if(cnnt==0){Stop();break;}
                        Reversal();                       
                }
        }
       
        while(DN&&UP)
        {
                tmrh=0;
                tmrl=0;
                break;
        }
       
}
unsigned int signal_key()
{
//The signal drops along the detection of the//
             while(!RA2)              //Reconfirm the signal and exit without the signal is pressed
        {
                        tmrh=0;
                        if(tmrl) break;
                        tmrl=1;


                        RA1=0;
                        INTF=0;       
                        TMR1ON=0;
                        TMR2ON=1;
                        if(TMR2IF==1)//Detect whether the 50MS error signal, stop running                        {
                                TMR2ON=0;
                                TMR2IF=0;
                                PR2=239;         //Set the initial value
                                Stop(); //Stop motor operation
                                return;
                        }
                                       
                }
// Stop motor operation//
                while(RA2)
                {   
                        tmrl=0;                       
                        if(tmrh) break;
                        tmrh=1;


                        TMR2ON=0;
                        INTF=1;
                       
                        if(TMR1IF==1)//Detect whether the 100MS error signal, stop running                        {
                                TMR1ON=0;
                                TMR1IF=0;
                                TMR1H=T1_100MS>>8;//0X80;         //Set the initial value                                TMR1L=T1_100MS;//0X00;
                                Stop(); //Stop motor operation
                                return;
                        }
                        break;
                }
//  Remove the ascending pulse signal time //
                if(TMR1ON==0)
                {
                        timerh=TMR1H;
                        timerl=TMR1L;
                        cnnt_timer = timerh<<8;
                        cnnt_timer += timerl;


                        TMR1IF=0;
                        TMR1H=T1_100MS>>8;//0X80;         //Set the initial value
                        TMR1L=T1_100MS;//0X00;               
                }
//removes the descent along the pulse signal time//
                if(TMR2ON==0)
                {
                        cnnt_tmr2 = TMR2;


                        TMR2IF=0;
                        PR2=239;         //Set the initial value      
                }


}


void interrupt ISR(void)
{
        if(INTF==1)        //The pulse starts to count, and the lifting timing starts on the TMR1        {
                INTF=0;
                RA1=1;
                if(rise) cnnt++;
                else cnnt--;       
                TMR1ON=1;
        }


        if(        TMR1IF==1)
        {
                TMR1IF=0;
                TMR1H=T1_100MS>>8;//0X80;         //Set the initial value
                TMR1L=T1_100MS;//0X00;
        }


        if(        TMR2IF==1)
        {
                TMR2IF=0;       
                PR2=239;         //Set the initial value     
        }


}
void main()
{
        initial();
    while (1)
    {
                getkey();     
        }  
main()
{

    PORTC = 0;
    CMCON0 = 7;                 
    TRISC = 0;
    TRISA = 0xFB;
    ANSEL = 0x00;                

    PORTA = 0;
    TRISAbits.TRISA0 = 1;
        ANSELbits.ANS0 = 1;

    ADCON0bits.ADFM = 1;
    ADCON0bits.VCFG = 0;
    ADCON1bits.ADCS = 0b001;


    ADCON0bits.CHS = 0;
    ADCON0bits.ADON = 1;

while(1)
    {
         __delay_us(3);

        ADCON0bits.GO = 1;
        while(ADCON0bits.GO==1){};

        result = (ADRESH<<8)+ADRESL;




    j = Twentyms;
    for (i = 0; i < j; i++);
    PORTC = 3;
    E = 1;  E = 0;
    j = Fivems;
    for (i = 0; i < j; i++);

    E = 1;  E = 0;
    j = TwoHundredus;
    for (i = 0; i < j; i++);

    E = 1;  E = 0;
    j = TwoHundredus;
    for (i = 0; i < j; i++);

    PORTC = 2;
    E = 1;  E = 0;
    j = TwoHundredus;
    for (i = 0; i < j; i++);

  

    LCDWrite(0b00101000, 0);

    LCDWrite(0b00000001, 0);

    LCDWrite(0b00000110, 0);

    LCDWrite(0b00001110, 0);

   if(result>200)
   {
      for (i=0;TopMessage[i] != 0;i++)
                LCDWrite(TopMessage[i], 1);
   }
   else if (result>100 && result <=200)
   {
      for (i = 0; TopMessage1[i] != 0; i++)
                LCDWrite(TopMessage1[i], 1);
   }
   else
   {
       for (i = 0; TopMessage2[i] != 0; i++)
                LCDWrite(TopMessage2[i], 1);
   }
    memset(BotMessage,0,sizeof(BotMessage));
    sprintf(BotMessage,"%d",result);


                LCDWrite(0b00000001, 1);

                LCDWrite(0b11000000, 0);    
                for (i = 0; BotMessage[i] != 0; i++)
                LCDWrite(BotMessage[i], 1);
   if (result>100)
  {
       for(a=0;a<5000;a++)
           Buzzer=LOW;
       for(a=0;a<5000;a++)
           Buzzer=HIGH;

  }
     
}

img

img

直接贴代码吧,截图不方便

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/1084112
  • 你也可以参考下这篇文章:C语言——MPLAB中if语句不执行问题
  • 以下回答来自chatgpt:

    我很抱歉,由于您并没有提供具体的报错信息和程序代码,我无法给出解决方案。建议您先查看报错信息,确定错误类型和具体位置,然后检查程序代码是否存在语法错误或者逻辑问题。如果您需要更详细的帮助,请提供更多信息,以便我能够准确地为您提供解决方案。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^