上个月折腾arduino最小系统,一不小心改错晶振熔丝位,导致一块Atmega8A-PU芯片无法识别,请教度娘得知需要使用高压编程器来恢复熔丝,虽然淘宝上找到有现成的刷写设备,本着折腾精神,百度了相关资料,发现DIY一个也应该不是很困难。然后就是根据资料里面的电路图上淘宝掏了相关电子元件(没办法,小地方,很多东西都买不到,只能网购),修修改改,没想到竟然做出来了,现在把一些制作过程分享一下,首先先上做好的板子如下:
下面说说制作过程,整个制作过程主要参考了以下相关资料
http://jingyan.baidu.com/article/22a299b53e2ab89e19376a05.html
http://mightyohm.com/blog/2008/09/arduino-based-avr-high-voltage-programmer/ (鸟文页面,好像上面百度那个也是翻译这里面的内容,需翻墙浏览,为啥??别问过,我也不知道为啥技术论坛也要翻墙)
制作材料如下:
1、合适大小洞洞板一块
2、1K 电容若干
3、2N3903或2N3904三极管一个
4、开关一个
5、led等一个
6、28脚芯片座一个
7、连接线若干
8、12V直流电供电设备一个(由于高压编程器需要外接12V直流电源,我是用淘宝上掏的一块升压模块接电池实现的)
首先对照下面的电路图把电子元件焊接到洞洞板上
图片中左边的芯片针脚对应arduino UNO,右边的针脚对应的事待恢复的芯片针脚(即28脚芯片座),具体的针脚顺序参照下图
电路接好后,将恢复代码刷写进arduino里,百度知识里面的那位哥们没有把代码文件分享出来,结果在那个鸟文网站找到了代码,为了方便没法翻墙的弟兄们,现将代码分享在这里,方便大家使用
/*
HVFuse - Use High Voltage Programming Mode to Set Fuses on ATmega48/88/168
09/23/08 Jeff Keyzer http://mightyohm.com
The HV programming routines are based on those described in the
ATmega48/88/168 datasheet 2545M-AVR-09/07, pg. 290-297
This program should work for other members of the AVR family, but has only
been verified to work with the ATmega168. If it works for you, please
let me know! http://mightyohm.com/blog/contact/
*/
// Desired fuse configuration
#define HFUSE 0xDF // Default for ATmega48/88/168, for others see
#define LFUSE 0x62 // http://www.engbedded.com/cgi-bin/fc.cgi
// Pin Assignments
#define DATA PORTD // PORTD = Arduino Digital pins 0-7
#define DATAD DDRD // Data direction register for DATA port
#define VCC 8
#define RDY 12 // RDY/!BSY signal from target
#define OE 11
#define WR 10
#define BS1 9
#define XA0 13
#define XA1 18 // Analog inputs 0-5 can be addressed as
#define PAGEL 19 // digital outputs 14-19
#define RST 14 // Output to level shifter for !RESET
#define BS2 16
#define XTAL1 17
#define BUTTON 15 // Run button
void setup() // run once, when the sketch starts
{
// Set up control lines for HV parallel programming
DATA = 0x00; // Clear digital pins 0-7
DATAD = 0xFF; // set digital pins 0-7 as outputs
pinMode(VCC, OUTPUT);
pinMode(RDY, INPUT);
pinMode(OE, OUTPUT);
pinMode(WR, OUTPUT);
pinMode(BS1, OUTPUT);
pinMode(XA0, OUTPUT);
pinMode(XA1, OUTPUT);
pinMode(PAGEL, OUTPUT);
pinMode(RST, OUTPUT); // signal to level shifter for +12V !RESET
pinMode(BS2, OUTPUT);
pinMode(XTAL1, OUTPUT);
pinMode(BUTTON, INPUT);
digitalWrite(BUTTON, HIGH); // turn on pullup resistor
// Initialize output pins as needed
digitalWrite(RST, HIGH); // Level shifter is inverting, this shuts off 12V
}
void loop() // run over and over again
{
while(digitalRead(BUTTON) == HIGH) { // wait until button is pressed
}
// Initialize pins to enter programming mode
digitalWrite(PAGEL, LOW);
digitalWrite(XA1, LOW);
digitalWrite(XA0, LOW);
digitalWrite(BS1, LOW);
digitalWrite(BS2, LOW);
// Enter programming mode
digitalWrite(VCC, HIGH); // Apply VCC to start programming process
digitalWrite(WR, HIGH); // Now we can assert !OE and !WR
digitalWrite(OE, HIGH);
delay(1);
digitalWrite(RST, LOW); // Apply 12V to !RESET thru level shifter
delay(1);
// Now we're in programming mode until RST is set HIGH again
// First we program HFUSE
sendcmd(B01000000); // Send command to enable fuse programming mode
writefuse(HFUSE, true);
// Now we program LFUSE
sendcmd(B01000000);
writefuse(LFUSE, false);
delay(1000); // wait a while to allow button to be released
// Exit programming mode
digitalWrite(RST, HIGH);
// Turn off all outputs
DATA = 0x00;
digitalWrite(OE, LOW);
digitalWrite(WR, LOW);
digitalWrite(PAGEL, LOW);
digitalWrite(XA1, LOW);
digitalWrite(XA0, LOW);
digitalWrite(BS1, LOW);
digitalWrite(BS2, LOW);
digitalWrite(VCC, LOW);
}
void sendcmd(byte command) // Send command to target AVR
{
// Set controls for command mode
digitalWrite(XA1, HIGH);
digitalWrite(XA0, LOW);
digitalWrite(BS1, LOW);
//DATA = B01000000; // Command to load fuse bits
DATA = command;
digitalWrite(XTAL1, HIGH); // pulse XTAL to send command to target
delay(1);
digitalWrite(XTAL1, LOW);
//delay(1);
}
void writefuse(byte fuse, boolean highbyte) // write high or low fuse to AVR
{
// if highbyte = true, then we program HFUSE, otherwise LFUSE
// Enable data loading
digitalWrite(XA1, LOW);
digitalWrite(XA0, HIGH);
delay(1);
// Write fuse
DATA = fuse; // set desired fuse value
digitalWrite(XTAL1, HIGH);
delay(1);
digitalWrite(XTAL1, LOW);
if(highbyte == true)
digitalWrite(BS1, HIGH); // program HFUSE
else
digitalWrite(BS1, LOW);
digitalWrite(WR, LOW);
delay(1);
digitalWrite(WR, HIGH);
delay(100);
}
代码需按照刷写芯片更改
#define HFUSE 0xDF // Default for ATmega48/88/168, for others see
#define LFUSE 0x62 //
以上两行位熔丝位,需根据恢复的芯片来修改,我的芯片是Atmega8A-PU,按照资料里面的修改发现不行,查看了手头上能正常使用的同型号芯片的熔丝位,改成下面的内容后,发现芯片修复正常。
#define HFUSE 0xDC
#define LFUSE 0xA4
刷完代码后,接上洞洞板和12V电源,UNO的L灯会亮,然后按洞洞板上的开关,UNO的灯会先灭再亮,这时芯片应该已经正常修复了,如果芯片还是修复不成功,在确保芯片不是烧毁的问题的情况下,检查熔丝位是否正确。注意,此设备只能起到恢复熔丝位的作用,无法修复烧毁芯片。最后提醒大家焊接洞洞板的时候对每个焊点都要确保焊接到位,不然到时出了问题都不知道是什么问题。
上一篇:atmega48 spi编程代码
下一篇:Atmega48 eeprom调试代码