×
单片机 > 单片机程序设计 > 详情

把ATmega128开发板转为Arduino

发布时间:2024-06-17 发布时间:
|

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: */

/* /zixunimg/eeworldimg/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 */

/* /zixunimg/eeworldimg/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

#include

#include

#include

#include

#include

/* 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

#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 */

/*

[1] [2] [3] [4] [5]
ATmega128开发板Arduino

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
AVR M16实验之六 DS18B20测温