目前共有5篇帖子。 內容轉換:不轉換▼
 
點擊 回復
917 4
【教程】Linux下烧写AVR单片机,以ATMega16为例
一派護法 十九級
1樓 發表于:2013-9-8 05:36
首先安装:
sudo yum install gcc
sudo yum install avrdude
sudo yum install avr-gcc
sudo yum install binutils
sudo yum install avr-libc

我安装的版本是:
Package gcc-4.8.1-1.fc19.x86_64 already installed and latest version
Package avrdude-5.11.1-4.fc19.x86_64 already installed and latest version
Package avr-gcc-4.7.3-0.1.fc19.x86_64 already installed and latest version
Package binutils-2.23.52.0.1-9.fc19.x86_64 already installed and latest version
Package avr-libc-1.8.0-5.fc19.noarch already installed and latest version

[octopus@pc3 ~]$ sudo yum install gcc
Loaded plugins: langpacks, refresh-packagekit
Package gcc-4.8.1-1.fc19.x86_64 already installed and latest version
Nothing to do
[octopus@pc3 ~]$ sudo yum install avrdude
Loaded plugins: langpacks, refresh-packagekit
Package avrdude-5.11.1-4.fc19.x86_64 already installed and latest version
Nothing to do
[octopus@pc3 ~]$ sudo yum install avr-gcc
Loaded plugins: langpacks, refresh-packagekit
Package avr-gcc-4.7.3-0.1.fc19.x86_64 already installed and latest version
Nothing to do
[octopus@pc3 ~]$ sudo yum install binutils
Loaded plugins: langpacks, refresh-packagekit
Package binutils-2.23.52.0.1-9.fc19.x86_64 already installed and latest version
Nothing to do
[octopus@pc3 ~]$ sudo yum install avr-libc
Loaded plugins: langpacks, refresh-packagekit
Package avr-libc-1.8.0-5.fc19.noarch already installed and latest version
Nothing to do
[octopus@pc3 ~]$


下面的程序引用的文件是avr/io.h,如果文件不存在就检查一下avr-libc是否安装好,我用的系统是fedora19
一派護法 十九級
2樓 發表于:2013-9-8 05:38
【示例程序】
【demo1.c】
#include <avr/io.h>

void main(void)
{
    unsigned char i,j,k=0;
    DDRB=PORTB=0xff;
    while (1)
    {
        PORTB=~PORTB;
        //if (PINB&BIT(0))
        //    PORTB&=~BIT(0);
        //else
        //    PORTB|=BIT(0);
        for (i=0;i<255;i++)
            for (j=0;j<255;j++)
                for (k=0;k<13;k++);
    }
}


该程序可以使PB口上的LED闪烁起来,时间大约是一秒(很不精确)。
一派護法 十九級
3樓 發表于:2013-9-8 05:39
【Makefile】
demo: demo1.c
    avr-gcc -mmcu=atmega16 -c demo1.c
    avr-gcc -mmcu=atmega16 -o demo1.elf demo1.o
    avr-objcopy -j .text -j .data -O ihex demo1.elf demo1.hex
    sudo avrdude -p m48 -c usbasp -e -U flash:w:demo1.hex -F
一派護法 十九級
4樓 發表于:2013-9-8 05:40
然后插上USBAsp下载器,输入make就可以编译并下载了哦
一派護法 十九級
5樓 發表于:2013-9-8 05:41
[octopus@pc3 t1]$ make
avr-gcc -mmcu=atmega16 -c demo1.c
avr-gcc -mmcu=atmega16 -o demo1.elf demo1.o
avr-objcopy -j .text -j .data -O ihex demo1.elf demo1.hex
sudo avrdude -p m48 -c usbasp -e -U flash:w:demo1.hex -F
[sudo] password for octopus:

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9403
avrdude: Expected signature for ATMEGA48 is 1E 92 05
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "demo1.hex"
avrdude: input file demo1.hex auto detected as Intel Hex
avrdude: writing flash (212 bytes):

Writing | ################################################## | 100% 0.13s



avrdude: 212 bytes of flash written
avrdude: verifying flash memory against demo1.hex:
avrdude: load data flash data from input file demo1.hex:
avrdude: input file demo1.hex auto detected as Intel Hex
avrdude: input file demo1.hex contains 212 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.06s



avrdude: verifying ...
avrdude: 212 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

[octopus@pc3 t1]$

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:917 回複數:4
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2013-9-8 05:41
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。