From: Murray R.V. L. <van...@se...> - 2003-11-23 11:32:36
|
I've just begun to use the latest win32 binary distribution of SDCC. I = can't seem to make printf or printf_small behave correctly on either the = s51 simulator or an AT89C51AC2. void main(void) { int i; init_adc_highres(0x03); init_sio_out(); AN2 =3D 0;=20 AN3 =3D 1; =20 while(1) { for(i =3D 0; i < 256; i++) { printf_small("Sample %d is %d \n\r", i, = (int)read_adc_highres(0)); } } } In this case read_adc_highres() returns an unsigned long, but the = problem will occur just as readily if I have it return an int. It seems that printf_small() will pre-pend minus signs to certain ranges = of numbers in both the loop counter and sampling routine return. ie Sample -245 is 179 Sample 23 is -159 I gave up on printf as I couldn't make it work at all! I compile with the --stack-after-data option.=20 If I were to do 3 printf_small statements in a row, the middle one might = work okay and the others not! Can anyone see immediately where I might be going wrong, or possibly = have some printf\ printf_small experience or usage examples to share? Regards, Murray. |
From: Paul S. <pa...@pj...> - 2003-11-24 09:42:46
|
Have you tried printf_fast ? I wrote that one :-) Paul Murray R.Van Luyn wrote: > I've just begun to use the latest win32 binary distribution of SDCC. I > can't seem to make printf or printf_small behave correctly on either > the s51 simulator or an AT89C51AC2. > > void main(void) > { > > int i; > > init_adc_highres(0x03); > init_sio_out(); > > AN2 = 0; > AN3 = 1; > > while(1) > { > for(i = 0; i < 256; i++) > { > printf_small("Sample %d is %d \n\r", i, > (int)read_adc_highres(0)); > } > } > } > > In this case read_adc_highres() returns an unsigned long, but the > problem will occur just as readily if I have it return an int. > > It seems that printf_small() will pre-pend minus signs to certain > ranges of numbers in both the loop counter and sampling routine return. > > ie Sample -245 is 179 > Sample 23 is -159 > > I gave up on printf as I couldn't make it work at all! > I compile with the --stack-after-data option. > > If I were to do 3 printf_small statements in a row, the middle one > might work okay and the others not! > > Can anyone see immediately where I might be going wrong, or possibly > have some printf\ printf_small experience or usage examples to share? > > Regards, > Murray. |