MikroC 上的错误

Errors on 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" 并且使用 不能以这种方式连接字符串。 你可以这样做,例如

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