From: George F. <fa...@sh...> - 2002-05-30 21:46:16
|
I have a piece of code as follows and it doesn't work. This is for an 8051, am I doing something wrong? int i; char c; xdata unsigned int abuf[1000]; for (i=0; i<1000; i++) { abuf[i] = i; } for (i=0; i<1000; i++) { if ( abuf[i] != i) { puts ("error"); } } This code always gives an error. In fact if I print the results with printf("i -> %x abuf -> %x \n", i, abuf[i]); in the for loop the results are different. i -> 0 | abuf -> 0 i -> 1 | abuf -> 1 i -> 2 | abuf -> 2 i -> 3 | abuf -> 3 i -> 4 | abuf -> 4 i -> 5 | abuf -> 5 i -> 6 | abuf -> 6 i -> 7 | abuf -> 7 i -> 8 | abuf -> 0 i -> 9 | abuf -> 1 i -> a | abuf -> 2 i -> b | abuf -> 3 i -> c | abuf -> 4 i -> d | abuf -> 5 i -> e | abuf -> 6 i -> f | abuf -> 7 i -> 10 | abuf -> 0 i -> 11 | abuf -> 1 i -> 12 | abuf -> 2 i -> 13 | abuf -> 3 Can some one please explain this to me. Thanks I'm new at this C code on 8051 bit:-) What I really want to do is read in 10000 bytes from an A/D convertor and store it in a buffer. Then do things with the results. Unfortunately I can't seem to read what I write in abuf[] no matter whether it is an xdata unsigned char or an integer. |
From: <MSoegtrop@Michael-Soegtrop.de> - 2002-05-31 09:40:54
|
Dear George, i have been working with sdcc for quite a while, and i can't say that it is 100% free of errors, but it is surely better than some Keil or Borland compilers i have been using in the past. What i want to say is: if i would have this effect, i would suspect that something with the xdata hardware is wrong, not with the compiler. Can you access any xdata variables correctly? Eventually your xdata memory is at a different location than sdcc expects it. Microncontrollers are not uniform like PCs and the code depends significantly on the environment, especially your memory map. You should check your schematics, make a memory map and look in the sdcc manual for the proper settings to adopt sdcc to your memory map. Best regards, Michael > -----Original Message----- > From: sdc...@li... > [mailto:sdc...@li...]On Behalf Of > George Farris > Sent: Thursday, May 30, 2002 11:44 PM > To: sdc...@li... > Subject: [Sdcc-user] array gives wrong results > > > I have a piece of code as follows and it doesn't work. This is for an > 8051, am I doing something wrong? > > int i; > char c; > xdata unsigned int abuf[1000]; > > for (i=0; i<1000; i++) { > abuf[i] = i; > } > > for (i=0; i<1000; i++) { > if ( abuf[i] != i) { > puts ("error"); > } > } > > This code always gives an error. In fact if I print the results with > printf("i -> %x abuf -> %x \n", i, abuf[i]); > in the for loop the results are different. > > i -> 0 | abuf -> 0 > i -> 1 | abuf -> 1 > i -> 2 | abuf -> 2 > i -> 3 | abuf -> 3 > i -> 4 | abuf -> 4 > i -> 5 | abuf -> 5 > i -> 6 | abuf -> 6 > i -> 7 | abuf -> 7 > i -> 8 | abuf -> 0 > i -> 9 | abuf -> 1 > i -> a | abuf -> 2 > i -> b | abuf -> 3 > i -> c | abuf -> 4 > i -> d | abuf -> 5 > i -> e | abuf -> 6 > i -> f | abuf -> 7 > i -> 10 | abuf -> 0 > i -> 11 | abuf -> 1 > i -> 12 | abuf -> 2 > i -> 13 | abuf -> 3 > > > Can some one please explain this to me. > Thanks > > I'm new at this C code on 8051 bit:-) > > What I really want to do is read in 10000 bytes from an A/D convertor > and store it in a buffer. Then do things with the results. > Unfortunately I can't seem to read what I write in abuf[] no matter > whether it is an xdata unsigned char or an integer. > > > > > _______________________________________________________________ > > Don't miss the 2002 Sprint PCS Application Developer's Conference > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > > _______________________________________________ > Sdcc-user mailing list > Sdc...@li... > https://lists.sourceforge.net/lists/listinfo/sdcc-user |
From: George F. <fa...@sh...> - 2002-05-31 18:06:22
|
OK here is the whole test. #include <8051.h> #include <stdio.h> typedef unsigned char byte; void main(void) { =09 int i; xdata byte abuf[100]; =09 for (i=3D0; i<100; i++) {=09 abuf[i] =3D i; } for (i=3D0; i<20; i++) { printf("i -> %x | abuf -> %x\n",i, abuf[i]); } } sdcc -c --model-small --stack-after-data main.c sdcc -c --model-small --stack-after-data hwinit.c sdcc --model-small --stack-after-data --xram-loc 0x9000 --code-loc 0x8000 m= ain.rel hwinit.rel running program: i -> 0 | abuf -> 0 i -> 1 | abuf -> 1 i -> 2 | abuf -> 2 i -> 3 | abuf -> 3 i -> 4 | abuf -> 0 i -> 5 | abuf -> 1 i -> 6 | abuf -> 2 i -> 7 | abuf -> 3 i -> 8 | abuf -> 0 i -> 9 | abuf -> 1 i -> a | abuf -> 2 i -> b | abuf -> 3 i -> c | abuf -> 0 i -> d | abuf -> 1 i -> e | abuf -> 2 i -> f | abuf -> 3 i -> 10 | abuf -> 0 i -> 11 | abuf -> 1 i -> 12 | abuf -> 2 i -> 13 | abuf -> 3 PAULMON2 Loc:9000 > Hex dump external memory 9000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F =20 9010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F =20 9020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F !"#$%&'()*+,-./ 9030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 0123456789:;<=3D>? 9040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F @ABCDEFGHIJKLMNO 9050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F PQRSTUVWXYZ[\]^_ 9060: 60 61 62 63 86 44 35 8E D7 E9 FF F7 5A BF 5F FF `abc D5 Wi wZ?_=20 9070: 6B A2 23 62 00 18 D0 01 DB D4 BF 4B 30 FC BA 4D k"#b P [T?K0|:M As you can see from the hex dump the program actually wrote the=20 chars just fine but reading them back seems to be a problem??? The hardware works as far as I can tell. PS: hwinit.c is just a bit of code to initialize the timer and setup the serial port #include "8051.h" #define OSCILLATOR 11059200 #define BAUD 19200 // timer 1 used for baudrate generator #define TIMER1_RELOAD_VALUE -(2*OSCILLATOR)/(32*12*BAUD) unsigned char _sdcc_external_startup() { // TIMER 1 // initialize timer1 for baudrate TR1=3D0; // stop timer 1 TMOD =3D (TMOD&0x0f)|0x20; // T1=3D8bit autoreload timer // baud =3D ((2^SMOD)*xtal)/(32*12*(256-TH1)) PCON |=3D 0x80; // SMOD=3D1: double baudrate TH1=3DTL1=3DTIMER1_RELOAD_VALUE; TR1=3D1; // start timer 1 // initialize serial port SCON=3D0x52; // mode 1, ren, txrdy, rxempty EA=3D1; // enable global interrupt return 0; } char getchar() { char c; while (!RI) ; RI=3D0; c=3DSBUF; return c; } void putchar(char c) { while (!TI) ; TI=3D0; SBUF=3Dc; if (c=3D=3D'\n') { putchar('\r'); } } On Fri, 2002-05-31 at 02:40, Michael S=F6gtrop wrote: > Dear George, >=20 > i have been working with sdcc for quite a while, and i can't say that it > is 100% free of errors, but it is surely better than some Keil or > Borland compilers i have been using in the past. What i want to say is: > if i would have this effect, i would suspect that something with the > xdata hardware is wrong, not with the compiler. Can you access any xdata > variables correctly? Eventually your xdata memory is at a different > location than sdcc expects it. Microncontrollers are not uniform like > PCs and the code depends significantly on the environment, especially > your memory map. You should check your schematics, make a memory map and > look in the sdcc manual for the proper settings to adopt sdcc to your > memory map. >=20 > Best regards, >=20 > Michael >=20 > > -----Original Message----- > > From: sdc...@li... > > [mailto:sdc...@li...]On Behalf Of > > George Farris > > Sent: Thursday, May 30, 2002 11:44 PM > > To: sdc...@li... > > Subject: [Sdcc-user] array gives wrong results > > > > > > I have a piece of code as follows and it doesn't work. This is for an > > 8051, am I doing something wrong? > > > > int i; > > char c; > > xdata unsigned int abuf[1000]; > > > > for (i=3D0; i<1000; i++) { > > abuf[i] =3D i; > > } > > > > for (i=3D0; i<1000; i++) { > > if ( abuf[i] !=3D i) { > > puts ("error"); > > } > > } > > > > This code always gives an error. In fact if I print the results with > > printf("i -> %x abuf -> %x \n", i, abuf[i]); > > in the for loop the results are different. > > > > i -> 0 | abuf -> 0 > > i -> 1 | abuf -> 1 > > i -> 2 | abuf -> 2 > > i -> 3 | abuf -> 3 > > i -> 4 | abuf -> 4 > > i -> 5 | abuf -> 5 > > i -> 6 | abuf -> 6 > > i -> 7 | abuf -> 7 > > i -> 8 | abuf -> 0 > > i -> 9 | abuf -> 1 > > i -> a | abuf -> 2 > > i -> b | abuf -> 3 > > i -> c | abuf -> 4 > > i -> d | abuf -> 5 > > i -> e | abuf -> 6 > > i -> f | abuf -> 7 > > i -> 10 | abuf -> 0 > > i -> 11 | abuf -> 1 > > i -> 12 | abuf -> 2 > > i -> 13 | abuf -> 3 > > > > > > Can some one please explain this to me. > > Thanks > > > > I'm new at this C code on 8051 bit:-) > > > > What I really want to do is read in 10000 bytes from an A/D convertor > > and store it in a buffer. Then do things with the results. > > Unfortunately I can't seem to read what I write in abuf[] no matter > > whether it is an xdata unsigned char or an integer. > > > > > > > > > > _______________________________________________________________ > > > > Don't miss the 2002 Sprint PCS Application Developer's Conference > > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > > > > _______________________________________________ > > Sdcc-user mailing list > > Sdc...@li... > > https://lists.sourceforge.net/lists/listinfo/sdcc-user >=20 >=20 > _______________________________________________________________ >=20 > Don't miss the 2002 Sprint PCS Application Developer's Conference > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm >=20 > _______________________________________________ > Sdcc-user mailing list > Sdc...@li... > https://lists.sourceforge.net/lists/listinfo/sdcc-user --=20 George Farris - VE7FRG Ge...@gm... |
From: Marcelo de C. <ma...@at...> - 2002-05-31 20:01:27
|
That's because everything is correct but abuf[i] is an int and you are=20 converting it to HEX to print.=20 it should be=20 printf("i -> %d | abuf -> %d\n",i, abuf[i]); On Friday 31 May 2002 02:06 pm, George Farris wrote: > } > for (i=3D0; i<20; i++) { > printf("i -> %x | abuf -> %x\n",i, abuf[i]); > } > } |
From: Marcelo de C. <ma...@at...> - 2002-05-31 20:05:23
|
Ooops not really... =20 soory disregard my last e-mail.=20 |
From: Jesus Calvino-F. <Jes...@tu...> - 2002-05-31 21:38:55
|
Hi, Just tried your code in an at89s53 at 22 MHz with 32k of external RAM mapped between 0x0000 and 0x7fff (sdcc options --xram-loc 0x7000 --code-loc 0x0000, everything else the same), no monitor, and this is what I get in a HyperTerminal window: i -> 0 | abuf -> 0 i -> 1 | abuf -> 1 i -> 2 | abuf -> 2 i -> 3 | abuf -> 3 i -> 4 | abuf -> 4 i -> 5 | abuf -> 5 i -> 6 | abuf -> 6 i -> 7 | abuf -> 7 i -> 8 | abuf -> 8 i -> 9 | abuf -> 9 i -> a | abuf -> a i -> b | abuf -> b i -> c | abuf -> c i -> d | abuf -> d i -> e | abuf -> e i -> f | abuf -> f i -> 10 | abuf -> 10 i -> 11 | abuf -> 11 i -> 12 | abuf -> 12 i -> 13 | abuf -> 13 which is correct. What version of sdcc are you using? I am using: D:\sdcc\bin>sdcc -v SDCC : mcs51/gbz80/z80/avr/ds390/pic14/TININative/xa51 2.3.1 (Mar 1 2002) (UNIX) At 11:06 AM 5/31/02, George Farris wrote: >OK here is the whole test. > >#include <8051.h> >#include <stdio.h> > >typedef unsigned char byte; > >void main(void) { > > int i; > xdata byte abuf[100]; > > for (i=0; i<100; i++) { > abuf[i] = i; > } > for (i=0; i<20; i++) { > printf("i -> %x | abuf -> %x\n",i, abuf[i]); > } >} > > >sdcc -c --model-small --stack-after-data main.c >sdcc -c --model-small --stack-after-data hwinit.c >sdcc --model-small --stack-after-data --xram-loc 0x9000 --code-loc 0x8000 >main.rel hwinit.rel > > >running program: > >i -> 0 | abuf -> 0 >i -> 1 | abuf -> 1 >i -> 2 | abuf -> 2 >i -> 3 | abuf -> 3 >i -> 4 | abuf -> 0 >i -> 5 | abuf -> 1 >i -> 6 | abuf -> 2 >i -> 7 | abuf -> 3 >i -> 8 | abuf -> 0 >i -> 9 | abuf -> 1 >i -> a | abuf -> 2 >i -> b | abuf -> 3 >i -> c | abuf -> 0 >i -> d | abuf -> 1 >i -> e | abuf -> 2 >i -> f | abuf -> 3 >i -> 10 | abuf -> 0 >i -> 11 | abuf -> 1 >i -> 12 | abuf -> 2 >i -> 13 | abuf -> 3 |
From: George F. <fa...@sh...> - 2002-05-31 22:23:23
|
Good at least it works. I'm using: sdcc -v SDCC : mcs51/gbz80/z80/avr/ds390/pic14/i186/tlcs900h/xa51 2.3.1-pj2 (May 25 2002) (UNIX) Where did you get the 2.3.1 version that you are using? It looks like my version is broken. I can only find 2.3.0 on the SDCC site. I got it from the PAULMON site. On Fri, 2002-05-31 at 14:37, Jesus Calvino-Fraga wrote: > Hi, > > Just tried your code in an at89s53 at 22 MHz with 32k of external RAM > mapped between 0x0000 and 0x7fff (sdcc options --xram-loc 0x7000 --code-loc > 0x0000, everything else the same), no monitor, and this is what I get in a > HyperTerminal window: > > i -> 0 | abuf -> 0 > i -> 1 | abuf -> 1 > i -> 2 | abuf -> 2 > i -> 3 | abuf -> 3 > i -> 4 | abuf -> 4 > i -> 5 | abuf -> 5 > i -> 6 | abuf -> 6 > i -> 7 | abuf -> 7 > i -> 8 | abuf -> 8 > i -> 9 | abuf -> 9 > i -> a | abuf -> a > i -> b | abuf -> b > i -> c | abuf -> c > i -> d | abuf -> d > i -> e | abuf -> e > i -> f | abuf -> f > i -> 10 | abuf -> 10 > i -> 11 | abuf -> 11 > i -> 12 | abuf -> 12 > i -> 13 | abuf -> 13 > > which is correct. What version of sdcc are you using? I am using: > > D:\sdcc\bin>sdcc -v > SDCC : mcs51/gbz80/z80/avr/ds390/pic14/TININative/xa51 2.3.1 (Mar 1 2002) > (UNIX) > > At 11:06 AM 5/31/02, George Farris wrote: > >OK here is the whole test. > > > >#include <8051.h> > >#include <stdio.h> > > > >typedef unsigned char byte; > > > >void main(void) { > > > > int i; > > xdata byte abuf[100]; > > > > for (i=0; i<100; i++) { > > abuf[i] = i; > > } > > for (i=0; i<20; i++) { > > printf("i -> %x | abuf -> %x\n",i, abuf[i]); > > } > >} > > > > > >sdcc -c --model-small --stack-after-data main.c > >sdcc -c --model-small --stack-after-data hwinit.c > >sdcc --model-small --stack-after-data --xram-loc 0x9000 --code-loc 0x8000 > >main.rel hwinit.rel > > > > > >running program: > > > >i -> 0 | abuf -> 0 > >i -> 1 | abuf -> 1 > >i -> 2 | abuf -> 2 > >i -> 3 | abuf -> 3 > >i -> 4 | abuf -> 0 > >i -> 5 | abuf -> 1 > >i -> 6 | abuf -> 2 > >i -> 7 | abuf -> 3 > >i -> 8 | abuf -> 0 > >i -> 9 | abuf -> 1 > >i -> a | abuf -> 2 > >i -> b | abuf -> 3 > >i -> c | abuf -> 0 > >i -> d | abuf -> 1 > >i -> e | abuf -> 2 > >i -> f | abuf -> 3 > >i -> 10 | abuf -> 0 > >i -> 11 | abuf -> 1 > >i -> 12 | abuf -> 2 > >i -> 13 | abuf -> 3 > > > _______________________________________________________________ > > Don't miss the 2002 Sprint PCS Application Developer's Conference > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > > _______________________________________________ > Sdcc-user mailing list > Sdc...@li... > https://lists.sourceforge.net/lists/listinfo/sdcc-user |
From: Jesus Calvino-F. <Jes...@tu...> - 2002-05-31 22:36:06
|
Got it from http://sdcc.sourceforge.net/snap.php At 03:22 PM 5/31/02, George Farris wrote: >Good at least it works. I'm using: >sdcc -v >SDCC : mcs51/gbz80/z80/avr/ds390/pic14/i186/tlcs900h/xa51 2.3.1-pj2 (May >25 2002) (UNIX) > >Where did you get the 2.3.1 version that you are using? >It looks like my version is broken. I can only find 2.3.0 on the SDCC >site. > >I got it from the PAULMON site. > |