极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 90850|回复: 35

Atmega16L-8PU搭建最小系统

[复制链接]
发表于 2012-12-27 22:35:25 | 显示全部楼层 |阅读模式
本帖最后由 绿林网页 于 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 图有些网友没看到,特提上来

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2012-12-28 14:38:10 | 显示全部楼层
本帖最后由 Ansifa 于 2012-12-28 14:39 编辑

{:soso_e120:}可以代替mega168,不错!其实图上面所有电容拆掉都能正常工作,只剩一个晶振,可以试试哦
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-28 23:27:19 | 显示全部楼层
IO分析不清楚了,谁能帮我?

试验一:
芯片只接晶振和电容,别的什么都不接,可读到如下数据?

  1. void setup()
  2. {
  3.   Serial.begin(9600);
  4.   Serial.println("begin");
  5. }

  6. void loop()
  7. {
  8.   for(int i=0;i<40;i++){
  9.     Serial.print(i);
  10.     Serial.print("=");
  11.     Serial.print(analogRead(i));
  12.     Serial.print("  ");
  13.   }  
  14.   Serial.println();
  15.   delay(500);
  16. }
复制代码


0=328  1=332  2=404  3=386  4=339  5=385  6=376  7=368  8=319  9=333  10=386  11=385  12=361  13=345  14=351  15=380  16=368  17=360  18=348  19=342  20=361  21=361  22=373  23=365  24=354  25=323  26=339  27=364  28=357  29=365  30=350  31=340  32=361  33=350  34=366  35=351  36=345  37=336  38=347  39=362  
0=377  1=348  2=370  3=376  4=392  5=370  6=376  7=389  8=371  9=339  10=369  11=363  12=396  13=378  14=356  15=364  16=374  17=392  18=370  19=363  20=356  21=362  22=382  23=374  24=394  25=362  26=341  27=353  28=360  29=385  30=371  31=366  32=333  33=346  34=375  35=362  36=372  37=356  38=334  39=360  
0=417  1=400  2=345  3=378  4=440  5=400  6=355  7=420  8=407  9=343  10=336  11=339  12=436  13=423  14=383  15=362  16=330  17=446  18=403  19=394  20=374  21=348  22=370  23=387  24=458  25=410  26=383  27=345  28=344  29=421  30=397  31=401  32=354  33=302  34=359  35=370  36=413  37=386  38=362  39=346  
0=397  1=475  2=401  3=330  4=444  5=430  6=384  7=398  8=392  9=438  10=401  11=300  12=394  13=417  14=451  15=405  16=318  17=343  18=397  19=422  20=389  21=389  22=375  23=352  24=434  25=405  26=443  27=390  28=342  29=352  30=384  31=423  32=404  33=381  34=359  35=338  36=415  37=394  38=413  39=381  
0=286  1=465  2=443  3=377  4=395  5=418  6=442  7=403  8=336  9=477  10=449  11=399  12=360  13=357  14=456  15=434  16=405  17=369  18=337  19=414  20=405  21=426  22=403  23=380  24=316  25=362  26=436  27=411  28=406  29=368  30=331  31=401  32=404  33=446  34=398  35=362  36=354  37=379  38=427  39=403  
0=366  1=357  2=415  3=449  4=389  5=380  6=461  7=418  8=302  9=430  10=408  11=464  12=416  13=335  14=382  15=416  16=480  17=411  18=377  19=376  20=381  21=436  22=410  23=419  24=374  25=311  26=363  27=386  28=438  29=402  30=374  31=362  32=354  33=449  34=406  35=408  36=377  37=333  38=387  39=395  
0=466  1=375  2=353  3=461  4=435  5=361  6=430  7=406  8=410  9=348  10=334  11=440  12=443  13=415  14=382  15=347  16=459  17=423  18=417  19=384  20=363  21=372  22=399  23=430  24=422  25=402  26=356  27=333  28=421  29=405  30=425  31=391  32=318  33=353  34=379  35=425  36=397  37=379  38=359  39=354  
0=504  1=426  2=342  3=410  4=425  5=431  6=384  7=381  8=483  9=407  10=306  11=372  12=389  13=473  14=426  15=371  16=334  17=390  18=439  19=397  20=391  21=383  22=347  23=405  24=413  25=470  26=413  27=365  28=345  29=381  30=438  31=410  32=403  33=364  34=324  35=409  36=392  37=425  38=391  39=359  
0=399  1=440  2=427  3=371  4=383  5=464  6=420  7=359  8=458  9=423  10=420  11=371  12=324  13=435  14=442  15=426  16=373  17=318  18=384  19=398  20=416  21=394  22=388  23=370  24=351  25=446  26=418  27=425  28=377  29=331  30=386  31=397  32=467  33=406  34=376  35=360  36=366  37=426  38=402  39=401  
0=346  1=377  2=474  3=418  4=338  5=449  6=427  7=399  8=364  9=381  10=464  11=440  12=355  13=361  14=390  15=448  16=418  17=381  18=371  19=364  20=425  21=405  22=421  23=398  24=330  25=337  26=375  27=436  28=405  29=387  30=363  31=356  32=455  33=405  34=421  35=385  36=344  37=366  38=385  39=420  
0=409  1=300  2=423  3=428  4=402  5=379  6=399  7=427  8=397  9=322  10=427  11=422  12=445  13=393  14=324  15=395  16=437  17=448  18=399  19=369  20=372  21=394  22=434  23=410  24=427  25=364  26=313  27=394  28=398  29=437  30=397  31=366  32=328  33=373  34=431  35=398  36=392  37=368  38=333  39=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)


  1. void setup()
  2. {
  3.   Serial.begin(9600);
  4.   Serial.println("begin");
  5. }

  6. void loop()
  7. {
  8.     int n = analogRead(0));
  9.     Serial.println(n);
  10.   delay(500);
  11. }
