#1472 pic16: unable to iterate over string

closed-invalid
nobody
5
2013-05-25
2008-08-05
No

While interfacing to a hd44780a-compatible module from a PIC18F2455 I noticed some strange things.

Using printf produced no output.

unsigned char a = 0;
const char msg[] = "Hello world!";
while(a<10)
putchar(msg[a++]);

produced a full display of 'HHHHHHHHHHHHHHHHHHHHH'

...
putchar(msg[9]);

produced 'l' as expected.

and

putchar('H');
putchar('e');
putchar('l');
putchar('l');
putchar('o');
putchar(' ');
putchar('w');
putchar('o');
putchar('r');
putchar('l');
putchar('d');
putchar('!');

produced the usual universal greeting.

To try to determine if the problem is in indexing a string or just looping, I added this code and expected an output of '0 1 2 3 4 ':

while(a<=5) {
putchar('0' + a);
putchar(' ');
a++;
}

but got only '0 1 1 1 1 1 1 1 1 1 1 1 1 ' (as far as the display reached)

So, either I'm doing something REALLY stupid ("Duh, you cant use loops in main!") or there's a bug in the code that produces loops in SDCC pic16.

Strangely, there should be some loops in the delays in the LCD-interface and those seems to work (might be in assembler), but with my head clogged in a cold I can't investigate now.

sdcc --version
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.8.2 #5202 (Aug 4 2008) (UNIX)

I've tried both amd64 and i386 versions. Problem first discovered in a version that was a few days older (maybe a week)

Discussion

  • Raphael Neider

    Raphael Neider - 2008-08-05

    Working source for reference

     
  • Raphael Neider

    Raphael Neider - 2008-08-05

    Logged In: YES
    user_id=1115835
    Originator: NO

    Please attach a complete, compiling source (plus generated .asm file(s)) that shows this behaviour. On my x86-32 box, the above examples happily iterate over the string/output "0 1 2 3 4 5" (using gpsim simulating an 18f1220 and a putchar that writes the char to PORTA, which I watch using "break w 0xF80", "run", "run", ...). Find my source attached (also tried successfully with msg being (a) static or (b) global --> more efficient).

    Did you define a stack using "#pragma [low] [size]" or do you use the default stack (0x200..0x2FF)? Have a look at the .map file (you might need to add -Wl,-m to the sdcc command line to pass -m to gplink).
    Any warnings during compilation/assembling/linking?

    Regards,
    Raphael

    File Added: b203850.c

     
  • Raphael Neider

    Raphael Neider - 2008-10-18
    • labels: --> pic16 target
    • milestone: --> non_bugs
    • status: open --> pending-invalid
     
  • Raphael Neider

    Raphael Neider - 2008-10-18

    It may already too late to answer this one, but still: This is probably due to improper configuration bits. Make sure that you explicitly disable the extended instruction set using
    __code char __at(__CONFIG4L) conf4l = _ENHCPU_OFF_4L; // & more if required

    Regards,
    Raphael

     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 30 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending-invalid --> closed-invalid
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks