Napisałem programik pod tiny13 w c daje program a tu niemiła niespodzianka.
Jeszcze kod programu:
Co jest nie tak??
P.s. Co ciekawe gdy zamienię linijkę:
na:Wszystko gra....
Więc jak inaczej wygenerować liczbę losową??
> "make.exe" program
Compiling C: main.c
avr-gcc -c -mmcu=attiny13 -I. -gdwarf-2 -DF_CPU=1000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./main.lst -std=gnu99 -MMD -MP -MF .dep/main.o.d main.c -o main.o
main.c: In function 'main':
main.c:12: warning: implicit declaration of function 'rand'
Linking: main.elf
avr-gcc -mmcu=attiny13 -I. -gdwarf-2 -DF_CPU=1000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.o -std=gnu99 -MMD -MP -MF .dep/main.elf.d main.o --output main.elf -Wl,-Map=main.map,--cref -lm
Creating load file for Flash: main.hex
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock main.elf main.hex
Creating load file for EEPROM: main.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O ihex main.elf main.eep || exit 0
avrdude -p attiny13 -P usb -c usbasp -U flash:w:main.hex
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.03s
avrdude: Device signature = 0x1e9007
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
[color=red]avrdude: ERROR: address 0x0410 out of range at line 65 of main.hex[/color]
avrdude: write to file 'main.hex' failed
avrdude done. Thank you.
make.exe: *** [program] Error 1
> Process Exit Code: 2
> Time Taken: 00:01
Jeszcze kod programu:
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
int nadal;
nadal = 0x01;
DDRB = 0x07;
PORTB = 0x18;
while(1) {
int zmienna = rand()%5000;
_delay_ms(zmienna);
PORTB |= 0x01;
while(nadal) {
if (!(PINB & 0x08)) {
PORTB &= ~0x01;
PORTB |= 0x02;
nadal = 0x00;
break;
}
if (!(PINB & 0x10)) {
PORTB &= ~0x01;
PORTB |= 0x03;
nadal = 0x00;
}
_delay_ms(3000);
}
}
}
Co jest nie tak??
P.s. Co ciekawe gdy zamienię linijkę:
int zmienna = rand()%5000;na:
int zmienna = 5673;Więc jak inaczej wygenerować liczbę losową??