复制代码



实验三:
将所有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无反应


  1. void setup()
  2. {

  3.   for(int i=0;i<40;i++){
  4.     pinMode(i,OUTPUT);
  5.   }

  6. }

  7. void loop()
  8. {
  9.   for(int i=0;i<40;i++){
  10.     digitalWrite(i,HIGH);
  11.     delay(50);
  12.     digitalWrite(i,LOW);
  13.     delay(50);
  14.   }
  15. }
复制代码


最终得出接论如图:
如果不对,请大叫纠正,并且哪位能解释 24,25,26,27 是怎么回事




其他补充:
1、配置文件中 atmega16.build.f_cpu=12000000L 配置的12M,实际晶振上的16M的,可以启动,但是串口通讯全是乱码,将配置修改为 atmega16.build.f_cpu=16000000L 后,一切正常

2、Ansifa 说的没错,整个电路只留下晶振可正常工作,去掉晶振就不能工作啦



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2012-12-29 00:41:02 | 显示全部楼层
本帖最后由 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配合设置)

  1. /*
  2.   pins_arduino.h - Pin definition functions for Arduino
  3.   Part of Arduino - [url]http://www.arduino.cc/[/url]

  4.   Copyright (c) 2007 David A. Mellis

  5.   This library is free software; you can redistribute it and/or
  6.   modify it under the terms of the GNU Lesser General Public
  7.   License as published by the Free Software Foundation; either
  8.   version 2.1 of the License, or (at your option) any later version.

  9.   This library is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.   Lesser General Public License for more details.

  13.   You should have received a copy of the GNU Lesser General
  14.   Public License along with this library; if not, write to the
  15.   Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16.   Boston, MA  02111-1307  USA

  17.   $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
  18. */

  19. #ifndef Pins_Arduino_h
  20. #define Pins_Arduino_h

  21. #include <avr/pgmspace.h>

  22. #define NUM_DIGITAL_PINS            20 //定义20个数字脚
  23. #define NUM_ANALOG_INPUTS           6//定义6个模拟
  24. #define analogInputToDigitalPin(p)  ((p < 6) ? (p) + 14 : -1)

  25. //下面几行是PWM


  26. #if defined(__AVR_ATmega8__)
  27. #define digitalPinHasPWM(p)         ((p) == 9 || (p) == 10 || (p) == 11)
  28. #else
  29. #define digitalPinHasPWM(p)         ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
  30. #endif
  31. //下面是一些特殊复用功能的定义
  32. static const uint8_t SS   = 10;
  33. static const uint8_t MOSI = 11;
  34. static const uint8_t MISO = 12;
  35. static const uint8_t SCK  = 13;

  36. static const uint8_t SDA = 18;
  37. static const uint8_t SCL = 19;
  38. static const uint8_t LED_BUILTIN = 13;

  39. static const uint8_t A0 = 14;
  40. static const uint8_t A1 = 15;
  41. static const uint8_t A2 = 16;
  42. static const uint8_t A3 = 17;
  43. static const uint8_t A4 = 18;
  44. static const uint8_t A5 = 19;
  45. static const uint8_t A6 = 20;
  46. static const uint8_t A7 = 21;

  47. #define digitalPinToPCICR(p)    (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
  48. #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
  49. #define digitalPinToPCMSK(p)    (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
  50. #define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))

  51. #ifdef ARDUINO_MAIN

  52. // On the Arduino board, digital pins are also used
  53. // for the analog output (software PWM).  Analog input
  54. // pins are a separate set.

  55. // ATMEL ATMEGA8 & 168 / ARDUINO
  56. //
  57. //                  +-\/-+
  58. //            PC6  1|    |28  PC5 (AI 5)
  59. //      (D 0) PD0  2|    |27  PC4 (AI 4)
  60. //      (D 1) PD1  3|    |26  PC3 (AI 3)
  61. //      (D 2) PD2  4|    |25  PC2 (AI 2)
  62. // PWM+ (D 3) PD3  5|    |24  PC1 (AI 1)
  63. //      (D 4) PD4  6|    |23  PC0 (AI 0)
  64. //            VCC  7|    |22  GND
  65. //            GND  8|    |21  AREF
  66. //            PB6  9|    |20  AVCC
  67. //            PB7 10|    |19  PB5 (D 13)
  68. // PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
  69. // PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
  70. //      (D 7) PD7 13|    |16  PB2 (D 10) PWM
  71. //      (D 8) PB0 14|    |15  PB1 (D 9) PWM
  72. //                  +----+
  73. //
  74. // (PWM+ indicates the additional PWM pins on the ATmega168.)

  75. // ATMEL ATMEGA1280 / ARDUINO
  76. //
  77. // 0-7 PE0-PE7   works
  78. // 8-13 PB0-PB5  works
  79. // 14-21 PA0-PA7 works
  80. // 22-29 PH0-PH7 works
  81. // 30-35 PG5-PG0 works
  82. // 36-43 PC7-PC0 works
  83. // 44-51 PJ7-PJ0 works
  84. // 52-59 PL7-PL0 works
  85. // 60-67 PD7-PD0 works
  86. // A0-A7 PF0-PF7
  87. // A8-A15 PK0-PK7


  88. // these arrays map port names (e.g. port B) to the
  89. // appropriate addresses for various functions (e.g. reading
  90. // and writing)
  91. //模式定义
  92. const uint16_t PROGMEM port_to_mode_PGM[] = {
  93.         NOT_A_PORT,
  94.         NOT_A_PORT,
  95.         (uint16_t) &DDRB,
  96.         (uint16_t) &DDRC,
  97.         (uint16_t) &DDRD,
  98. };
  99. //输出定义
  100. const uint16_t PROGMEM port_to_output_PGM[] = {
  101.         NOT_A_PORT,
  102.         NOT_A_PORT,
  103.         (uint16_t) &PORTB,
  104.         (uint16_t) &PORTC,
  105.         (uint16_t) &PORTD,
  106. };
  107. //输入定义
  108. const uint16_t PROGMEM port_to_input_PGM[] = {
  109.         NOT_A_PORT,
  110.         NOT_A_PORT,
  111.         (uint16_t) &PINB,
  112.         (uint16_t) &PINC,
  113.         (uint16_t) &PIND,
  114. };

  115. //下面这两组数组定义要匹配对应来定义引脚,按0到最大定义引脚上限数顺序,现在是0~20
  116. //举例说明:下面的0脚被定义为PD0(PD _BV(0))
  117. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  118.         PD, /* 0 */
  119.         PD,
  120.         PD,
  121.         PD,
  122.         PD,
  123.         PD,
  124.         PD,
  125.         PD,
  126.         PB, /* 8 */
  127.         PB,
  128.         PB,
  129.         PB,
  130.         PB,
  131.         PB,
  132.         PC, /* 14 */
  133.         PC,
  134.         PC,
  135.         PC,
  136.         PC,
  137.         PC,
  138. };

  139. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  140.         _BV(0), /* 0, port D */
  141.         _BV(1),
  142.         _BV(2),
  143.         _BV(3),
  144.         _BV(4),
  145.         _BV(5),
  146.         _BV(6),
  147.         _BV(7),
  148.         _BV(0), /* 8, port B */
  149.         _BV(1),
  150.         _BV(2),
  151.         _BV(3),
  152.         _BV(4),
  153.         _BV(5),
  154.         _BV(0), /* 14, port C */
  155.         _BV(1),
  156.         _BV(2),
  157.         _BV(3),
  158.         _BV(4),
  159.         _BV(5),
  160. };


  161. //下面是TIMER的设置

  162. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  163.         NOT_ON_TIMER, /* 0 - port D */
  164.         NOT_ON_TIMER,
  165.         NOT_ON_TIMER,
  166.         // on the ATmega168, digital pin 3 has hardware pwm
  167. #if defined(__AVR_ATmega8__)
  168.         NOT_ON_TIMER,
  169. #else
  170.         TIMER2B,
  171. #endif
  172.         NOT_ON_TIMER,
  173.         // on the ATmega168, digital pins 5 and 6 have hardware pwm
  174. #if defined(__AVR_ATmega8__)
  175.         NOT_ON_TIMER,
  176.         NOT_ON_TIMER,
  177. #else
  178.         TIMER0B,
  179.         TIMER0A,
  180. #endif
  181.         NOT_ON_TIMER,
  182.         NOT_ON_TIMER, /* 8 - port B */
  183.         TIMER1A,
  184.         TIMER1B,
  185. #if defined(__AVR_ATmega8__)
  186.         TIMER2,
  187. #else
  188.         TIMER2A,
  189. #endif
  190.         NOT_ON_TIMER,
  191.         NOT_ON_TIMER,
  192.         NOT_ON_TIMER,
  193.         NOT_ON_TIMER, /* 14 - port C */
  194.         NOT_ON_TIMER,
  195.         NOT_ON_TIMER,
  196.         NOT_ON_TIMER,
  197.         NOT_ON_TIMER,
  198. };

  199. #endif

  200. #endif
