Atmega16L-8PU搭建最小系统
本帖最后由 绿林网页 于 2013-9-21 17:28 编辑买到一块Atmega16L-8PU的芯片,想搭建最小系统试试,查了一些资料,也多亏论坛各位兄弟的帮忙 ,终于能跑起来了,分享一些资料在这里,同时也有一些问题没弄完,抽空继续弄好了,再分享出来
相关帖子:http://www.geek-workshop.com/thread-2901-1-1.html
感谢 nengcai0313 提供的bootloader;
感谢 mxx_xm告诉我添加板卡的方法:
将下载文件解压后放在hardware\arduino\bootloaders\optiboot
并在hardware\arduino\boards.txt里添加如下信息:
###############################################################
atmega16.name=Arduino NG or older w/ ATmega16
atmega16.upload.protocol=stk500
atmega16.upload.maximum_size=14336
atmega16.upload.speed=9600
atmega16.bootloader.low_fuses=0xcf
atmega16.bootloader.high_fuses=0x98
atmega16.bootloader.path=atmega16
atmega16.bootloader.file=ATmegaBOOT.hex
atmega16.bootloader.unlock_bits=0x3F
atmega16.bootloader.lock_bits=0x0F
atmega16.build.mcu=atmega16
atmega16.build.f_cpu=12000000L
atmega16.build.core=M2Arduino
atmega16.upload.using=arduino:avrisp
手头只有 16M的晶振,就上了16M晶振,但配置文件里忘了改写了12M的,还是能启动哈,原因未知,回头配置改16M试试
时间关系,暂时只测试处理这几个管脚,别的还没测试出来,先放上来,回头测试完再补发
第一次画面包图,不会画,请勿见笑哦,在这里感谢 弘毅 提供软件给我
补改:
下面的IO 图有些网友没看到,特提上来
http://image.geek-workshop.com/forum/201212/28/232238os6s7rj17v4iobs4.jpg
本帖最后由 Ansifa 于 2012-12-28 14:39 编辑
{:soso_e120:}可以代替mega168,不错!其实图上面所有电容拆掉都能正常工作,只剩一个晶振,可以试试哦 IO分析不清楚了,谁能帮我?
试验一:
芯片只接晶振和电容,别的什么都不接,可读到如下数据?
void setup()
{
Serial.begin(9600);
Serial.println("begin");
}
void loop()
{
for(int i=0;i<40;i++){
Serial.print(i);
Serial.print("=");
Serial.print(analogRead(i));
Serial.print("");
}
Serial.println();
delay(500);
}
0=3281=3322=4043=3864=3395=3856=3767=3688=3199=33310=38611=38512=36113=34514=35115=38016=36817=36018=34819=34220=36121=36122=37323=36524=35425=32326=33927=36428=35729=36530=35031=34032=36133=35034=36635=35136=34537=33638=34739=362
0=3771=3482=3703=3764=3925=3706=3767=3898=3719=33910=36911=36312=39613=37814=35615=36416=37417=39218=37019=36320=35621=36222=38223=37424=39425=36226=34127=35328=36029=38530=37131=36632=33333=34634=37535=36236=37237=35638=33439=360
0=4171=4002=3453=3784=4405=4006=3557=4208=4079=34310=33611=33912=43613=42314=38315=36216=33017=44618=40319=39420=37421=34822=37023=38724=45825=41026=38327=34528=34429=42130=39731=40132=35433=30234=35935=37036=41337=38638=36239=346
0=3971=4752=4013=3304=4445=4306=3847=3988=3929=43810=40111=30012=39413=41714=45115=40516=31817=34318=39719=42220=38921=38922=37523=35224=43425=40526=44327=39028=34229=35230=38431=42332=40433=38134=35935=33836=41537=39438=41339=381
0=2861=4652=4433=3774=3955=4186=4427=4038=3369=47710=44911=39912=36013=35714=45615=43416=40517=36918=33719=41420=40521=42622=40323=38024=31625=36226=43627=41128=40629=36830=33131=40132=40433=44634=39835=36236=35437=37938=42739=403
0=3661=3572=4153=4494=3895=3806=4617=4188=3029=43010=40811=46412=41613=33514=38215=41616=48017=41118=37719=37620=38121=43622=41023=41924=37425=31126=36327=38628=43829=40230=37431=36232=35433=44934=40635=40836=37737=33338=38739=395
0=4661=3752=3533=4614=4355=3616=4307=4068=4109=34810=33411=44012=44313=41514=38215=34716=45917=42318=41719=38420=36321=37222=39923=43024=42225=40226=35627=33328=42129=40530=42531=39132=31833=35334=37935=42536=39737=37938=35939=354
0=5041=4262=3423=4104=4255=4316=3847=3818=4839=40710=30611=37212=38913=47314=42615=37116=33417=39018=43919=39720=39121=38322=34723=40524=41325=47026=41327=36528=34529=38130=43831=41032=40333=36434=32435=40936=39237=42538=39139=359
0=3991=4402=4273=3714=3835=4646=4207=3598=4589=42310=42011=37112=32413=43514=44215=42616=37317=31818=38419=39820=41621=39422=38823=37024=35125=44626=41827=42528=37729=33130=38631=39732=46733=40634=37635=36036=36637=42638=40239=401
0=3461=3772=4743=4184=3385=4496=4277=3998=3649=38110=46411=44012=35513=36114=39015=44816=41817=38118=37119=36420=42521=40522=42123=39824=33025=33726=37527=43628=40529=38730=36331=35632=45533=40534=42135=38536=34437=36638=38539=420
0=4091=3002=4233=4284=4025=3796=3997=4278=3979=32210=42711=42212=44513=39314=32415=39516=43717=44818=39919=36920=37221=39422=43423=41024=42725=36426=31327=39428=39829=43730=39731=36632=32833=37334=43135=39836=39237=36838=33339=401
(以下试验中接电位器和发光二极管的不包含 电源和晶振脚复位脚 9,10,11,12,13,30,31,32)
实验二:
从 IO 40脚 ---》 33脚 逐个接 上拉电位器 可以读到模拟电压 程序设置为 0-7 ,其他管脚接电位器均无反应
得出结论:IO 40 --- 33 分别是模拟输入口 0 -7(程序里只能写 0 ,不能写 A0,写A0无法编译 报错:'A0'was not declared in this scope)
void setup()
{
Serial.begin(9600);
Serial.println("begin");
}
void loop()
{
int n = analogRead(0));
Serial.println(n);
delay(500);
}
实验三:
将所有IO 接 发光二极管 验证输出
结果:
40脚 --》33脚 程序设置分别为 0-7 闪烁;
1脚 ---》 8 脚 程序设置分别为 8-15 闪烁;
22脚,23脚 程序设置分别为 16,17 闪烁;
28脚29脚, 程序设置分别为闪烁22,23 闪烁;
14--》21 程序设置分别为 24-31 闪烁;
27,25,24 脚常亮,26无反应
void setup()
{
for(int i=0;i<40;i++){
pinMode(i,OUTPUT);
}
}
void loop()
{
for(int i=0;i<40;i++){
digitalWrite(i,HIGH);
delay(50);
digitalWrite(i,LOW);
delay(50);
}
}
最终得出接论如图:
如果不对,请大叫纠正,并且哪位能解释 24,25,26,27 是怎么回事
其他补充:
1、配置文件中 atmega16.build.f_cpu=12000000L 配置的12M,实际晶振上的16M的,可以启动,但是串口通讯全是乱码,将配置修改为 atmega16.build.f_cpu=16000000L 后,一切正常
2、Ansifa 说的没错,整个电路只留下晶振可正常工作,去掉晶振就不能工作啦
本帖最后由 mxx_xm 于 2012-12-29 00:54 编辑
另外帮你补充一点,事实上引脚是可以定义的,在1.0以上版本的boards.txt文件里每种板子有类似atmega8.build.variant=standard的参数根据这个参数你可以在variants文件夹中找到对应的文件夹下的
pins_arduino.h文件这个文件就定义了引脚的对应功能,如果你愿意,你可以用多数AVR芯片(99%)来做Arduino兼容.以1.0为例我做一下简单注释(1.0以前的此文件在\hardware\arduino\cores\arduino文件夹下,不需要variant参数指定,但还要和pins_arduino.c配合设置)
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA02111-1307USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define NUM_DIGITAL_PINS 20 //定义20个数字脚
#define NUM_ANALOG_INPUTS 6//定义6个模拟
#define analogInputToDigitalPin(p)((p < 6) ? (p) + 14 : -1)
//下面几行是PWM
#if defined(__AVR_ATmega8__)
#define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11)
#else
#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
#endif
//下面是一些特殊复用功能的定义
static const uint8_t SS = 10;
static const uint8_t MOSI = 11;
static const uint8_t MISO = 12;
static const uint8_t SCK= 13;
static const uint8_t SDA = 18;
static const uint8_t SCL = 19;
static const uint8_t LED_BUILTIN = 13;
static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
#ifdef ARDUINO_MAIN
// On the Arduino board, digital pins are also used
// for the analog output (software PWM).Analog input
// pins are a separate set.
// ATMEL ATMEGA8 & 168 / ARDUINO
//
// +-\/-+
// PC61| |28PC5 (AI 5)
// (D 0) PD02| |27PC4 (AI 4)
// (D 1) PD13| |26PC3 (AI 3)
// (D 2) PD24| |25PC2 (AI 2)
// PWM+ (D 3) PD35| |24PC1 (AI 1)
// (D 4) PD46| |23PC0 (AI 0)
// VCC7| |22GND
// GND8| |21AREF
// PB69| |20AVCC
// PB7 10| |19PB5 (D 13)
// PWM+ (D 5) PD5 11| |18PB4 (D 12)
// PWM+ (D 6) PD6 12| |17PB3 (D 11) PWM
// (D 7) PD7 13| |16PB2 (D 10) PWM
// (D 8) PB0 14| |15PB1 (D 9) PWM
// +----+
//
// (PWM+ indicates the additional PWM pins on the ATmega168.)
// ATMEL ATMEGA1280 / ARDUINO
//
// 0-7 PE0-PE7 works
// 8-13 PB0-PB5works
// 14-21 PA0-PA7 works
// 22-29 PH0-PH7 works
// 30-35 PG5-PG0 works
// 36-43 PC7-PC0 works
// 44-51 PJ7-PJ0 works
// 52-59 PL7-PL0 works
// 60-67 PD7-PD0 works
// A0-A7 PF0-PF7
// A8-A15 PK0-PK7
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
//模式定义
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
};
//输出定义
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
};
//输入定义
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
};
//下面这两组数组定义要匹配对应来定义引脚,按0到最大定义引脚上限数顺序,现在是0~20
//举例说明:下面的0脚被定义为PD0(PD _BV(0))
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
PC, /* 14 */
PC,
PC,
PC,
PC,
PC,
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(0), /* 14, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
};
//下面是TIMER的设置
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
// on the ATmega168, digital pin 3 has hardware pwm
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
#else
TIMER2B,
#endif
NOT_ON_TIMER,
// on the ATmega168, digital pins 5 and 6 have hardware pwm
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
NOT_ON_TIMER,
#else
TIMER0B,
TIMER0A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER, /* 8 - port B */
TIMER1A,
TIMER1B,
#if defined(__AVR_ATmega8__)
TIMER2,
#else
TIMER2A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 14 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
#endif
#endif
我说的不一定准确,也是瞎搞,仅供参考。更复杂的芯片你需要参考MEGA的参数设定,如果是xmega的话核心库也要改动
本帖最后由 绿林网页 于 2012-12-29 13:02 编辑
mxx_xm 发表于 2012-12-29 00:41 static/image/common/back.gif
另外帮你补充一点,事实上引脚是可以定义的,在1.0以上版本的boards.txt文件里每种板子有类似atmega8.build ...
膜拜!高手呀!学习了!顺便把资料贴一点上来
阅,不错! 其实论坛已经有人发过对应引脚了,lz还重新测一遍,真不容易。不过这倒是一篇不错的学习帖 wasdpkj 发表于 2012-12-29 21:22 static/image/common/back.gif
其实论坛已经有人发过对应引脚了,lz还重新测一遍,真不容易。不过这倒是一篇不错的学习帖
我没有搜到Atmega16L 的呀,Atmega8的倒是很多
笨笨的学习了哈 绿林网页 发表于 2012-12-29 22:19 static/image/common/back.gif
我没有搜到Atmega16L 的呀,Atmega8的倒是很多
笨笨的学习了哈
比如:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=1856
不过此帖的引脚检测办法不错,聪明人 wasdpkj 发表于 2012-12-29 22:21 static/image/common/back.gif
比如:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=1856
不过此帖的引脚检测办法不错 ...
恩,看到了,谢谢!学习中 比我速度多了 您好我下载那个bootload了解压后是一个“M2Arduino” 的文件夹把这个文件夹放到“optiboot”文件夹就可以吗? 安装楼主说的我没有成功,文件放的位置有问题,后来搞定了 楼主16L-8pu的熔丝位设置是什么呢? stig3 发表于 2013-2-25 16:39 static/image/common/back.gif
楼主16L-8pu的熔丝位设置是什么呢?
atmega16.bootloader.low_fuses=0xcf
atmega16.bootloader.high_fuses=0x98