mikroC Error Messages - Page 1
Forum section: electronics / beginners

author: TeddyPython
author_rank: Contributor
timestamp: January 31, 2017, 06:10:50 pm
content: hello,I am quiet new to programming so please bear with me, but I have tried to copy a CAN project from "Advanced PIC Microcontroller Projects in C" by Ibrahim. Page 475 onwards if you are interested.I see that the author has used mikroc for its convenient CAN functions, which he mentions on page 499. I intend to use the PIC18F258, with the MCP2551 CAN transceiver, however I cannot get the code on page 511 (the collector node) to compile. mikroc tells me that on line 31 " Invalid declarator expected'(' or identifier" and on line 37 " '}' expected ';' found". I am not entirely sure what these mean, and I have tried googling for an answer, but I would think that the book's example should be at least working. :/Could somebody explain what these errors mean, and how I should think about fixing them please?My code is as follows:Code:void main(){unsigned char temperature, data; // LINE 31unsigned short init_flag, send_flag, dt, len, read_flag;char SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, txt;unsigned int temp;unsigned long mV;long id, mask;TRISA = 0xFF; // PORTA are inputs LINE 37TRISB = 0x08; // RB2 is output, RB3 is input//// Configure A/D converter//ADCON1 = 0x80;//// CAN BUS Timing Parameters//SJW = 1;BRP = 1;Phase_Seg1 = 6;Phase_Seg2 = 7;BRP = 1;Prop_Seg = 6;init_flag = CAN_CONFIG_SAMPLE_THRICE &CAN_CONFIG_PHSEG2_PRG_ON &CAN_CONFIG_STD_MSG &CAN_CONFIG_DBL_BUFFER_ON &CAN_CONFIG_VALID_XTD_MSG &CAN_CONFIG_LINE_FILTER_OFF;send_flag = CAN_TX_PRIORITY_0 &CAN_TX_XTD_FRAME &CAN_TX_NO_RTR_FRAME;read_flag = 0;//// Initialise CAN module//CANInitialize(SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, init_flag);//// Set CAN CONFIG mode//CANSetOperationMode(CAN_MODE_CONFIG, 0xFF);mask = -1;//// Set all MASK1 bits to 1's//CANSetMask(CAN_MASK_B1, mask, CAN_CONFIG_XTD_MSG);//// Set all MASK2 bits to 1's//CANSetMask(CAN_MASK_B2, mask, CAN_CONFIG_XTD_MSG);//// Set id of filter B1_F1 to 3//CANSetFilter(CAN_FILTER_B2_F3,500,CAN_CONFIG_XTD_MSG);//// Set CAN module to NORMAL mode//CANSetOperationMode(CAN_MODE_NORMAL, 0xFF);//// Program loop. Read the temperature from analog temperature// sensor//for(;;) // Endless loop{//// Wait until a request is received//dt = 0;while(!dt) dt = CANRead(&id, data, &len, &read_flag);if(id == 500 && data == 'T'){//// Now read the temperature//temp = Adc_Read(0); // Read tempmV = (unsigned long)temp * 5000 / 1024; // in mVtemperature = mV/10; // in degrees C//// send the temperature to Node:Display//data = temperature;id = 3; // IdentifierCANWrite(id, data, 1, send_flag); // send temperature}}}Note, I have removed a large comment from the code in the book, but I have commented the two lines in question.thank you all.

author: snarkysparky
author_rank: Frequent Contributor
timestamp: January 31, 2017, 07:02:44 pm
content: look for a missing item above this code. like a ; or ( or ) .

author: TeddyPython
author_rank: Contributor
timestamp: January 31, 2017, 07:13:42 pm
content: thank you for your reply.I managed to gather that much from the error messages. :[However, I cannot see where or why these things are needed. This is the entire program, and the two lines in question seem to me to be fine. void main() doesnt need any other brackets, and the lines before 37 are simple enough, just needing a ; at the end, right?

author: TeddyPython
author_rank: Contributor
timestamp: January 31, 2017, 07:24:17 pm
content: Wow, thank you so much for your time Peter. Especially to verify its compilation, I am truly grateful.A bit annoying how the book was so wrong though! O.oI will try to program the PIC itself tomorrow.