avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Bizarre string problem, part 3


From: Ian Caddy
Subject: Re: [avr-gcc-list] Bizarre string problem, part 3
Date: Thu, 09 Sep 2004 15:09:18 +0800
User-agent: Mozilla Thunderbird 0.6 (Windows/20040502)

I actually didn't notice the compilation and downloading commands in your original message.

Following on from my other email, you can not just use the .text section in the obj-copy to get your hex file as this will not contain the initialisation data I was talking about.

Try the objcopy command without the "-j .text" option and see how you go, although you also don't seem to have linked with the libraries that you will need to perform the initialisation as well.

I would get the example makefile that comes with WinAVR (for example) and use it to generate your compilation and linking.

regards,

Ian Caddy


André - BOL wrote:

Hi! First, I'd like to thank everybody for the tips, but they haven't
worked. I formulated a new very simple example to demonstrate the
problem I'm facing.
Suppose I "initialize" a variable in some different and equivalent ways: char a[10] = {'T', 'T', 'T', 'T', 'T' }; char b[] = "TTTTTTT";
    char c[10];      c[0]='T';    c[1]='T';     c[2]='T';      c[3]='T';
//i think this can't be called an initialization!!!
    char *d      = "TTTTTTT"
now, I perform the test if ( x[2] == 'T' ) printf("hi"); // x = a, b, c or d All examples are LEGAL STANDARD PURE C. I chose size 10 and the 3rd
( [2] ! ) element to avoid avoid any doubts that I had enougth space
reserved, and that I took the correct character. All tests should return
true and print "hi". My example ttest.c is to be run on Pc and shows
exactly that with printf's
PROBLEM: when using the very same code on the ATMEGA, changing the
printf's for "turn on led 1", "turn on led 2", etc., only the third char
sequence (C) causes correct evaluation of the if expression (i can see
that, because I have the leds correctly connected and only the 3rd one
lights)
I tryed this under WINDOWS AND UNDER LINUX, using avr-gcc. Compilation and downloading commands: avr-gcc -g -mmcu=atmega32 -Wall -o t.o t.c avr-objcopy -j .text -O ihex t.o t.hex
uisp -dprog=dapa --erase
uisp -dprog=dapa --upload if=t.hex -dno-poll -v=3 --hash=32

------------------------------------------------------------------------

#include <avr/io.h>
#include <string.h>


void xisa() {
        // doesn't work
        char aux[10] = {'A', 'A', 'A', 'A', 'A'} ;
        if ('A' == aux[2]) PORTB |= 0X01;   // 1st led
}


void xisb() {
        // doesn't work
        char aux[] = "BBBBBBB";       
        if ('B' == aux[2]) PORTB |= 0X02;   // 2nd led
}

void xisc() {
        // WORKS !!!!
        char aux[10];
        
        aux[0] = 'C';
        aux[1] = 'C';
        aux[2] = 'C';
        aux[3] = 'C';
        aux[4] = 'C';   
        aux[0] = '\0';
        
        if ('C' == aux[2]) PORTB |= 0X04; // 3rd led
}


void xisd() {
        // doesn't work
        char aux[10];
        aux[0] = '\0';
        strcat(aux, "DDDDDDDD");
        if ('D' == aux[2]) PORTB |= 0X08;   //4th led
}



void main(){
        /***************************************************
        *  I/O
        ***************************************************/
        outp(0xff,DDRB);   // PORT B = OUTPUT   
        outp(0xff,PORTB);  // WRITE PORT        
        PORTB = 0x00;      // BLANKS PORT
                
// TRY EACH OF THESE COMMANDS ALONE, // and the problem persists xisa(); xisb();
        xisc();
        xisd();
        
        
        
}



------------------------------------------------------------------------

#include <string.h>
#include <stdio.h>


void xisa() {
        // doesn't work
        char aux[10] = {'A', 'A', 'A', 'A', 'A'} ;
if ('A' == aux[2]) printf("\n1st led"); }


void xisb() {
        // doesn't work
        char aux[] = "BBBBBBB";       
        if ('B' == aux[2]) printf("\n2ndt led"); // 2nd led
}

void xisc() {
        // WORKS !!!!
        char aux[10];
        
        aux[0] = 'C';
        aux[1] = 'C';
        aux[2] = 'C';
        aux[3] = 'C';
        aux[4] = 'C';   
        aux[0] = '\0';
        
        if ('C' == aux[2]) printf("\n3rd led"); // 3rd led
}


void xisd() {
        // doesn't work
        char aux[10];
        aux[0] = '\0';
        strcat(aux, "DDDDDDDD");
        if ('D' == aux[2]) printf("\n4th led");  //4th led
}



void main(){
        /***************************************************
        *  I/O
        ***************************************************/
        //outp(0xff,DDRB);   // PORT B = OUTPUT 
        //outp(0xff,PORTB);  // WRITE PORT      
        //PORTB = 0x00;      // BLANKS PORT
                
        
xisa(); xisb();
        xisc();
        xisd();
        
        
        
}



------------------------------------------------------------------------

_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


reply via email to

[Prev in Thread] Current Thread [Next in Thread]