Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1974436
  • 博文数量: 356
  • 博客积分: 8284
  • 博客等级: 中将
  • 技术积分: 4580
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-15 20:25
个人简介

天行健,君子以自强不息

文章分类

全部博文(356)

文章存档

2018年(1)

2016年(4)

2015年(13)

2014年(14)

2013年(2)

2012年(25)

2011年(43)

2010年(65)

2009年(189)

分类:

2010-03-07 22:41:25

WinAVR(GCC)新手快速入门



导读:很多学习AVR单片机的朋友们,开始都是因为觉得WinAVR比较繁琐才放弃了选择WinAVR做为初学入门的工具,本文将通过一个简单的实例详细介绍WinAVR的入门的Makefile配置和PN(Programmer's Notepad)的使用。

推荐下载最新版本的WinAVR 20090313。

安装完软件后,能看到如下图:

说明见下表:

名称

说明

AVR Insight[WinAVR] 仿真调试用的工具
avr-libc Manual[WinAVR] AVRGCC的C语言函数库帮助手册
GNU Manuals Online[WinAVR] GNU在线帮助
MFile[WinAVR] GCC参数配置工具,为PN编译配置相关参数;具体介绍见下文Makefile配置;
ProgrammersNotepad[WinAVR]  行内简称PN,GCC语言编辑器,提供应用程序接口;
Uninstall WinAVR-20090313 总所周知,卸载该程序时用的;
WinAVR User Manual WinAVR用户手册;
版本 WinAVR-20090313【说明一下版本号】

          

       

          









上表只是对安装软件后的说明,我们实际使用中,主要使用PN和MFile;下面以实例说明。

步骤一:点击PN(ProgrammersNotepad)

步骤二:点击工具栏File-->New-->Project Group, 如下图


点击File-->New-->Project,如下图


在Name里面输入你要建立的工程的名称,Folder为工程文件的路径;点击OK;

步骤三:建立C文件,如下图


点击New新建文件输入如下代码后保存

#include
#include

int  main(void)
{
 unsigned char i;
 DDRB=0XFF;
 PORTB=0XFF;
 while(1)
 {
 for(i=0;i<8;i++)
 {
   PORTB=0X00;   
  }  
 }
 }

代码仅供熟悉软件使用的,没有什么难度,也可以是其它的GCC代码;输入完毕后保存到上面建立的工程文件里面,在同一个文件夹下面;命名为test.c ;
在test项目上面添加刚保存的C文件;




步骤四:配置Makefile文件

点击MFile[WinAVR],点击后跳出对话框,工具栏只有File和Makeflie,点击Makeflie见下图

点击Main file name 输入含有main()函数的那个c文件的文件名,注意此处不用输入扩展名;

Mcu type 选择atmega16;

配置完毕后,Makefile部分内容如下:

# MCU name
MCU = atmega16

# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the
#     processor frequency. You can then use this symbol in your source code to
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
#     Typical values are:
#         F_CPU =  1000000
#         F_CPU =  1843200
#         F_CPU =  2000000
#         F_CPU =  3686400
#         F_CPU =  4000000
#         F_CPU =  7372800
#         F_CPU =  8000000
#         F_CPU = 11059200
#         F_CPU = 14745600
#         F_CPU = 16000000
#         F_CPU = 18432000
#         F_CPU = 20000000
F_CPU = 8000000

# Output format. (can be srec, ihex, binary)
FORMAT = ihex

# Target file name (without extension).
TARGET = test


# Object files directory
#     To put object files in current directory, use a dot (.), do NOT make
#     this an empty or blank macro!
OBJDIR = .


# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c
********************  其它的建议不要配置使用默认的,高手除外****************************
步骤五:最终要的一步就是把上面配置好的文件保存在C文件所在目录里面,并且保持文件名为Makeflie,不要更改Makeflie文件名;

要说明的是,默认的晶振是8MHz的,要是7.3728MHz的,可以在上面的Makeflie文件中将F_CPU = 8000000更改为7372800

步骤六:Make All  操作,如下图

编译成功后,在output窗口会有如下的 Process Exit Code: 0  信息。如果不是0,表面有错误,请检查Makeflie文件和test.c文件,看是否在同一个文件夹里面;
编译成功完整信息如下:

> "make.exe" all

-------- begin --------
avr-gcc (WinAVR 20090313) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Size before:
AVR Memory Usage
----------------
Device: atmega16

Program:     130 bytes (0.8% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

Size after:
AVR Memory Usage
----------------
Device: atmega16

Program:     130 bytes (0.8% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

-------- end --------


> Process Exit Code: 0
> Time Taken: 00:02

编译完成后的test项目文件夹如下图:

步骤七:完成操作

烧录ISP,JTAG仿真待续;

:文章引自

阅读(4022) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~