|
|
View previous topic :: View next topic |
Author |
Message |
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
Pointer types don't match |
Posted: Tue Jun 28, 2016 1:19 pm |
|
|
Hi, I have just moved to v5 compiler and I am getting the above warning and I don't see why. I didn't get in v4 or v3 and it is as in the help!
Code: |
void download(char *p)
{
int i = 0;
char temp[10];
float fTemp;
while(*(p + i) != ',')
{
fTemp[i] = *(p + i);
i++;
}
write_eeprom(4, atoi(fTemp));
p += i + 1;
} |
What am I missing?
Brian |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19596
|
|
Posted: Tue Jun 28, 2016 1:39 pm |
|
|
This is wrong in any compiler version.
fTemp, is a single floating point value. You try to access it as an array.... |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
Pointer problems |
Posted: Tue Jun 28, 2016 3:18 pm |
|
|
Hi, Sorry about that - my fingers!
Code should have read:
Code: |
void download(char* p)
{
int i = 0;
while(*(p + i) != ',')
{
temp[i] = *(p + i);
i++;
}
write_float_eeprom(0, atof(temp));
p += (i + 1);
i = 0;
}
|
temp is declared elsewhere as char temp[10];
Hope this makes more sense! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 28, 2016 3:45 pm |
|
|
You didn't post your PIC, or a test program, or your compiler version
so I don't know how you expect us to solve your problem.
Based on your previous posts, I put together the test program shown
below and compiled it with vs. 5.060. It compiles with no problems.
Quote: | Executing: "C:\Program files\Picc\CCSC.exe" +FH "PCH_Test.c" +DF +LY -T -A +M -Z +Y=9 +EA #__buildcount__="0" #__18F2620=TRUE
Memory usage: ROM=3% RAM=3% - 4%
0 Errors, 0 Warnings.
Build Successful.
Loaded C:\Program Files\PICC\Projects\PCH_Test\PCH_Test.cof.
BUILD SUCCEEDED: Tue Jun 28 14:44:08 2016 |
Code: |
#include <18F2620.h>
#fuses H4, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=40M)
#use rs232(baud=9600, UART1, ERRORS)
#include <stdlib.h>
#include <internal_eeprom.c>
char temp[10];
void download(char* p)
{
int i = 0;
while(*(p + i) != ',')
{
temp[i] = *(p + i);
i++;
}
write_float_eeprom(0, atof(temp));
p += (i + 1);
i = 0;
}
//=========================
void main(void)
{
int8 data[80];
download(data);
while(TRUE);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19596
|
|
Posted: Tue Jun 28, 2016 11:40 pm |
|
|
There is a separate problem in the code as posted. No null terminator. When the ',' is seen, you need to write a 0 to the buffer, otherwise depending on what is already in 'temp', the return could be garbage.
Code: |
#include <18F2620.h>
#fuses H4, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=40M)
#use rs232(baud=9600, UART1, ERRORS)
#include <stdlib.h>
#include <internal_eeprom.c>
char temp[10];
void download(char* p)
{
int i = 0;
while(*(p + i) != ',')
{
temp[i] = *(p + i);
i++;
}
temp[i]='\0'; //null terminate
write_float_eeprom(0, atof(temp));
p += (i + 1);
//writing 0 here is pointless i is set to 0 each time
}
//=========================
void main(void)
{
int8 data[80];
download(data);
while(TRUE);
}
|
|
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
Pointer types don't match |
Posted: Wed Jun 29, 2016 2:44 am |
|
|
Hi all, Thanks for replies. I am using the demo compiler 5.056d
Here is my test program. 18LF2620 at 10MHz:
Code: |
#include <TestLCD.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
void main()
{
char temp[10];
float value;
//char LCDline0[21], LCDline1[21], LCDline2[21], LCDline3[21];
//LBV on AN0, LBI on AN1, Aquaroll on AN2, O/B tank on AN3
setup_adc_ports(AN0_TO_AN3|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
setup_wdt(WDT_ON);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(false);
setup_low_volt_detect(false);
//setup serial LCD117
fputs("?S0", lcd); //no display screen on boot
fputs("?f", lcd); //clear lcd
fputs("?G420", lcd); //4x20 LCD
fputs("?c0", lcd); //no cursor
fputs("?BFF", lcd); //display at full brightness
delay_ms(100);
//define Euro symbol for LCD
fputs("?D003041E081E040300", lcd);
//define Pound symbol for LCD
fputs("?D10609081E08081F00", lcd);
//define ßeta symbol for LCD
fputs("?D20C12121412111116", lcd);
fputs("?f", lcd); //clear lcd
delay_ms(200);
fputs("Caravan monitoring?nunit, version 5.00?n(c) 2016 B.L. Lonnon", lcd);
delay_ms(2700);
fputs("?f", lcd); //clear lcd
delay_ms(200);
//warning here "Pointer types do not match"
strcpy(temp, "12.45");
value = atof(temp);
for(;;)
{
}
}
|
The atof code is as per that in the help file!
Brian |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19596
|
|
Posted: Wed Jun 29, 2016 4:51 am |
|
|
OK.
First there are quite a few things wrong in what you post:
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
//Not recommended above 1MHz. Read the data sheet for the correct setting.
setup_spi(SPI_SS_DISABLED);
//Incorrect. Correct command is:
setup_spi(FALSE);
You are turning the SPI 'on', with slave select disabled.....
Then the fault is actually the declaration of atof in the stdlib.h file:
#define atof(s) strtof(s, 0)
Needs to be:
#define atof(s) strtof(s, (char *)0)
With the latest few compilers, CCS have 'tightened up' on warning about type changes between pointers when used. |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
Pointers |
Posted: Wed Jun 29, 2016 5:36 am |
|
|
Hi Ttelmah
Thank you for that. I can only think wrong setup commands came from originally using a PIC16.
On stdlib.h - that's a CCS file so why haven't they corrected it on a compiler costing $600!!!!!!!! Don't they do testing?
Thanks for your help and I will go and play further!
Brian |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|