problem mit c strings

Gast #284715
Lesenswert?
• ▲
▼
Hallo,

ich komme mir schon total doof vor, hab alles mögliche gelesen, aber
der code funktioniert nicht:

int main(void)
{
  uint8_t i;
  char ic[]="abcd";
  char ic2[]="dcba";

  for(i=0;i<4;i++)
  {
    if(ic[i] == ic2[i])
    {
      lcd_writechar(97);//schreibt einfach ein a
    }
  }
}


das dämliche: ich bekomme 4 a's :-(
ich versuche strings auf's graphik display zu schreiben, dort kommt
nur müll an. wie der obige code zeigt passiert ja auch seltsames.
irgend was stimmt mit den char arrays nicht.

kann mir mal bitte jemand die tomaten von den augen nehmen?

danke
alex
#284716
Lesenswert?
• ▲
▼
Hmm. Auf Anhieb sehe ich da nichts.
Hast Du den Code neu getippt, oder per Cut&Paste
eingefuegt?

Falls neu getippt: Ein beliebter Fehler, der das
von Dir geschilderte Verhalten erklaeren koennte, waere

anstelle von

    if(ic[i] == ic2[i])

hast Du im Original Code

    if(ic[i] = ic2[i])

(also eine Zuweisung anstatt einem Vergleich)
Gast #284718
Lesenswert?
• ▲
▼
hallo,

jetzt kopiere ich den code mal rein (ich finde aber keine abweichung).
ich lasse mal alles andere stehen:

int main(void)
{
  uint8_t ivar;
  uint16_t i;
  uint16_t j;
  uint16_t k;

  char ic[] = "abcd";
  char ic2[] = "dcba";

  unsigned char my_string[]="123";

  //*************** the global init
  init();
    lcd_setadress(0,0);

    //my_string[40]="Hallo";

    //strcpy(my_string, "test");
    //lcd_stringr(my_string);
    //lcd_writechar(97);

    //   if(ic[0]!='a') lcd_writechar(98);
    //if(ic[0]=='a') lcd_writechar(97);
    for(i=0;i<4;i++)
      {
  if(ic[i] == ic2[i]){
    lcd_writechar(97);
  }
      }
}




unten steht mein makefile.
die objcopy zeile sieht so aus:
${OBJCOPY} -j .text -O ihex ${OBJDIR}/${PROJNAME}.out \
${BINDIR}/${BINNAME}

also nix von .data.
wie müsste denn das aussehen? ich muss aus dem gleichen .out file
.text und .data rauskopieren  richtig?


danke
alex


#
SHELL=/bin/sh

COMPILER=avr-gcc
ASSEMBLER=avr-as
#ASM with cpp
ASSEMBLER=avr-gcc
MMCU=atmega32


#the asm flags
ifeq (${ASSEMBLER},avr-as)
 AFLAGS=-mmcu=${MMCU} \
       -I ${SRCDIR} \

#       --gstabs \
#       -Os
endif
ifeq (${ASSEMBLER},avr-gcc)
 AFLAGS=-mmcu=${MMCU} \
       -c \
       -x assembler-with-cpp \
       -I ${SRCDIR} \
       -Os \

#       -Wa,-gstabs
endif


#the compiler flags
ifeq (${COMPILER},avr-gcc)
 FLAGS=-mmcu=${MMCU} \
       -Os \
       -c \

#      -g
endif


#----------- NO USER-INPUT NEEDED HERE ----------------------------
#the asm command
ifeq (${COMPILER},avr-gcc)
  ASSEMBLE=${ASSEMBLER} ${AFLAGS}
endif


#the compile command
ifeq (${COMPILER},avr-gcc)
  COMPILE=${COMPILER} ${FLAGS}
endif


#the link command
ifeq (${COMPILER},avr-gcc)
  LINK=${COMPILER} -mmcu=${MMCU}
endif
#------------------------------------------------------------------




#____________________ DIRECTORIES __________________

#___________________________ root directory of the SESM distribution
ROOTDIR=./
#___________________________ path to the object files
BINDIR=${ROOTDIR}bin
#___________________________ path to the object files
OBJDIR=${ROOTDIR}bin/obj
#___________________________ path to the object files
SRCDIR=${ROOTDIR}src
#_______________________________________________________________________ 
_



#____________________ ADDITIONAL LIBRARIES __________________
LLIBS=


OBJCOPY=avr-objcopy

#the objects to compile/link
OBJ = main.o \
      s1d1565.o \


#the assembler sources
ASM= lib_eybasm.o \


#name of the final binary
PROJNAME=eyb

BINNAME=${PROJNAME}.hex



#define the path for the obj files:
vpath %.o ${OBJDIR}

#_____________________ the targets _______________________

default: shift ${BINDIR}/${BINNAME}

#the bin target (depends on all obj)
${BINDIR}/${BINNAME}: ${OBJDIR}/${PROJNAME}.out
  @echo
"---OBJCOPY-----------------------------------------------------------"
  ${OBJCOPY} -j .text -O ihex ${OBJDIR}/${PROJNAME}.out
${BINDIR}/${BINNAME}
  @echo
"---------------------------------------------------------------------"
  @echo " "

#linker
${OBJDIR}/${PROJNAME}.out: ${ASM} ${OBJ}
  @echo
"---LINKER------------------------------------------------------------"
  ${LINK} -o ${OBJDIR}/${PROJNAME}.out
-W1,-Map,${OBJDIR}/${PROJNAME}.map $(patsubst %.o,${OBJDIR}/%.o,$(OBJ))
$(patsubst %.o,${OBJDIR}/%.o,$(ASM)) ${LLIBS}
  @echo
"---------------------------------------------------------------------"
  @echo " "


#the object targets (% means all) (depend on the source code)
#this compiles the *.c --> *.o (only those in OBJ-list)
${OBJ}: %.o: ${SRCDIR}/%.c
  @echo
"---COMPILER----------------------------------------------------------"
  ${COMPILE} -o ${OBJDIR}/$@ ${SRCDIR}/$*.c
  @echo
"---------------------------------------------------------------------"
  @echo " "

#the asm targets (% means all) (depend on the source code)
#this compiles the *.S --> *.o (only those in ASM-list)
${ASM}: %.o: ${SRCDIR}/%.S
  @echo
"---ASSEMBLER---------------------------------------------------------"
  ${ASSEMBLE} -o ${OBJDIR}/$@ ${SRCDIR}/$*.S
  @echo
"---------------------------------------------------------------------"
  @echo " "




flash:  ${BINDIR}/${BINNAME}
  @echo
"---FLASH-------------------------------------------------------------"
  #avrdude -P /dev/ttyUSB0 -c stk500v2 -p m32 -U
flash:w:${BINDIR}/${BINNAME}
  avrdude -V -P /dev/ttyUSB0 -c stk500v2 -p m32 -U
flash:w:${BINDIR}/${BINNAME}
  @echo
"---------------------------------------------------------------------"
  @echo " "



new: shift clean default


clean:
  @echo
"---CLEAN-------------------------------------------------------------"
  rm -rf ${OBJDIR}/*.o
  rm -rf ${BINDIR}/${BINNAME}
  rm -rf ${SRCDIR}/*~
  @echo
"---------------------------------------------------------------------"
  @echo " "

shift:
  @echo " "
  @echo " "
  @echo " "
  @echo " "


terminal:
  @echo
"---TERMINAL------------------------------------------------------------ 
-"
  @echo "use 'r xfuse'"
  avrdude -P /dev/ttyUSB0 -c stk500v2 -p m32 -t
  @echo
"---------------------------------------------------------------------"
  @echo 'use the following command to flash the fuse'
  @echo 'avrdude -P /dev/ttyUSB0 -c stk500v2 -p m32 -U xfuse:w:0xii:m
'
  @echo " "
Gast #284719
Lesenswert?
• ▲
▼
lesen bildet :-)
aus man avr-objcopy:

-j sectionname
       --only-section=sectionname
           Copy only the named section from the input file to the
output file.   This
           option  may be given more than once.  Note that using this
option inappro-
           priately may make the output file unusable.


besonders das letzte wort ;-)

wie bin ich drauf gekommen nur nen teil zu kopieren? weiss ich gar
nicht mehr. gibts nen teil den ich NICHT brauche?

gruß
alex
Gast #284721
Lesenswert?
• ▲
▼
ok, nachdem ich nen fehler in den display routinen gefunden hatte,
funktioniert's nun wirklich so wie's soll.

ich hatte die routinen glaub ich hier aus dem vorum (s1d1565)
die richtige version ist:
void lcd_stringr (unsigned char *s)         //Display String from RAM
{unsigned char i;
 while (*s){
   for (i=0; i<6; i++){
     lcd_writebyte(pgm_read_byte(&Font[*s][i]));
   }
   s++;
 }
}

vorher war das s++ im writebyte aufruf mit drin, was natürlich nur mist
produziert.

danke
alex

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren