I am programming the pic16f1823 using mikroC and I am getting some very strange errors.
When I declare an integer an error appears and when I try to declare a char* array I get an error which says Too many chars
. And one of the weirdest errors are '}' expected '}'.
My code is below if you spot any mistakes that would make such an error please inform me.
#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
}
filters declaration is wrong. You declared a char pointer array and init it with char literals.
You need pointer to string of one char
char *filters[25] = { "1", "6", "11", "2", "7", "12", "3", "8", "13", "4", "9", "14", "5", "10", "15" };
It depends on what filters
is used for.
Second problem is
Lcd_Out(1, 3, 'filter 15');
surely this code must eb
Lcd_Out(1, 3, "filter 15");
C-strings literals must be sorrounded by "
not '
Third problem
char *finalFilter = 'filter ' + filter;
it is wrong. As explained before, string must be "filter"
and using c you cannot concatenate strings in that way.
You can do, for example
char finalFilter[32];
sprintf(finalFilter, "%s%s", "filter", filter);