把ATmega128开发板转为Arduino

本文介绍如何将一个ATmega128的开发板改造成Arduino。主要涉及在AVR单片机上烧录bootloader,使用Arduino IDE进行编程,并详细说明了制作bootloader、设置开发环境和引脚映射的步骤。
摘要由CSDN通过智能技术生成

        暑假来临,闲来无事,听有同学在玩arduino,挺想尝试看看,但是不想买啊,正好手中有一套ATmege128的开发板。以前听过arduino是由avr封装而成,于是就想把这avr开发板改造下。GOOGLE了下,还是有办法的。

        其实Arduino,就是在AVR单片机上烧录了一个bootloader,在通过arduino集成开发环境与单片机进行通讯,继而进行片上编程。

        转载请注明原文地址:http://blog.csdn.net/embbnux/article/details/9391781

  博主最近在电脑上自建了博客,以后会更多的用那个了,欢迎关注访问,里面也有很多有用资源:

      http://www.embbnux.com/


AVR环境:

       编译环境: ubuntu + avr-gcc 

       烧写工具: avrdude+usbasp

 具体构建步骤查看上一篇博客。

   avr环境多种多样,在linux下还可以用eclipse集成环境。在window下推荐用WINAVR,其实本质上和linux下一样是用avr-gcc,烧写工具用prgisp.当然有了avr jtag仿真器就更好了,不用usbasp.

下载arduino工具:

      arduino.cc/en/Main/Software

     我下载的linux 64位版本,下载后解压到主目录下。

开发板:

       BK-AVR128开发板   


一、制作属于atmega128的bootloader

       代码主要是arduino工具自带的,编译时有点问题,我改了几处。

        可以直接到我的资源里面下载编译好的hex文件直接烧写到单片机就可以了:

           download.csdn.net/detail/canyue102/5809329

 源代码boot _mega128.c:

     

/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers        */
/*                                                        */
/* tested with ATmega8, ATmega128 and ATmega168           */
/* should work with other mega's, see code for details    */
/*                                                        */
/*                                           */
/*                                                        */
/*                                                        */
/* 20090308: integrated Mega changes into main bootloader */
/*           source by D. Mellis                          */
/* 20080930: hacked for Arduino Mega (with the 1280       */
/*           processor, backwards compatible)             */
/*           by D. Cuartielles                            */
/* 20070626: hacked for Arduino Diecimila (which auto-    */
/*           resets when a USB connection is made to it)  */
/*           by D. Mellis                                 */
/* 20060802: hacked for Arduino by D. Cuartielles         */
/*           based on a previous hack by D. Mellis        */
/*           and D. Cuartielles                           */
/*                                                        */
/* Monitor and debug functions were added to the original */
/* code by Dr. Erik Lins, chip45.com. (See below)         */
/*                                                        */
/* Thanks to Karl Pitrich for fixing a bootloader pin     */
/* problem and more informative LED blinking!             */
/*                                                        */
/* For the latest version see:                            */
/* http://www.chip45.com/                                 */
/*                                                        */
/* ------------------------------------------------------ */
/*                                                        */
/* based on stk500boot.c                                  */
/* Copyright (c) 2003, Jason P. Kyle                      */
/* All rights reserved.                                   */
/* see avr1.org for original file and information         */
/*                                                        */
/* This program is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General    */
/* Public License as published by the Free Software       */
/* Foundation; either version 2 of the License, or        */
/* (at your option) any later version.                    */
/*                                                        */
/* This program is distributed in the hope that it will   */
/* be useful, but WITHOUT ANY WARRANTY; without even the  */
/* implied warranty of MERCHANTABILITY or FITNESS FOR A   */
/* PARTICULAR PURPOSE.  See the GNU General Public        */
/* License for more details.                              */
/*                                                        */
/* You should have received a copy of the GNU General     */
/* Public License along with this program; if not, write  */
/* to the Free Software Foundation, Inc.,                 */
/* 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA */
/*                                                        */
/* Licence can be viewed at                               */
/* http://www.fsf.org/licenses/gpl.txt                    */
/*                                                        */
/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
/* m8515,m8535. ATmega161 has a very small boot block so  */
/* isn't supported.                                       */
/*                                                        */
/* Tested with m168                                       */
/**********************************************************/

/* $Id$ */


/* some includes */
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/delay.h>

/* the current avr-libc eeprom functions do not support the ATmega168 */
/* own eeprom write/read functions are used instead */
#if !defined(__AVR_ATmega168__) || !defined(__AVR_ATmega328P__)
#include <avr/eeprom.h>
#endif

/* Use the F_CPU defined in Makefile */

