Avatar billede tras Juniormester
15. september 2006 - 21:53 Der er 4 kommentarer og
1 løsning

2 Problemer med min kode plz hjælp

Kan i se hvad jeg laver forkert her?! jeg kan nemlig ikke!.

Kode.-...-...--..-.-.
#include "asuro.h"
int main(void){
    unsigned int data[2];
    Init();
    StatusLED(GREEN);
    FrontLED(ON);
    MortorDir(FWD,FWD);
    while(1){
   
        LineData(data[1]);
        if(data[0]>data[1]){
        MortorSpeed(200,150);
        }else{
        MortorSpeed(150,200);
        }
    }
    return 0;
}



BUGS************************************************

C:\Documents and Settings\Admin\Desktop\digi>make all
set -e; avr-gcc -MM -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=test.lst test.c \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > test.d; \
[ -s test.d ] || rm -f test.d
-------- begin --------
avr-gcc --version
avr-gcc (GCC) 3.3.1
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

avr-gcc -c -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=test.lst test.c -o test.o
test.c: In function `main':
test.c:7: warning: implicit declaration of function `MortorDir'
test.c:10: warning: passing arg 1 of `LineData' makes pointer from integer without a cast
test.c:12: warning: implicit declaration of function `MortorSpeed'
avr-gcc -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=test.o test.o asuro.o  --output test.elf -Wl,-Map=test.map,--cref -lm
test.o(.text+0x1e): In function `main':
C:\Documents and Settings\Admin\Desktop\digi/test.c:7: undefined reference to `MortorDir'
test.o(.text+0x3c):C:\Documents and Settings\Admin\Desktop\digi/test.c:14: undefined reference to `MortorSpeed'
make: *** [test.elf] Error 1

> Process Exit Code: 2




asuro.h**********************************************************
/*******************************************************************************
*
* File Name:  asuro.h
* Project  :  ASURO
*
*
* Ver.    Date        Author          Comments
* -------  ----------  --------------  ------------------------------
* 1.00      14.08.2003  Jan Grewe        build
* 2.00    14.10.2003  Jan Grewe        LEFT_VEL, RIGHT_VEL -> MotorSpeed(unsigned char left_speed, unsigned char right_speed);
*                                        LeftRwd(),LeftFwd(),RightRwd(),RigthFwd() -> MotorDir(unsigned char left_dir, unsigned char right_dir);
*                                        GREEN_ON,GREEN_OFF,RED_ON,RED_OFF -> StatusLED(unsigned char color);
*                                        LED_RED_ON, LED_RED_OFF -> FrontLED(unsigned char color);
*                                        Blink(unsigned char left, unsigned char right) -> BackLED(unsigned char left, unsigned char right);
*                                        Alles in Funktionen gefasst => leichter verständlich ?!?!
* 2.10    17.10.2003  Jan Grewe        new Timer funktion void Sleep(unsigned char time36kHz) 
*
*
* Copyright (c) 2003 DLR Robotics & Mechatronics
*****************************************************************************/
/***************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or    *
*  any later version.                                                    *
***************************************************************************/

#ifndef ASURO_H
#define ASURO_H

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

#define  FALSE    0
#define  TRUE    1

#define  OFF    0
#define  ON    1

#define GREEN    1
#define RED        2
#define YELLOW  3

/* Init function Processor will be initalized to work correctly */
void Init(void);

/* Set Status LED (OFF,GREEN,RED,YELLOW)*/
/* example code set Status LED GREEN */
/* StatusLED(GREEN); */
inline void StatusLED(unsigned char color);
/* function for front LED */
/* example code front LED On */
/* FrontLED(ON); */
inline void FrontLED(unsigned char status);

/* function for Back LEDs */
/* example code right LED On left LED Off */
/* BackLED(OFF,ON); */
void BackLED(unsigned char left, unsigned char right);

/* Set motor direction (FWD,RWD,BREAK,FREE)*/
/* example code set Direction for right motor to rewind */
/* MotorDir(BREAK,RWD); */
inline void MotorDir(unsigned char left_dir, unsigned char right_dir);

/* range for motor speed 0..255 */
/* example code set speed for left motor to 150 */
/* MotorSpeed(150,0); */
inline void MotorSpeed(unsigned char left_speed, unsigned char right_speed);

/* function for serial communication */
void SerWrite(unsigned char *data,unsigned char length);
/* timeout = 0 => bloking mode !!! */
void SerRead(unsigned char *data, unsigned char length, unsigned int timeout);

/* function to read out line follow phototransistors (left,rigth) */
void LineData(unsigned int *data);

/* function to read out odometrie phototransistors (left,rigth) */
void OdometrieData(unsigned int *data);

/* function to read out switches */
unsigned char PollSwitch (void);
/* for working with Interrupt */
void StartSwitch(void);
void StopSwitch(void);

/* Sleep function using 36kHz counter */
void Sleep(unsigned char timer36kHz);
/* ----------- END ------------ */


/* --------------- INTERNAL ------------- */
#define GREEN_LED_ON  PORTB |=  GREEN_LED
#define GREEN_LED_OFF PORTB &= ~GREEN_LED
#define RED_LED_ON    PORTD |=  RED_LED
#define RED_LED_OFF  PORTD &= ~RED_LED

#define FWD        (1 << PB5) /* (1 << PD5) */
#define RWD        (1 << PB4) /* (1 << PD4) */
#define BREAK    0x00
#define FREE    (1 << PB4) | (1 << PB5) /* (1 << PD4) | (1 << PD5)*/

#define IRTX        (1 << PB3)
#define GREEN_LED  (1 << PB0)
#define RED_LED    (1 << PD2)

#define PWM       (1 << PB1) | (1 << PB2)
#define RIGHT_DIR (1 << PB4) | (1 << PB5)
#define LEFT_DIR  (1 << PD4) | (1 << PD5)

#define SWITCHES  (1 << PD3)
#define SWITCH_ON  PORTD |= SWITCHES
#define SWITCH_OFF PORTD &= ~SWITCHES

#define BATTERIE  (1 << MUX0) | (1 << MUX2) //ADC5
#define SWITCH    (1 << MUX2)                            //ADC4
#define IR_LEFT      (1 << MUX0) | (1 << MUX1)    //ADC3
#define IR_RIGHT  (1 << MUX1)                            //ADC2
#define FRONT_LED (1 << PD6)

#define ODOMETRIE_LED       (1 << PD7)
#define ODOMETRIE_LED_ON  PORTD |= ODOMETRIE_LED
#define ODOMETRIE_LED_OFF PORTD &= ~ODOMETRIE_LED

#define WHEEL_LEFT  (1 << MUX0)            //ADC1
#define WHEEL_RIGHT  0                    //ADC0

#endif /* ASURO_H */
Avatar billede arne_v Ekspert
15. september 2006 - 22:05 #1
jeg vil tro at fejlene skyldes at Mortor er stavet forkert (skal vaere Motor)
Avatar billede tras Juniormester
15. september 2006 - 22:25 #2
:/ hmm hvorfor så jeg ikke det? Du har 100% ret... Tak. :P
Avatar billede arne_v Ekspert
15. september 2006 - 22:26 #3
saa ligger jeg et svar
Avatar billede karas Nybegynder
16. september 2006 - 00:33 #4
Du skulle nok også overveje at omskrive "LineData(data[1]);" til "LineData(&data[1]);" (jeg har tilføjet '&') hvis du vil have det til at virke:-)
Avatar billede karas Nybegynder
16. september 2006 - 00:35 #5
Du har nok også en anden fejl. Det ser ikke ud til at din kode får skrevet til data[0]. Dvs. når du laver sammenligningen med data[1], så er resultatet udefineret.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester