Joined: 14 Mar 2010 11:05
Posts: 2 Hi.Still I have problem in my program codes.I write a program in mikroC PROV2.50 for my microcontroller(PIC 18F452) but I
faced to a problem that related only to C language and compiler give me the following error
messages;

extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 16 1504 Initialization of extern object 'adcvalmax' t1x.c //)in function;void Display_AdcX(int adcvalmax[8] ) 

extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 43 1504 Initialization of extern object 'adcvalmax' t1x.c//)in function; int MR_CHNS(int adcvalmax[8])

return(adcvalmax);//77 1506 Implicit conversion of pointer to int t1x.c //)infunction; int MR_CHNS(int adcvalmax[8])

LCD_Out(2,14,rp2val);// 96 1508 Implicit conversion of int to ptr t1x.c //)in function; void update_pwm(unsigned short int rp2val)

184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c) 
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c 

For the ease I attached the program and its error messages the following of this

Here are the descriptions of my Functions and Main program;

int CHS_Read(int adcvalmax[8]); Reading input values by analog to digital module of the PIC18F452 and save the results in the array
" adcvalmax[m] ".

void Display_AdcX(int adcvalmax[8] ) ;get the array
" adcvalmax[m] "and by using it display its value on LCD.

In the Main program I call Function; " void Display_AdcX(int adcvalmax[8] ) " as; Display_AdcX( adcvalmax[] ); .

Would you please help me and tell me mistakes in my program?

Thanks,

My code of program and error messages;

int t4=0,index;
char *tc;
int adcvalmax[8]= {0,0,0,0,0,0,0,0};

#define stepsize 98
int interb0=0;


void Display_AdcX(int adcvalmax[8] ) {
int i=0,m=0;
char ch[8]= {0,0,0,0,0,0,0,0};
extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 16 1504 Initialization of extern object 'adcvalmax' t1x.c //

for(i,m=0;i,m<8;i++,m++){ //IS THIS FOR STATEMENT RIGHT? ****************


ch[i] = adcvalmax[m] /1000; //prepare value for display in A
Lcd_Chr(2, 1, 48 + ch[i]); //write ASCII at 2nd row,1st column
Lcd_Chr_Cp('.');

ch[i] = (adcvalmax[m] /100) % 10;
Lcd_Chr_Cp(48 + ch[i]);

ch[i] = (adcvalmax[m] /10) % 10;
Lcd_Chr_Cp(48 + ch[i]);

ch[i] = adcvalmax[m] % 10;
Lcd_Chr_Cp(48 + ch[i]);
Lcd_Chr_Cp('A');

}

}//~


int MR_CHNS(int adcvalmax[8]){

long longadc=0;
extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 43 1504 Initialization of extern object 'adcvalmax' t1x.c//
int ch[8]= {0,0,0,0,0,0,0,0};//declares a array of 8 integers
int m=0,i=0;
int Px=0,P1st=0,P2nd=0;


for(i=0;i<8;i++){

for(m=0;m<8;m++){

do{
ch[i]=ADC_Read(i);
Px=ch[i];
}while(Px!=0);

P1st=ADC_Read(m);
Delay_ms(10);//10 ms pause
P2nd=ADC_Read(m);

while(P1st<=P2nd){
P1st=P2nd;
P2nd=0;
P2nd=ADC_Read(m);
}

adcvalmax[m] = P1st;// if (vf>vn)
index = (stepsize);
ADRESH = (ADRESH)&&(0b00000011);
longadc = ADRESH + ADRESL;
adcvalmax[m] = longadc * index;//in mA or mv

}
}

return(adcvalmax);//77 1506 Implicit conversion of pointer to int t1x.c //

}//~




void update_pwm(unsigned short int rp2val){

rp2val=0;

t4 = Adc_Read(4);
rp2val = ADRESL;


PWM1_Set_Duty(rp2val);//Set & change duty ratio due to the VRP2 value
//from 0 -255;(ADRESL)


LCD_Out(2,14,rp2val);// 96 1508 Implicit conversion of int to ptr t1x.c //

//(127: 50% duty ratio)
if(rp2val == 127) PORTC.F5=1;//Turn the LED on (RC5/pin24)

}//~



