把ATmega128开发板转为Arduino

发布者:zhihua最新更新时间:2020-03-30 来源: eefocus关键字:ATmega128  开发板  Arduino 手机看文章 扫描二维码
随时随地手机看文章

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

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

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

[1] [2] [3] [4] [5]
关键字:ATmega128  开发板  Arduino 引用地址:把ATmega128开发板转为Arduino

上一篇:Arduino - 最小系统(基于ATMEGA8-16PU)
下一篇:基于ATMEGA8515的SPI驱动ST7565P液晶屏的程序

小广播
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved