Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I'm having trouble implementing a MikroC code for PIC18F458 that i found online

Status
Not open for further replies.

Kirthi Kulkarni

Newbie level 2
Newbie level 2
Joined
Apr 7, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
15
Implementation of temperature sensor using CAN protocol :
These are the errors i got, it's written along the lines where i got the error.
Some errors I've listed out in the end.
I tried alot couldn't fix them, I'm new to PIC!!

Code:
void main()
{
//LCD_Init();
unsigned char temperature;
unsigned char data[8]; //ERROR: INVALID DECLARATOR EXPECTED '(' OR IDENTIFIER
unsigned short init_flag;
unsigned short send_flag, dt, len, read_flag;
char SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg;
char txt[4];
long id, mask;
TRISC = 0x00; // PORTC are outputs (LCD) // '}' EXPECTED ';' FOUND 
TRISB = 0x08; // RB2 is output, RB3 is input
//
// CAN BUS Parameters
//
SJW = 1;
BRP = 1;
Phase_Seg1 = 6;
Phase_Seg2 = 7;
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;
//
// Initialize 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 B2_F3 to 3
//
CANSetFilter(CAN_FILTER_B2_F3,3,CAN_CONFIG_XTD_MSG );
//
// Set CAN module to NORMAL mode
//
CANSetOperationMode(CAN_MODE_NORMAL, 0xFF);
//
// Configure LCD
//
Lcd_Config(&PORTC,4,5,0,3,2,1,0); // LCD is connected to PORTC
Lcd_Cmd(LCD_CLEAR); // Clear LCD
Lcd_Out(1,1,"CAN BUS"); // Display heading on LCD
Delay_ms(1000); // Wait for 2 seconds
//
// Program loop. Read the temperature from Node:COLLECTOR and display
// on the LCD continuously
//
for(;;) // Endless loop
{
Lcd_Cmd(LCD_CLEAR); // Clear LCD
Lcd_Out(1,1,"Temp = "); // Display "Temp = "
//
// Send a message to Node:COLLECTOR and ask for data
//
data[0] = 'T'; // Data to be sent
id = 500; // Identifier
CANWrite(id, data, 1, send_flag); // send 'T'
//
// Get temperature from node:COLLECT
//
dt = 0;
while(!dt)dt = CANRead(&id, data, &len, &read_flag);
if(id == 3)
{
temperature = data[0];
ByteToStr(temperature,txt); // Convert to string
Lcd_Out(1,8,txt); // Output to LCD
Delay_ms(1000); // Wait 1 second
}
}
}


IT SHOWS THESE ERRORS AT THE SECOND LAST '}' BRACKET :
SPECIFIER NEEDED
INVALID DECALRATOR EXPECTED '(' OR IDENTIFIER
; EXPECTED BUT '}' FOUND
"INTERNAL ERROR"
 

Implementation of temperature sensor using CAN protocol :
These are the errors i got, it's written along the lines where i got the error.
Some errors I've listed out in the end.
I tried alot couldn't fix them, I'm new to PIC!!

Code:
void main()
{
//LCD_Init();
unsigned char temperature;
unsigned char data[8]; //ERROR: INVALID DECLARATOR EXPECTED '(' OR IDENTIFIER
unsigned short init_flag;
unsigned short send_flag, dt, len, read_flag;
char SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg;
char txt[4];
long id, mask;
TRISC = 0x00; // PORTC are outputs (LCD) // '}' EXPECTED ';' FOUND 
TRISB = 0x08; // RB2 is output, RB3 is input
//
// CAN BUS Parameters
//

"INTERNAL ERROR"[/QUOTE]

'data' is a keyword in MicroC, you can't use it as a variable name. Change data to mydata or a different name wherever this var is used on the code.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top