void interrupt() {

static int interb0;
//Turn off charger interrupt via INTO/RB0
INTCON.INT0IF=0;//Clear INT0(INTCON)external interrupt Flag bit to detect
//next inter.
interb0++;//interb0 = interb0+1

while(interb0 ==1){

PWM1_Stop();//Stop PWM


LCD_Cmd(_LCD_CLEAR);// send command to LCD (clear LCD)
tc = "STAND BY!";// assign a text to string
LCD_Out(1,1,tc);// print a string on LCD, 1st row, 1st column

PORTC.F3=1;//Turn the LED on (RC3/pin18):LED stand by state indicator
Delay_ms(1000);//One second pause
PORTC.F3=0;//Turn the LED off (RC3/pin18)
}

if(interb0!=1){
PWM1_Start();//Start PWM ,(interb0!=1)
interb0 = 0;
PORTC.F3=0;//Turn the LED off (RC3/pin18)
}

}//~




// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections











void main() {



PORTA=0;//Clear port A
TRISA=0XFF;//Port A is input
PORTD=0;//Clear port D
TRISD=0;//Port D is output
PORTC=0;//Clear port C
TRISC=0;//port C is output
PORTB=0;//Clear port B
TRISB=0XFF;//port B is input
PORTE=0;//Clear port E
TRISE=0XFF;//Port E is input
TRISC = PORTC = 0;

INTCON.GIEH = 1; // When IPEN = 1,enables all high priority interrupts
INTCON.GIEL=1;//When IPEN = 1,enables all low priority peripheral interrupts
RCON.IPEN = 1;//Enable priority levels on interrupts
INTCON.INT0IE=1;//Enables the INT0 external interrupt
INTCON2.INTEDG0 = 0;// Interrupt on falling edge







LCD_Init();// initialize(4-bit interface connection)
LCD_Cmd(_LCD_CURSOR_OFF);// send command to LCD (cursor off)
LCD_Cmd(_LCD_CLEAR);// send command to LCD (clear LCD)
tc = "Hi!";// assign a text to string
LCD_Out(1,1,tc);// print a string on LCD, 1st row, 1st column



PWM1_Init(500);//500HZ but should Initialize PWM module at 50HZ ;
//using frequency divider with D-Flip_Flop IC.
PWM1_Set_Duty(127);//Set duty ratio to 50%



update_pwm(t4);
PWM1_Start();//Start PWM


//Not required to determine ADCON0;it is asked by uC compiler on NEW Project
// icon bar at the top at first automatically &done via:Adc_Read() Library

ADCON1=0x80;//configure VDD=Vref+,Vss=Vref-,8-analog channels&Right justified
//A/D Result Format
Delay_ms(2000);


MR_CHNS(adcvalmax);
Display_AdcX(adcvalmax);



}//~!

()

0 1 mikroCPIC1618.exe -MSF -DBG -pP18F452 -DL -O11111114 -fo8 -N"E:\T1\t1x.mcppi" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\defs\" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\uses\P18\" -SP"E:\T1\" "t1x.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprintf.mcl" "__Lib_PrintOut.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM_256.mcl" "__Lib_FLASH_w8_e64.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_CFFat16.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_Mmc.mcl" "__Lib_MmcFat16.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl" 
0 125 All files Preprocessed in 15 ms 
0 121 Compilation Started t1x.c
16 1504 Initialization of extern object 'adcvalmax' t1x.c
43 1504 Initialization of extern object 'adcvalmax' t1x.c
77 1506 Implicit conversion of pointer to int t1x.c
96 1508 Implicit conversion of int to ptr t1x.c
223 122 Compiled Successfully t1x.c
0 126 All files Compiled in 172 ms 
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c
0 102 Finished (with errors): 08 May 2010, 09:47:28 t1x.mcppi
0 1 mikroCPIC1618.exe -MSF -DBG -pP18F452 -DL -O11111114 -fo8 -N"E:\T1\t1x.mcppi" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\defs\" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\uses\P18\" -SP"E:\T1\" "t1x.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprintf.mcl" "__Lib_PrintOut.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM_256.mcl" "__Lib_FLASH_w8_e64.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_CFFat16.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_Mmc.mcl" "__Lib_MmcFat16.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl" 
0 125 All files Preprocessed in 15 ms 
0 121 Compilation Started t1x.c
16 1504 Initialization of extern object 'adcvalmax' t1x.c
43 1504 Initialization of extern object 'adcvalmax' t1x.c
77 1506 Implicit conversion of pointer to int t1x.c
96 1508 Implicit conversion of int to ptr t1x.c
223 122 Compiled Successfully t1x.c
0 126 All files Compiled in 172 ms 
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c
0 102 Finished (with errors): 08 May 2010, 09:47:28 t1x.mcppi

