c - MikroC 上的错误



我正在使用mikroC对pic16f1823进行编程,但遇到了一些非常奇怪的错误。

当我声明一个

整数时会出现一个错误,当我尝试声明一个 char* 数组时,我得到一个错误,上面写着Too many chars .最奇怪的错误之一是"}"预期"}"。

我的代码在下面,如果您发现任何会导致此类错误的错误,请通知我。

#include <stdio.h>
char *filter;
char *filters[25] = {'1','6','11','2','7','12','3','8','13','4','9','14','5','10','15'};//error: TOO many chars
int PositionOfFilters[] = {1,6,11,2,7,12,3,8,13,4,9,14,5,10,15};
int EEPROM_READ(void);
void main() {
     TRISA = 0;//all port A are set as outputs
     TRISC = 0;//all port C are set as outputs
     while(1){
              int prevState = RA2;//store the previous state of RA2 to see if the button was every pressed or not
              int i;
              unsigned int *address[15];
              i2c_Start();
              for(i = 0; i < 16; i++){
                    address[i] = i2c_read(0);//should return what pin is set high;
              }
              i2c_Stop();
           if(RA2 != prevState){ //if the state of RA2 is different than the previous state that means the button was pressed
                  LCD_Cmd(_LCD_CLEAR);
                  int position;//error invalid experison
                  int on;
                  Lcd_Out(2,14,'LOC'); //prints out the we are on local mode
                  for(i = 0; i<16;i++){
                        if(address[i]!=0x00){ //checking to see which pin is high as well as where it's corresponding position is
                            on = address[i]; //should work because only one number shouldn't be 0x00
                            position = i; //gets the corresponding position
                            break;
                        }
                  }
                  if(on == 0x06){
                        Lcd_Out(1,3,'filter 15');//must be filter 15 because there is no other filter that has 0x06;
                  }
                  else{
                       int j;
                       for(j = 0; j < 15; j++){
                             if(PositionOfFilters[j] == position){
                                   //we know what filter we are at
                                   filter = filters[j];
                                   break;
                             }
                     } '}' expected '}' found MyProject.c
                       char *finalFilter = 'filter ' + filter;
                       Lcd_Out(1,3,finalFilter);//Prints out which filter is on
                  }
                  //for the eeprom
                  EEPROM_READ();
           }
           else{
                Lcd_Out(2,14,'REM'); //will print out REM for remote mode
           }
     }
}
int EEPROM_READ(void){
      //figure out how long the eeprom data is
      //start storing the data in a array and then return that array
      //do this by using i2c_start() then eeprom_read(address) then i2c_restart
}

过滤器声明是错误的。您声明了一个 char 指针数组并使用 char 文本对其进行初始化。

你需要指向一个字符的字符串的指针

char *filters[25] = { "1", "6", "11", "2", "7", "12", "3", "8", "13", "4", "9", "14", "5", "10", "15" }; 

这取决于filters的用途。


第二个问题是

Lcd_Out(1, 3, 'filter 15');

当然,此代码必须 EB

Lcd_Out(1, 3, "filter 15");

C 字符串文本必须由"而不是'四舍五入


第三个问题

char *finalFilter = 'filter ' + filter;

这是错误的。如前所述,字符串必须"filter",使用 c 不能以这种方式连接字符串。你可以做,例如

char finalFilter[32];
sprintf(finalFilter, "%s%s", "filter", filter);

相关内容

  • 没有找到相关文章

最新更新