답변:
나는 완전한 설명을 할 시간이 없지만, AVR을 프로그래밍하기 위해 리눅스 박스에서 사용하는 요리 책 스타일의 명령을 줄 수있다.
sudo apt-get install avr-libc avrdude binutils-avr gcc-avr srecord을 gdb-avr simulavr위해 선택적으로 던져 넣습니다 .mkdir ~/attiny: cd ~/attinymkdir waveShare4digit8segmentDisplay; cd waveShare4digit8segmentDisplayvi project.cpp아래 명령은 유지 보수를 쉽게하기 위해 환경 변수에 크게 의존합니다.
src=projectcflags="-g -DF_CPU=${avrFreq} -Wall -Os - Werror -Wextra"사용하는 정확한 프로그래머에 따라 아래 변수를 변경해야 할 수도 있습니다. 자세한 내용은 man페이지를 참조하십시오.
baud=19200 프로그래머가 PC와 통신하는 속도 : programmerDev=/dev/ttyUSB003프로그래머가있는 장치 이름. dmesg자세한 내용은 출력을 확인 하십시오.programmerType=avrisp 정확한 프로그래머에 따라 다를 수 있습니다. 아래 변수는 프로그래밍하려는 정확한 컨트롤러에 따라 다릅니다.
avrType=attiny2313avrdude -c $programmerType지원되는 장치를 확인하십시오 .avrFreq=1000000 컨트롤러의 데이터 시트에서 기본 시계를 확인하십시오.avr-gcc ${cflags) -mmcu=${avrType) -Wa,-ahlmns=${src).lst -c -o ${src).o ${src).cppavr-gcc ${cflags) -mmcu=${avrType) -o ${src).elf ${src).oavr-objcopy -j .text -j .data -O ihex ${src).elf ${src).flash.hexavrdude -p${avrType} -c${programmerType} -P${programmerDev} -b${baud} -v -U flash:w:${src}.flash.hex명령을 기억하는 대신, 나는 내 개인 취향에 메이크 위로 요리, 당신은 이름으로 저장할 수 있습니다 Makefile(자본 마음 M). 다음과 같이 작동합니다.
make makefile makefile을 편집하십시오.make edit 소스 파일을 편집하십시오.make flash 장치의 플래시 메모리를 프로그래밍하십시오.make help 다른 명령을 나열하십시오.makefile은 다음과 같습니다.
baud=19200
src=project
avrType=attiny2313
avrFreq=4000000 # 4MHz for accurate baudrate timing
programmerDev=/dev/ttyUSB003
programmerType=arduino
cflags=-g -DF_CPU=$(avrFreq) -Wall -Os -Werror -Wextra
memoryTypes=calibration eeprom efuse flash fuse hfuse lfuse lock signature application apptable boot prodsig usersig
.PHONY: backup clean disassemble dumpelf edit eeprom elf flash fuses help hex makefile object program
help:
@echo 'backup Read all known memory types from controller and write it into a file. Available memory types: $(memoryTypes)'
@echo 'clean Delete automatically created files.'
@echo 'disassemble Compile source code, then disassemble object file to mnemonics.'
@echo 'dumpelf Dump the contents of the .elf file. Useful for information purposes only.'
@echo 'edit Edit the .cpp source file.'
@echo 'eeprom Extract EEPROM data from .elf file and program the device with it.'
@echo 'elf Create $(src).elf'
@echo 'flash Program $(src).hex to controller flash memory.'
@echo 'fuses Extract FUSES data from .elf file and program the device with it.'
@echo 'help Show this text.'
@echo 'hex Create all hex files for flash, eeprom and fuses.'
@echo 'object Create $(src).o'
@echo 'program Do all programming to controller.'
edit:
vi $(src).cpp
makefile:
vi Makefile
#all: object elf hex
clean:
rm $(src).elf $(src).eeprom.hex $(src).fuses.hex $(src).lfuse.hex $(src).hfuse.hex $(src).efuse.hex $(src).flash.hex $(src).o
date
object:
avr-gcc $(cflags) -mmcu=$(avrType) -Wa,-ahlmns=$(src).lst -c -o $(src).o $(src).cpp
elf: object
avr-gcc $(cflags) -mmcu=$(avrType) -o $(src).elf $(src).o
chmod a-x $(src).elf 2>&1
hex: elf
avr-objcopy -j .text -j .data -O ihex $(src).elf $(src).flash.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(src).elf $(src).eeprom.hex
avr-objcopy -j .fuse -O ihex $(src).elf $(src).fuses.hex --change-section-lma .fuse=0
srec_cat $(src).fuses.hex -Intel -crop 0x00 0x01 -offset 0x00 -O $(src).lfuse.hex -Intel
srec_cat $(src).fuses.hex -Intel -crop 0x01 0x02 -offset -0x01 -O $(src).hfuse.hex -Intel
srec_cat $(src).fuses.hex -Intel -crop 0x02 0x03 -offset -0x02 -O $(src).efuse.hex -Intel
disassemble: elf
avr-objdump -s -j .fuse $(src).elf
avr-objdump -C -d $(src).elf 2>&1
eeprom: hex
#avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U eeprom:w:$(src).eeprom.hex
date
fuses: hex
avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U lfuse:w:$(src).lfuse.hex
#avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U hfuse:w:$(src).hfuse.hex
#avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U efuse:w:$(src).efuse.hex
date
dumpelf: elf
avr-objdump -s -h $(src).elf
program: flash eeprom fuses
flash: hex
avrdude -p$(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U flash:w:$(src).flash.hex
date
backup:
@for memory in $(memoryTypes); do \
avrdude -p $(avrType) -c$(programmerType) -P$(programmerDev) -b$(baud) -v -U $$memory:r:./$(avrType).$$memory.hex:i; \
done
실행하는 데 필요한 보일 수 있습니다 avrdude으로 root그게 무슨 일이 생기면, 그 자체에 질문을 정당화한다 . 해결 방법은 udev있지만 운영 체제에서 프로그래머를 인식하는 방법에 대한 약간의 특정 정보가 필요합니다.
컨트롤러 핀 2 (PB3) (예 : ATtiny13, ATtiny45, ATtiny85)를 1Hz로 전환하는 'Hello World'를 입력하겠습니다. 핀에 LED 및 직렬 저항을 연결하면 LED가 깜박이기 시작합니다.
i
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB = 0x08;
while (1) {
PORTB = 0x00; _delay_ms(500);
PORTB = 0x08; _delay_ms(500);
}
}
<ESC>:wq
끝난.
우분투에서 AVR을 개발하기 위해서는 몇 단계 만 거치면됩니다.
툴체인 설치 :
sudo apt-get install gcc-avr binutils-avr gdb-avr avr-libc avrdude
Hello world Code를 작성하고 저장하십시오.
#include<avr/io.h>
#define F_CPU 8000000UL
#include<util/delay.h>
int main() {
DDRB = 0xff; // make PORTB as O/P
PORTB = 0xFF;
while(1) {
PORTB |= (1 << 0);
_delay_ms(100);
PORTB &= ~(1 << 0);
_delay_ms(100);
}
}
메이크 다운로드 tempelate을 하고 저장 한 같은 디렉토리에 저장 hello_world.c파일을.
Makefile 편집 :
# MCU name (Specify the MCU you are using)
MCU = atmega16
# Processor frequency.
F_CPU = 8000000
# Target file name (without extension).
#in this case file name is hello_world
TARGET = main
목표를 세우십시오
그냥 입력 make콘솔에 입력하고 Enter 키를 누르십시오.
avrdude를 사용하여 AVR에 지침 업로드
콘솔에서 다음과 같이 명령을 사용하십시오 (사용하는 프로그래머가 usbasp, google 또는 다른 옵션에 대한 매뉴얼 참조)
$avrdude -c m16 -p usbasp -U flash:w:hello_world.hex