()

int t4=0,index;
char *tc;
int adcvalmax[8]= {0,0,0,0,0,0,0,0};

#define stepsize 98
int interb0=0;


void Display_AdcX(int adcvalmax[8] ) {
int i=0,m=0;
char ch[8]= {0,0,0,0,0,0,0,0};
extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 16 1504 Initialization of extern object 'adcvalmax' t1x.c //

for(i,m=0;i,m<8;i++,m++){ //IS THIS FOR STATEMENT RIGHT? ****************


ch[i] = adcvalmax[m] /1000; //prepare value for display in A
Lcd_Chr(2, 1, 48 + ch[i]); //write ASCII at 2nd row,1st column
Lcd_Chr_Cp('.');

ch[i] = (adcvalmax[m] /100) % 10;
Lcd_Chr_Cp(48 + ch[i]);

ch[i] = (adcvalmax[m] /10) % 10;
Lcd_Chr_Cp(48 + ch[i]);

ch[i] = adcvalmax[m] % 10;
Lcd_Chr_Cp(48 + ch[i]);
Lcd_Chr_Cp('A');

}

}//~


int MR_CHNS(int adcvalmax[8]){

long longadc=0;
extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 43 1504 Initialization of extern object 'adcvalmax' t1x.c//
int ch[8]= {0,0,0,0,0,0,0,0};//declares a array of 8 integers
int m=0,i=0;
int Px=0,P1st=0,P2nd=0;


for(i=0;i<8;i++){

for(m=0;m<8;m++){

do{
ch[i]=ADC_Read(i);
Px=ch[i];
}while(Px!=0);

P1st=ADC_Read(m);
Delay_ms(10);//10 ms pause
P2nd=ADC_Read(m);

while(P1st<=P2nd){
P1st=P2nd;
P2nd=0;
P2nd=ADC_Read(m);
}

adcvalmax[m] = P1st;// if (vf>vn)
index = (stepsize);
ADRESH = (ADRESH)&&(0b00000011);
longadc = ADRESH + ADRESL;
adcvalmax[m] = longadc * index;//in mA or mv

}
}

return(adcvalmax);//77 1506 Implicit conversion of pointer to int t1x.c //

}//~




void update_pwm(unsigned short int rp2val){

rp2val=0;

t4 = Adc_Read(4);
rp2val = ADRESL;


PWM1_Set_Duty(rp2val);//Set & change duty ratio due to the VRP2 value
//from 0 -255;(ADRESL)


LCD_Out(2,14,rp2val);// 96 1508 Implicit conversion of int to ptr t1x.c //

//(127: 50% duty ratio)
if(rp2val == 127) PORTC.F5=1;//Turn the LED on (RC5/pin24)

}//~



void interrupt() {

static int interb0;
//Turn off charger interrupt via INTO/RB0
INTCON.INT0IF=0;//Clear INT0(INTCON)external interrupt Flag bit to detect
//next inter.
interb0++;//interb0 = interb0+1

while(interb0 ==1){

PWM1_Stop();//Stop PWM


LCD_Cmd(_LCD_CLEAR);// send command to LCD (clear LCD)
tc = "STAND BY!";// assign a text to string
LCD_Out(1,1,tc);// print a string on LCD, 1st row, 1st column

PORTC.F3=1;//Turn the LED on (RC3/pin18):LED stand by state indicator
Delay_ms(1000);//One second pause
PORTC.F3=0;//Turn the LED off (RC3/pin18)
}

if(interb0!=1){
PWM1_Start();//Start PWM ,(interb0!=1)
interb0 = 0;
PORTC.F3=0;//Turn the LED off (RC3/pin18)
}

}//~




// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections











void main() {



PORTA=0;//Clear port A
TRISA=0XFF;//Port A is input
PORTD=0;//Clear port D
TRISD=0;//Port D is output
PORTC=0;//Clear port C
TRISC=0;//port C is output
PORTB=0;//Clear port B
TRISB=0XFF;//port B is input
PORTE=0;//Clear port E
TRISE=0XFF;//Port E is input
TRISC = PORTC = 0;

INTCON.GIEH = 1; // When IPEN = 1,enables all high priority interrupts
INTCON.GIEL=1;//When IPEN = 1,enables all low priority peripheral interrupts
RCON.IPEN = 1;//Enable priority levels on interrupts
INTCON.INT0IE=1;//Enables the INT0 external interrupt
INTCON2.INTEDG0 = 0;// Interrupt on falling edge







LCD_Init();// initialize(4-bit interface connection)
LCD_Cmd(_LCD_CURSOR_OFF);// send command to LCD (cursor off)
LCD_Cmd(_LCD_CLEAR);// send command to LCD (clear LCD)
tc = "Hi!";// assign a text to string
LCD_Out(1,1,tc);// print a string on LCD, 1st row, 1st column



PWM1_Init(500);//500HZ but should Initialize PWM module at 50HZ ;
//using frequency divider with D-Flip_Flop IC.
PWM1_Set_Duty(127);//Set duty ratio to 50%



update_pwm(t4);
PWM1_Start();//Start PWM


//Not required to determine ADCON0;it is asked by uC compiler on NEW Project
// icon bar at the top at first automatically &done via:Adc_Read() Library

ADCON1=0x80;//configure VDD=Vref+,Vss=Vref-,8-analog channels&Right justified
//A/D Result Format
Delay_ms(2000);


MR_CHNS(adcvalmax);
Display_AdcX(adcvalmax);



}//~!

()

0 1 mikroCPIC1618.exe -MSF -DBG -pP18F452 -DL -O11111114 -fo8 -N"E:\T1\t1x.mcppi" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\defs\" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\uses\P18\" -SP"E:\T1\" "t1x.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprintf.mcl" "__Lib_PrintOut.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM_256.mcl" "__Lib_FLASH_w8_e64.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_CFFat16.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_Mmc.mcl" "__Lib_MmcFat16.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl" 
0 125 All files Preprocessed in 15 ms 
0 121 Compilation Started t1x.c
16 1504 Initialization of extern object 'adcvalmax' t1x.c
43 1504 Initialization of extern object 'adcvalmax' t1x.c
77 1506 Implicit conversion of pointer to int t1x.c
96 1508 Implicit conversion of int to ptr t1x.c
223 122 Compiled Successfully t1x.c
0 126 All files Compiled in 172 ms 
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c
0 102 Finished (with errors): 08 May 2010, 09:47:28 t1x.mcppi
0 1 mikroCPIC1618.exe -MSF -DBG -pP18F452 -DL -O11111114 -fo8 -N"E:\T1\t1x.mcppi" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\defs\" -SP"E:\Bob's File\mikroC PRO PIC 2009 V2.50\MikroCProV2.50\uses\P18\" -SP"E:\T1\" "t1x.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprintf.mcl" "__Lib_PrintOut.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM_256.mcl" "__Lib_FLASH_w8_e64.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_CFFat16.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_Mmc.mcl" "__Lib_MmcFat16.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl" 
0 125 All files Preprocessed in 15 ms 
0 121 Compilation Started t1x.c
16 1504 Initialization of extern object 'adcvalmax' t1x.c
43 1504 Initialization of extern object 'adcvalmax' t1x.c
77 1506 Implicit conversion of pointer to int t1x.c
96 1508 Implicit conversion of int to ptr t1x.c
223 122 Compiled Successfully t1x.c
0 126 All files Compiled in 172 ms 
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c
0 102 Finished (with errors): 08 May 2010, 09:47:28 t1x.mcppi