复制代码


我说的不一定准确,也是瞎搞,仅供参考。更复杂的芯片你需要参考MEGA的参数设定,如果是xmega的话核心库也要改动
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-29 13:00:13 | 显示全部楼层
本帖最后由 绿林网页 于 2012-12-29 13:02 编辑
mxx_xm 发表于 2012-12-29 00:41
另外帮你补充一点,事实上引脚是可以定义的,在1.0以上版本的boards.txt文件里每种板子有类似atmega8.build ...


膜拜!高手呀!学习了!顺便把资料贴一点上来




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2012-12-29 20:10:43 | 显示全部楼层
阅,不错!
回复 支持 反对

使用道具 举报

发表于 2012-12-29 21:22:38 | 显示全部楼层
其实论坛已经有人发过对应引脚了,lz还重新测一遍,真不容易。不过这倒是一篇不错的学习帖
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-29 22:19:27 | 显示全部楼层
wasdpkj 发表于 2012-12-29 21:22
其实论坛已经有人发过对应引脚了,lz还重新测一遍,真不容易。不过这倒是一篇不错的学习帖

我没有搜到Atmega16L 的呀,Atmega8的倒是很多
笨笨的学习了哈
回复 支持 反对

使用道具 举报

发表于 2012-12-29 22:21:43 | 显示全部楼层
绿林网页 发表于 2012-12-29 22:19
我没有搜到Atmega16L 的呀,Atmega8的倒是很多
笨笨的学习了哈

