logo elektroda
logo elektroda
X
logo elektroda
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

Dlaczego poniższy kod wyrzuca błędy? Pliki nagłówkowe.

martinez_93 12 Lut 2016 23:29 822 3
  • #1 15430570
    martinez_93
    Poziom 7  
    Witam serdecznie, mam problem z prostym zastosowaniem plików nagłówkowych.

    Cały czas wyskakują błędy przy poniższym kodzie:

    /*
    * led.h
    *
    * Created on: 12 lut 2016
    * Author: Marcin
    */

    #ifndef LED_H_
    #define LED_H_

    #define LED_PORT B
    #define LED 6

    #endif /* LED_H_ */


    /*
    * led.c
    *
    * Created on: 12 lut 2016
    * Author: Marcin
    */

    #include "led.h"

    DDR(LED_PORT) |= (1<<LED);
    PORT(LED_PORT) |= (1<<LED);


    W czym leży problem?

    Dodano po 31 [sekundy]:

    avr-gcc -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega32 -DF_CPU=8000000UL -MMD -MP -MF"led.d" -MT"led.o" -c -o "led.o" "../led.c"
    ../led.c:10:1: warning: return type defaults to 'int' [enabled by default]
    DDR(LED_PORT) |= (1<<LED);
    ^
    ../led.c: In function 'DDR':
    ../led.c:10:15: error: expected declaration specifiers before '|=' token
    DDR(LED_PORT) |= (1<<LED);
    ^
    ../led.c:11:1: error: expected declaration specifiers before 'PORT'
    PORT(LED_PORT) |= (1<<LED);
    ^
    ../led.c:10:1: warning: type of 'B' defaults to 'int' [enabled by default]
    DDR(LED_PORT) |= (1<<LED);
    ^
    ../led.c:11:1: error: expected '{' at end of input
    PORT(LED_PORT) |= (1<<LED);
    ^
    ../led.c:11:1: warning: control reaches end of non-void function [-Wreturn-type]
    PORT(LED_PORT) |= (1<<LED);
    ^
    make: *** [led.o] Błąd 1

    23:26:03 Build Finished (took 308ms)
  • #2 15430586
    BlueDraco
    Specjalista - Mikrokontrolery
    Poneważ nie widać defincji makra DDR(x), kompilator przyjmuje, że jest to funkcja, której nie zdefiniowałeś; analogicznie dla PORT(x).
  • #3 15430600
    martinez_93
    Poziom 7  
    Jestem bardzo początkujący, mógłbyś poradzić jak to rozwiązać?
    Z góry dziękuję ;)
  • #4 15431089
    BlueDraco
    Specjalista - Mikrokontrolery
    Proste: daruj sobie makra z portami.

    DDRB |= 1 << LED;
    PORTB |= 1 << LED;

    Albo inaczej:

    #define LED_DDR DDRB
    #define LED_PORT PORTB
    #define LED_MASK (1 << LED)

    LED_DDR |= LED_MASK;
    LED_PORT |= LED_MASK;

    Da się to też zapewne zrobić tak, jak chcesz, używając operatora ##, ale nie radzę tego używać początkującemu.
REKLAMA