@sternest der Code ist genau der gleiche wie der oben. Ich habe kein Zeichen verändert sondern nur strg c und dann strg v gemacht.
aber hier auch nochmal alle Fehlermeldungen dazuCode:/************************************************************************ SERVO Controller for up to 10 Servos controlled by serial line default: 2400 Baud 8N1 Processor: ATMEGA 8 CLOCK: 8MHZ, no prescaler set config bits of Atmega 8 correctly ! Compiler: AVR-GCC This code is licensed under the GPL. You may modify, redistribute the code .. blabla, you know what I mean ... Copyright stochri (c.hab@gmx.net) Nov.2005 Warnungen beiseitigt von uwegw ***************************************************************************/ #include <stdlib.h> #include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> typedef unsigned char byte; #define SYSCLK 8000000 // timer clock 8Mhz #define MAXPULSFREQ 500 // 2ms => 500HZ #define TIMER_MAXPULS SYSCLK/MAXPULSFREQ // Timer1 value for a 2ms Puls #define MINPULS TIMER_MAXPULS/4 // min pulslength = 0.5ms #define MAXPULS TIMER_MAXPULS // max pulslength=2ms // port pin definitions // you may redefine the pins to suit your application // tale a look at the interrupt routine and enable the cases for your servo #define LOW_SERVO0 PORTD&=~(1<<6) #define HIGH_SERVO0 PORTD|=(1<<6) #define LOW_SERVO1 PORTB&=~(1<<0) #define HIGH_SERVO1 PORTB|=(1<<0) #define LOW_SERVO2 PORTB&=~(1<<1) #define HIGH_SERVO2 PORTB|=(1<<1) #define LOW_SERVO3 #define HIGH_SERVO3 #define LOW_SERVO4 #define HIGH_SERVO4 #define LOW_SERVO5 #define HIGH_SERVO5 #define LOW_SERVO6 #define HIGH_SERVO6 #define LOW_SERVO7 #define HIGH_SERVO7 #define LOW_SERVO8 #define HIGH_SERVO8 #define LOW_SERVO9 #define HIGH_SERVO9 uint16_t Pulslength[20]; // array for all delays /************************************************************************ SIGNAL(SIG_OVERFLOW1) timer1 interrupt, generates the high and low pulses for each servo ***************************************************************************/ SIGNAL(SIG_OVERFLOW1) { static byte servoindex_half=0; switch (servoindex_half) { case 0: HIGH_SERVO0; break; case 1: LOW_SERVO0; break; case 2: HIGH_SERVO1; break; case 3: LOW_SERVO1; break; case 4: HIGH_SERVO2; break; case 5: LOW_SERVO2; break; // case 6: HIGH_SERVO3; break; // case 7: LOW_SERVO3; break; // case 8: HIGH_SERVO4; break; // case 9: LOW_SERVO4; break; // case 10: HIGH_SERVO5; break; // case 11: LOW_SERVO5; break; // case 12: HIGH_SERVO6; break; // case 13: LOW_SERVO6; break; // case 14: HIGH_SERVO7; break; // case 15: LOW_SERVO7; break; // case 16: HIGH_SERVO8; break; // case 17: LOW_SERVO8; break; // case 18: HIGH_SERVO9; break; // case 19: LOW_SERVO9; break; } TCNT1 =Pulslength[servoindex_half]; // set time for next interrupt servoindex_half++; // increment timervalue index if(servoindex_half==20)servoindex_half=0; // reset index } /************************************************************************ void setservo(byte index, byte value) Set servo position value: 0..255 ***************************************************************************/ void setservo(byte index, byte value) { uint16_t wert; wert=MINPULS+(MAXPULS-MINPULS)/256*value; // callculate hightime Pulslength[index<<1]=0-wert; // sume of low and hightime for one servo is 2ms Pulslength[(index<<1)+1]=0-(TIMER_MAXPULS-wert); // 10 Servos give you 10*2ms=20ms total cycle time } /************************************************************************ void init_servos() initialize all Servos to the start position ***************************************************************************/ void init_servos(void) { byte n; for(n=0;n<10;n++) setservo(n,128); } /************************************************************************ void init(void) initialize the prozessor registers ***************************************************************************/ void init(void) { // prepare RS232 UCSRA = 0x00; UCSRB = 0x00; UCSRC = 0x86; // No Parity | 1 Stop Bit | 8 Data Bit UBRRL = 0xCF; // 2400bps @ 8.00MHz // UBRRL = 51; // 9600bps @ 8.00MHz // UBRRL = 25; // 19200bps @ 8.00MHz /* initialize ports */ DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; // init timer1 TCNT1 = 0-16000; TCCR1A=0; TCCR1B=0x01; TIMSK |= _BV(TOIE2) | _BV(TOIE1); /* allow interrupts */ sei(); } /************************************************************************ serial communication ***************************************************************************/ byte chgetchar(void) { UCSRB = 0x10; // enable receiver while(!(UCSRA & 0x80)); // wait for received byte return UDR; } void chputchar(byte zeichen) { UCSRB = 0x08; // enable transmitter UCSRA|=0x40; // clear transmitter flag while (!(UCSRA & 0x20)); // wait for empty transmit buffer UDR = zeichen; while (!(UCSRA & 0x40)); // Wait for transmit complete flac (TXC) } void chSerPrint(char *data) { unsigned char i = 0; while(data[i]!=0x00) chputchar(data[i++]); } /************************************************************************ main programm servo controll by RS232 interface ***************************************************************************/ int main(void) { char c; byte n; byte servos[10]; init(); init_servos(); chSerPrint("\n\r-- Atmega8 servo controller V1.0 --\n\r"); chSerPrint("Connection OK\n\r"); while(1) { // get key from terminal c=chgetchar(); if(c=='q') servos[0] += 10; if(c=='w') servos[0] -= 10; if(c=='a') servos[1] += 10; if(c=='s') servos[1] -= 10; if(c=='y') servos[2] += 10; if(c=='x') servos[2] -= 10; // set to default position, if space is pressed if(c==' ') { servos[0] = 128; servos[1] = 128; servos[2] = 128; } for(n=0;n<10;n++) setservo(n,servos[n]); } }
achja und noch das MakefileCode:rm -rf Test_Serial.o Test_Serial.elf dep/* Test_Serial.hex Test_Serial.eep Test_Serial.lss Test_Serial.map Build succeeded with 0 Warnings... avr-gcc.exe -mmcu=atmega128 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT Test_Serial.o -MF dep/Test_Serial.o.d -c ../Test_Serial.c ../Test_Serial.c: In function 'init': ../Test_Serial.c:160: error: 'UCSRA' undeclared (first use in this function) ../Test_Serial.c:160: error: (Each undeclared identifier is reported only once ../Test_Serial.c:160: error: for each function it appears in.) ../Test_Serial.c:161: error: 'UCSRB' undeclared (first use in this function) ../Test_Serial.c:162: error: 'UCSRC' undeclared (first use in this function) ../Test_Serial.c:163: error: 'UBRRL' undeclared (first use in this function) ../Test_Serial.c: In function 'chgetchar': ../Test_Serial.c:193: error: 'UCSRB' undeclared (first use in this function) ../Test_Serial.c:194: error: 'UCSRA' undeclared (first use in this function) ../Test_Serial.c:195: error: 'UDR' undeclared (first use in this function) ../Test_Serial.c: In function 'chputchar': ../Test_Serial.c:200: error: 'UCSRB' undeclared (first use in this function) ../Test_Serial.c:201: error: 'UCSRA' undeclared (first use in this function) ../Test_Serial.c:203: error: 'UDR' undeclared (first use in this function) make: *** [Test_Serial.o] Error 1 Build failed with 12 errors and 0 warnings...
ich danke auf jedenfall schon mal für die HilfeCode:############################################################################### # Makefile for the project Test_Serial ############################################################################### ## General Flags PROJECT = Test_Serial MCU = atmega128 TARGET = Test_Serial.elf CC = avr-gcc.exe ## Options common to compile, link and assembly rules COMMON = -mmcu=$(MCU) ## Compile options common for all C compilation units. CFLAGS = $(COMMON) CFLAGS += -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d ## Assembly specific flags ASMFLAGS = $(COMMON) ASMFLAGS += $(CFLAGS) ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 ## Linker flags LDFLAGS = $(COMMON) LDFLAGS += -Wl,-Map=Test_Serial.map ## Intel Hex file production flags HEX_FLASH_FLAGS = -R .eeprom HEX_EEPROM_FLAGS = -j .eeprom HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings ## Objects that must be built in order to link OBJECTS = Test_Serial.o ## Objects explicitly added by the user LINKONLYOBJECTS = ## Build all: $(TARGET) Test_Serial.hex Test_Serial.eep Test_Serial.lss size ## Compile Test_Serial.o: ../Test_Serial.c $(CC) $(INCLUDES) $(CFLAGS) -c $< ##Link $(TARGET): $(OBJECTS) $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) %.hex: $(TARGET) avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ %.eep: $(TARGET) -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 %.lss: $(TARGET) avr-objdump -h -S $< > $@ size: ${TARGET} @echo @avr-size -C --mcu=${MCU} ${TARGET} ## Clean target .PHONY: clean clean: -rm -rf $(OBJECTS) Test_Serial.elf dep/* Test_Serial.hex Test_Serial.eep Test_Serial.lss Test_Serial.map ## Other dependencies -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)







Zitieren
Lesezeichen