/* 20060803: hacked by DojoCorp */
/* 20070626: hacked by David A. Mellis to decrease waiting time for auto-reset */
/* set the waiting time for the bootloader */
/* get this from the Makefile instead */
#define MAX_TIME_COUNT (F_CPU>>1)

/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
#define MAX_ERROR_COUNT 5

/* set the UART baud rate */
/* 20060803: hacked by DojoCorp */
//#define BAUD_RATE   115200
#ifndef BAUD_RATE
#define BAUD_RATE   19200
#endif


/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
/* never allow AVR Studio to do an update !!!! */
#define HW_VER	 0x02
#define SW_MAJOR 0x01
#define SW_MINOR 0x10


/* Adjust to suit whatever pin your hardware uses to enter the bootloader */
/* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */
/* ATmega1280 has four UARTS, but for Arduino Mega, we will only use RXD0 to get code */
/* BL0... means UART0, BL1... means UART1 */
#ifdef __AVR_ATmega128__
#define BL_DDR  DDRF
#define BL_PORT PORTF
#define BL_PIN  PINF
#define BL0     PINF7
#define BL1     PINF6
#elif defined __AVR_ATmega1280__
/* we just don't do anything for the MEGA and enter bootloader on reset anyway*/
#else
/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */
#define BL_DDR  DDRD
#define BL_PORT PORTD
#define BL_PIN  PIND
#define BL      PIND6
#endif


/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
/* if monitor functions are included, LED goes on after monitor was entered */
#if defined __AVR_ATmega128__ || defined __AVR_ATmega1280__
/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128, Arduino Mega) */
#define LED_DDR  DDRB
#define LED_PORT PORTB
#define LED_PIN  PINB
#define LED      PINB7
#else
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */
/* other boards like e.g. Crumb8, Crumb168 are using PB2 */
#define LED_DDR  DDRB
#define LED_PORT PORTB
#define LED_PIN  PINB
#define LED      PINB5
#endif


/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
#define MONITOR 1
#endif


/* define various device id's */
/* manufacturer byte is always the same */
#define SIG1	0x1E	// Yep, Atmel is the only manufacturer of AVR micros.  Single source :(

#if defined __AVR_ATmega1280__
#define SIG2	0x97
#define SIG3	0x03
#define PAGE_SIZE	0x80U	//128 words

#elif defined __AVR_ATmega1281__
#define SIG2	0x97
#define SIG3	0x04
#define PAGE_SIZE	0x80U	//128 words

#elif defined __AVR_ATmega128__
#define SIG2	0x97
#define SIG3	0x02
#define PAGE_SIZE	0x80U	//128 words

#elif defined __AVR_ATmega64__
#define SIG2	0x96
#define SIG3	0x02
#define PAGE_SIZE	0x80U	//128 words

#elif defined __AVR_ATmega32__
#define SIG2	0x95
#define SIG3	0x02
#define PAGE_SIZE	0x40U	//64 words

#elif defined __AVR_ATmega16__
#define SIG2	0x94
#define SIG3	0x03
#define PAGE_SIZE	0x40U	//64 words

#elif defined __AVR_ATmega8__
#define SIG2	0x93
#define SIG3	0x07
#define PAGE_SIZE	0x20U	//32 words

#elif defined __AVR_ATmega88__
#define SIG2	0x93
#define SIG3	0x0a
#define PAGE_SIZE	0x20U	//32 words

#elif defined __AVR_ATmega168__
#define SIG2	0x94
#define SIG3	0x06
#define PAGE_SIZE	0x40U	//64 words

#elif defined __AVR_ATmega328P__
#define SIG2	0x95
#define SIG3	0x0F
#define PAGE_SIZE	0x40U	//64 words

#elif defined __AVR_ATmega162__
#define SIG2	0x94
#define SIG3	0x04
#define PAGE_SIZE	0x40U	//64 words

#elif defined __AVR_ATmega163__
#define SIG2	0x94
#define SIG3	0x02
#define PAGE_SIZE	0x40U	//64 words

#elif defined __AVR_ATmega169__
#define SIG2	0x94
#define SIG3	0x05
#define PAGE_SIZE	0x40U	//64 words

#elif defined __AVR_ATmega8515__
#define SIG2	0x93
#define SIG3	0x06
#define PAGE_SIZE	0x20U	//32 words

#elif defined __AVR_ATmega8535__
#define SIG2	0x93
#define SIG3	0x08
#define PAGE_SIZE	0x20U	//32 words
#endif