Recommended Answers

All 7 Replies

Error messages are pretty straightforward - non-reentrant library code can't be executed in the same time by several threads (2 threads in this case).
You must use semaphores (mutex) to lock shared resources between threads in such a way, that shared resource is accessed by only 1 thread at a time. That is - you must implement thread synchronization.
http://en.wikipedia.org/wiki/Semaphore_%28programming%29
For example- in system which supports POSIX threads, thread synchronization could look like this:

#include <pthread.h>

// global mutex variable
pthread_mutex_t LCD_mutex;

pthread_mutex_lock(&LCD_mutex);
// call non-reentrant LCD_* function here, such as =>
Lcd_out(...);
pthread_mutex_unlock(&LCD_mutex);

But concrete semaphore/mutex implementation is OS-dependent, so you should read your microcontroller manual about mutex implementation. Besides you must think - what code exactly you want to lock for thread synchronization. It can be just a single LCD_* operation OR it can be whole section of your code as well. Depends on what your goals are.

Good luck.

Hi.Thanks a great.But how about these error messages,please;


1)extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 43 1504 Initialization of extern object 'adcvalmax' t1x.c//

2) return(adcvalmax);//77 1506 Implicit conversion of pointer to int t1x.c //

3) LCD_Out(2,14,rp2val);// 96 1508 Implicit conversion of int to ptr t1x.c //

Thanks,


Error messages are pretty straightforward - non-reentrant library code can't be executed in the same time by several threads (2 threads in this case).
You must use semaphores (mutex) to lock shared resources between threads in such a way, that shared resource is accessed by only 1 thread at a time. That is - you must implement thread synchronization.
http://en.wikipedia.org/wiki/Semaphore_%28programming%29
For example- in system which supports POSIX threads, thread synchronization could look like this:

#include <pthread.h>

// global mutex variable
pthread_mutex_t LCD_mutex;

pthread_mutex_lock(&LCD_mutex);
// call non-reentrant LCD_* function here, such as =>
Lcd_out(...);
pthread_mutex_unlock(&LCD_mutex);

But concrete semaphore/mutex implementation is OS-dependent, so you should read your microcontroller manual about mutex implementation. Besides you must think - what code exactly you want to lock for thread synchronization. It can be just a single LCD_* operation OR it can be whole section of your code as well. Depends on what your goals are.

Good luck.

Hi.Thanks a great.But how about these error messages,please;


1)extern int adcvalmax[8]= {0,0,0,0,0,0,0,0};// 43 1504 Initialization of extern object 'adcvalmax' t1x.c//

You get "Initialization of extern object xxx" error because you try to initialize extern object which is already initialized. So double initialization is not legal. So if you want to re-fill zeros of adcvalmax array - do something like instead:

memset(adcvalmax,0,8*sizeof(int));

Or just use loop to re-assign zeros to each element. But memset maybe more effective.

I am too tired to analyze rest errors ;)

OK, now about other errors.

1.Implicit conversion of pointer to int.

You don't need to return anything from MR_CHNS function, because it already accepts pointer to array and modifies that array in-place. So just change declaration of that function to

void MR_CHNS(int adcvalmax[8])
// AND delete this line in function =>
return(adcvalmax);

2. Implicit conversion of int to ptr.

I don't know what parameters LCD_out accepts, because you didn't show here how this library function header looks like. But i suppose that it must accept pointer to something. And you are feeding just INT. Which is bad.
If lcd_out can accept pointer to int, then do this instead

LCD_Out(2,14,&rp2val);

But somehow i suspect that it must accept pointer to char array. In this case the fact that you are trying to feed int is doubly-bad. You must in this case convert int to char*. Something like:

char* buffer[50];
sprintf(buffer,"%d",rp2val);
LCD_Out(2,14,buffer);

The problem is that I don't know what you are trying to achieve here. So i can only guess and try to help based on these guesses.
Hope that helps.