比如:http://www.geek-workshop.com/for ... thread&tid=1856

不过此帖的引脚检测办法不错,聪明人
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-29 22:26:03 | 显示全部楼层
wasdpkj 发表于 2012-12-29 22:21
比如:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=1856

不过此帖的引脚检测办法不错 ...

恩,看到了,谢谢!学习中
回复 支持 反对

使用道具 举报

发表于 2013-1-22 01:29:56 | 显示全部楼层
比我速度多了
回复 支持 反对

使用道具 举报

发表于 2013-2-1 23:56:26 | 显示全部楼层
您好  我下载那个bootload了  解压后是一个“M2Arduino” 的文件夹  把这个文件夹放到“optiboot”文件夹就可以吗?
回复 支持 反对

使用道具 举报

发表于 2013-2-3 11:40:46 | 显示全部楼层
安装楼主说的我没有成功,文件放的位置有问题,后来搞定了
回复 支持 反对

使用道具 举报

发表于 2013-2-25 16:39:43 | 显示全部楼层
楼主16L-8pu的熔丝位设置是什么呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-2-28 07:57:55 | 显示全部楼层
stig3 发表于 2013-2-25 16:39
楼主16L-8pu的熔丝位设置是什么呢?

atmega16.bootloader.low_fuses=0xcf
atmega16.bootloader.high_fuses=0x98
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 18:04 , Processed in 0.047472 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表