Witam, napisałem taki o to programik do uC atmega8:
Przy kompilacji wyrzuca mi błędy:
Programik wymyśliłem w devc++, i tam funkcje time(), srand() i rand() działają bez problemu, a winavr 'krzyczy', że nie ma bibliotek. Co jest źle?
* kostka.c programik do losowania liczby (1;6) i wyświetlania na 7-segment.*/
/* układ ATmega 1MHz */
/* PB0,PB1 - diody LED; PD0 - przycisk */
#define F_CPU 1000000L
#include <avr/io.h>
#include <util/delay.h>
#include <time.h>
#include <cstdlib>
int main(void)
{
/*
0
_
5|_|1
4|_|2
3
6 - środek
*/
int x;
DDRD=0xFF;// wszystkie linie portu D beda wyjsciami (segmenty)
DDRB=0x00; //wszystkie linie portu B beda wejsciami z podc. do Vcc
PORTB=0xFF;
while (1)
{
if(!(PINB & 0x01)) // jesli przycisk B1 wcisnienty - losuj
{PORTD=0x00;
srand( (unsigned)time(0) );
x=1+rand()%6;
_delay_ms(1000);
switch(x)
{
case 1:
PORTD=0x06;
break;
case 2:
PORTD=0x5B;
break;
case 3:
PORTD=0x4F;
break;
case 4:
PORTD=0x66;
break;
case 5:
PORTD=0x6D;
break;
case 6:
PORTD=0x7D;
break;
}//switch
}//if
}//while
}//main
Przy kompilacji wyrzuca mi błędy:
kostka.c:5:1: warning: "F_CPU" redefined
<command-line>: warning: this is the location of the previous definition
led.c:8:19: warning: cstdlib: No such file or directory
led.c:9:18: warning: time.h: No such file or directory
led.c:10:20: warning: iostream: No such file or directory
led.c:11:32: warning: conio.h: No such file or directory
led.c: In function 'main':
led.c:40: warning: implicit declaration of function 'srand'
led.c:40: warning: implicit declaration of function 'time'
led.c:41: warning: implicit declaration of function 'rand'
Linking: led.elf
avr-gcc -mmcu=atmega8 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=led.o -std=gnu99 -MMD -MP -MF .dep/led.elf.d led.o --output led.elf -Wl,-Map=led.map,--cref -lm
led.o: In function `main':
D:\dane\jarek\projekty\Mikrokontrolery AVR\led/led.c:40: undefined reference to `time'
make.exe: *** [led.elf] Error 1
> Process Exit Code: 2
> Time Taken: 00:01Programik wymyśliłem w devc++, i tam funkcje time(), srand() i rand() działają bez problemu, a winavr 'krzyczy', że nie ma bibliotek. Co jest źle?