Dear 0x69,
Hi.Thanks a great for your very use full suggestions.I tested your suggestions a minute ago and all error messages omitted(but reentrancy error messages still remain) and my compiler accept the following library routines as you
suggested;

PWM1_Set_Duty(rp2val);//Set & change duty ratio due to the VRP 2 value from 0 -255;(ADRESL)

LCD_Out(2,14,&rp2val);
//void Lcd_Out(char row, char column, char *text);

//void Lcd_Out_Cp(char *text);//

void Lcd_Chr(char row, char column, char out_char);//

void Lcd_Chr_Cp(char out_char);//

void Lcd_Cmd(char out_char);//

memset(adcvalmax,0,8*sizeof(int));
memset(ch,0,8*sizeof(int));

Also,My compiler's note on using" Indirect Function Calls"( that is vague for me):


mikroC Help--------------------------------------------------------------------------------

Indirect Function Calls
If the linker encounters an indirect function call (by a pointer to function), it assumes that any one of the functions, addresses of which were taken anywhere in the program, can be called at that point. Use the #pragma funcall directive to instruct the linker which functions can be called indirectly from the current function:

#pragma funcall <func_name> <called_func>[, <called_func>,...]

A corresponding pragma must be placed in the source module where function func_name is implemented. This module must also include declarations of all functions listed in the called_func list.

All functions listed in the called_func list will be linked if function func_name is called in the code no meter whether any of them was called or not.

Note: The #pragma funcall directive can help the linker to optimize function frame allocation in the compiled stack.



But still remain these ( may be I do not exactly how to write
#pragma funcall directive);

0 125 All files Preprocessed in 16 ms
0 121 Compilation Started E
226 122 Compiled Successfully E
0 126 All files Compiled in 172 ms
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
184 365 Reentrancy is not allowed: function 'Lcd_Out' called from two threads __Lib_Lcd.c
50 365 Reentrancy is not allowed: function 'Lcd_Chr_CP' called from two threads __Lib_Lcd.c
18 365 Reentrancy is not allowed: function 'Lcd_Cmd' called from two threads __Lib_Lcd.c
0 102 Finished (with errors): 09 May 2010, 15:27:44 t3x.mcppi

Would you please tell me where and how to write the directive(thread/semaphore) #pragma funcall in my program?

Thanks & Regards,


OK, now about other errors.

1.Implicit conversion of pointer to int.

You don't need to return anything from MR_CHNS function, because it already accepts pointer to array and modifies that array in-place. So just change declaration of that function to

void MR_CHNS(int adcvalmax[8])
// AND delete this line in function =>
return(adcvalmax);

2. Implicit conversion of int to ptr.

I don't know what parameters LCD_out accepts, because you didn't show here how this library function header looks like. But i suppose that it must accept pointer to something. And you are feeding just INT. Which is bad.
If lcd_out can accept pointer to int, then do this instead

LCD_Out(2,14,&rp2val);

But somehow i suspect that it must accept pointer to char array. In this case the fact that you are trying to feed int is doubly-bad. You must in this case convert int to char*. Something like:

char* buffer[50];
sprintf(buffer,"%d",rp2val);
LCD_Out(2,14,buffer);

The problem is that I don't know what you are trying to achieve here. So i can only guess and try to help based on these guesses.
Hope that helps.

Ok. My last help attempt regarding non-reentrancy.
I don't know trick about "#pragma funcall" - it is too special for microchip API. However i could suggest 2 possible solutions:

1.
As i said about using semaphore/mutex. I don't know PIC controller specifics, but after some googling i found that some microcontrollers supports OS_WAIT() function. You could use this function to implement semaphore. Something like this site mentions-
http://www.keil.com/support/docs/690.htm

2. Try to re-write code in such a way that all non-reentrant LCD_* functions are called only from one thread. That is - in all interrupt functions only leave code which sets flags to 1 - meaning interrupt signal was received.
In main() have a loop which checks these flags and if it is 1 - does all necessary actions with LCD and clears these flags. So that all calls to LCD_* will be performed only from one thread.

Maybe that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.