From: Jesus Calvino-F. <Je...@ec...> - 2005-06-06 18:54:21
|
Works fine here. Below is my test program. The results compiling using MSVC 6 and sdcc follow. What version of sdcc are you using. What was your command line? ----- fp.c test program ----- #include <stdio.h> #include <string.h> #ifdef SDCC_mcs51 #include <8052.h> #endif void main(void) { float result; unsigned char I_HI; unsigned char F_HI; char buff[10], j; printf("Test begins...\n"); for(I_HI=1, F_HI=63; I_HI<220; I_HI+=11) { result= 54.2535 * ((float) (I_HI) + (float) (F_HI) / 65536); //Prepare the floating point result for display using three decimal digits sprintf(buff, "%ld", (long)(result*1000)); j=strlen(buff); buff[j+1]=0; buff[j]=buff[j-1]; buff[j-1]=buff[j-2]; buff[j-2]=buff[j-3]; buff[j-3]='.'; printf("I_HI=%d, F_HI=%d, result=%s\n", I_HI, F_HI, buff); } printf("Test completed...\n"); } #ifdef SDCC_mcs51 unsigned char _sdcc_external_startup(void) { TR1=0; TMOD=(TMOD&0x0f)|0x20; PCON|=0x80; TH1=TL1=0xfd; //38400 baud with 22MHz crystal TR1=1; SCON=0x52; return 0; } char getchar(void) { char c; while (!RI); RI=0; c=SBUF; return c; } void putchar(char c) { while (!TI); TI=0; SBUF=c; if (c=='\n') putchar('\r'); } #endif ----- fp.c End of test program ----- If compiled with MSVC (usinc cl fp.c) this is the output: C:\sdcc\tests>fp Test begins... I_HI=1, F_HI=63, result=54.305 I_HI=12, F_HI=63, result=651.094 I_HI=23, F_HI=63, result=1247.882 I_HI=34, F_HI=63, result=1844.671 I_HI=45, F_HI=63, result=2441.459 I_HI=56, F_HI=63, result=3038.248 I_HI=67, F_HI=63, result=3635.036 I_HI=78, F_HI=63, result=4231.825 I_HI=89, F_HI=63, result=4828.613 I_HI=100, F_HI=63, result=5425.402 I_HI=111, F_HI=63, result=6022.190 I_HI=122, F_HI=63, result=6618.979 I_HI=133, F_HI=63, result=7215.767 I_HI=144, F_HI=63, result=7812.556 I_HI=155, F_HI=63, result=8409.344 I_HI=166, F_HI=63, result=9006.133 I_HI=177, F_HI=63, result=9602.921 I_HI=188, F_HI=63, result=10199.710 I_HI=199, F_HI=63, result=10796.498 I_HI=210, F_HI=63, result=11393.287 Test completed... If compiled using sdcc (using sdcc fp.c) and ran from an AT89S53 this is the output I got in HyperTerminal: Test begins... I_HI=1, F_HI=63, result=54.305 I_HI=12, F_HI=63, result=651.094 I_HI=23, F_HI=63, result=1247.882 I_HI=34, F_HI=63, result=1844.671 I_HI=45, F_HI=63, result=2441.459 I_HI=56, F_HI=63, result=3038.248 I_HI=67, F_HI=63, result=3635.036 I_HI=78, F_HI=63, result=4231.825 I_HI=89, F_HI=63, result=4828.614 I_HI=100, F_HI=63, result=5425.402 I_HI=111, F_HI=63, result=6022.191 I_HI=122, F_HI=63, result=6618.979 I_HI=133, F_HI=63, result=7215.768 I_HI=144, F_HI=63, result=7812.556 I_HI=155, F_HI=63, result=8409.345 I_HI=166, F_HI=63, result=9006.134 I_HI=177, F_HI=63, result=9602.922 I_HI=188, F_HI=63, result=10199.711 I_HI=199, F_HI=63, result=10796.499 I_HI=210, F_HI=63, result=11393.287 Test completed... By the way, this is the version of sdcc I used: C:\sdcc\tests>sdcc -v SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.5.1 #1 040 (Jun 1 2005) (MSVC) At 08:57 AM 6/6/2005, you wrote: >Hello > >I'm building a project using a 87c52 mcu and the SDCC compiler. > >I have a need to solve this equation: > >result= 54.2535 * ((float) (I_HI) + (float) (F_HI) / 65536); > >I have declared the variables as: > >float result; >unsigned char I_HI; >unsigned char F_HI; > >I have compiled a program in MS C++ to solve this equation and it works >fine, but using SDCC it doesn't. I don't know if the problem lies with the >mcu, the code , SDCC or all of the above > >Anybody has any advice I'll appreciate it > >Thanks >Jim Peterson -- Internal Virus Database is out-of-date. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.11.12 - Release Date: 5/17/2005 |