/* function prototypes */
void putch(char);
char getch(void);
void getNch(uint8_t);
void byte_response(uint8_t);
void nothing_response(void);
char gethex(void);
void puthex(char);
void flash_led(uint8_t);

/* some variables */
union add
### 回答1: ATmega128是一款功能强大的8位微控制器,常用于嵌入式系统开发。其开发板资料主要包括以下几个方面。 首先,ATmega128开发板资料中包含了ATmega128芯片的详细规格说明书。该规格说明书详细介绍了芯片的功能、引脚定义、电气特性等重要信息,对于开发者来说是重要的参考文档。 其次,开发板资料中通常包含了ATmega128的板级支持文件,如原理图、PCB设计文件等。这些文件展示了开发板的硬件电路设计,使开发者能够更好地了解开发板的结构与原理。 在开发板资料中,我们还可以找到ATmega128开发板的驱动程序和示例代码。这些驱动程序和示例代码可以帮助开发者快速上手并开始开发自己的应用程序。 此外,ATmega128开发板资料中还可能包含了一些相关的开发工具和软件。比如,集成开发环境(IDE)、编译器、调试器等工具可以帮助开发者进行程序开发、调试和烧录。 最后,开发板资料中可能还包括一些使用指南、教程和技术文档。这些文档可以指导开发者正确地使用开发板和芯片,解决常见问题,提供技术支持。 总之,ATmega128开发板资料的丰富和完整性对于开发者来说十分重要。它们提供了开发所需的硬件、软件和技术支持,帮助开发者快速搭建和开发自己的嵌入式系统。 ### 回答2: ATmega128是一种高性能的微控制器,广泛应用于各种嵌入式系统开发中。有关ATmega128开发板的资料如下: 1. 芯片规格:ATmega128是一款AVR系列的8位RISC微控制器,具有128KB闪存和4KB静态随机存储器(SRAM)。它采用基于哈佛结构的指令集,运行速度高达16MHz。 2. 引脚布局:ATmega128开发板具有一系列引脚,包括数字输入/输出引脚、PWM输出引脚、UART引脚、SPI引脚、I2C引脚等。这些引脚可用于连接各种外部设备和传感器。 3. 开发环境:ATmega128可以使用多种开发工具进行编程,包括基于C语言的AVR Studio和Arduino开发环境。这些工具提供了丰富的库函数和示例代码,方便开发者进行项目开发。 4. 扩展模块:ATmega128开发板通常配备有多个扩展插槽,用于连接各种扩展模块。这些模块可以包括LCD显示模块、无线通信模块、传感器模块等,以增强开发板的功能和灵活性。 5. 示例项目:ATmega128开发板资料中通常提供了一些示例项目,可以帮助开发者快速入门。这些项目包括LED灯控制、温度监测、无线通信等,旨在展示ATmega128的功能和应用场景。 总之,ATmega128开发板是一种功能强大的嵌入式系统开发平台,它提供了丰富的开发文档和支持工具,帮助开发者快速实现各种应用。无论是初学者还是经验丰富的开发者,都可以通过ATmega128开发板轻松地进行嵌入式系统的开发和调试工作。 ### 回答3: ATmega128是一款由微芯科技公司推出的8位单片机芯片。它具有高性能、低功耗、丰富的外设和强大的处理能力,广泛应用于嵌入式系统和电子产品的开发中。 ATmega128开发板是专门为ATmega128芯片设计的开发工具。它包含了一些基本的硬件设施,方便开发者进行对ATmega128的开发。常见的开发板提供了芯片的电源管理、外部接口、调试接口以及一些常用的元件。 ATmega128开发板上通常会包括红外、蜂鸣器、数码管、按键、LED等常见输入输出设备,以及电源管理模块、USB接口等常见外设。这些设备可以通过对芯片的编程进行控制,实现各种功能的设计和测试。 通过ATmega128开发板,开发者可以使用编程工具(如C语言、汇编语言等)对芯片进行编程,实现各种任务。开发板上的外设和接口能够提供丰富的功能和灵活的扩展能力,使得开发者可以更便捷地进行芯片功能的验证和调试。 在进行ATmega128开发时,开发者可以根据需要选择合适的开发板,并结合相应的开发环境进行开发。常见的开发环境有Atmel Studio、AVR-GCC等。这些开发环境提供了丰富的工具和库函数,方便开发者进行程序编写、下载和调试等操作。 总之,ATmega128开发板提供了便捷的开发平台和丰富的外设接口,可以有效地进行ATmega128芯片的开发和测试。开发者可以通过开发板和相应的开发环境,利用ATmega128芯片的高性能和强大功能,实现各种嵌入式系统和电子产品的设计和开发。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值