|
楼主 |
发表于 2005-7-18 13:42:06
|
显示全部楼层
ATmaga8 简易并行高压(12V)编程器
已通过对以下芯片恢复熔丝位测试:
Mega32
Mega16
Mega8
Mega48
ATmaga8 简易并行高压(12V)编程器原理电路图:
主控芯片90S4433P改为ATmaga8 PC5连接一支4K7电阻到三极管B极(Q1三极管用9014) R1 1K改为10K
取消S1按键及LED2,将RXD及TXD加接一片MAX202,作为和上位机串行通信。
程序可参考以下现成的AVR熔丝自动恢复器C原程序。
//
// ATmaga8のヒュ〖ズ恃构脱 パラレルプログラマ
//
// MCU:ATmaga8
//
// 2003.9.15 KAWAKAMI Yukio
//
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <stdlib.h>
// 今きこむヒュ〖ズデ〖タ
//#define FUSE_H 0xD9
#define FUSE_H 0xD1 // チップ久殿から EEPROMを瘦割
//#define FUSE_L 0xEF // クロック嘲婶券慷 3×8MHz
//#define FUSE_L 0xE0 // クロック嘲婶掐蜗
#define FUSE_L 0xE3 // クロック柒婶 4MHz
//#define FUSE_L 0xAF // BOD钓材、クロック嘲婶券慷 3×8MHz
#define ERASE_CHIP 0x80 // チップ久殿コマンド
#define WRITE_FUSE 0x40 // ヒュ〖ズ今き哈みコマンド
#define READ_FUSE 0x04 // ヒュ〖ズ粕みだしコマンド
#define LF 10
#define ON 1
#define OFF 0
#define SWITCH 0 // PORTD
#define LED 1
#define LED_ON sbi(PORTD,LED)
#define LED_OFF cbi(PORTD,LED)
#define OE 2 // PORTD
#define OE_H sbi(PORTD,OE)
#define OE_L cbi(PORTD,OE)
#define WR 3
#define WR_H sbi(PORTD,WR)
#define WR_L cbi(PORTD,WR)
#define BS1 4
#define BS1_H sbi(PORTD,BS1)
#define BS1_L cbi(PORTD,BS1)
#define XA0 5
#define XA0_H sbi(PORTD,XA0)
#define XA0_L cbi(PORTD,XA0)
#define XA1 6
#define XA1_H sbi(PORTD,XA1)
#define XA1_L cbi(PORTD,XA1)
#define PAGEL 7
#define PAGEL_H sbi(PORTD,PAGEL)
#define PAGEL_L cbi(PORTD,PAGEL)
#define BS2 2 // PORTC
#define BS2_H sbi(PORTC,BS2)
#define BS2_L cbi(PORTC,BS2)
#define XTAL1 3
#define XTAL1_H sbi(PORTC,XTAL1)
#define XTAL1_L cbi(PORTC,XTAL1)
#define RDY 4
#define RESET 5
#define RESET_H cbi(PORTC,RESET)
#define RESET_L sbi(PORTC,RESET)
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
void wait(void);
void wait0(void);
void set_command(uchar com);
void set_data(uchar data);
uchar read_data(void);
void write_puls(void);
void error(void);
#define NOP asm volatile("nop
"::)
#define WDR asm volatile("wdr
"::)
//*********************************
// メインル〖チン
//*********************************
int main (void) {
uint i;
int t, retry;
outp(0x00, PORTB); // PB5×0 L
outp(0x00, DDRB); // PB5×0 out
outp(0x00, PORTC); // PC5 H, PC4×0 L
outp(0x2C, DDRC); // PC5, PC4×0 out
outp(0x01, PORTD); // PD0 pull up
outp(0xFE, DDRD); // PD7×1 out, PD0 in
outp(0x03, TCCR0); // タイマ〖プリスケ〖ラ 1/64
// 弹瓢箕に3搀爬糖
for (i=0; i<3; i++){
LED_ON;
for (t=0; t<200; t++){
wait();
}
LED_OFF;
for (t=0; t<200; t++){
wait();
}
}
// スイッチ掐蜗略ち
while(inp(PIND)&(1<<SWITCH));
// パラレルプログラミングへの败乖
RESET_L;
for (i=0; i < 10; i++){
XTAL1_H;
NOP;
XTAL1_L;
}
OE_L;
WR_L;
BS1_L;
XA0_L;
XA1_L;
PAGEL_L;
BS2_L;
XTAL1_L;
NOP;
RESET_H;
wait();
wait();
// チップ久殿
set_command(ERASE_CHIP);
write_puls();
wait();
wait();
// ヒュ〖ズ布疤バイト今哈み
for (retry = 0; retry < 8; retry++){
set_command(WRITE_FUSE);
set_data(FUSE_L);
BS1_L;
BS2_L;
write_puls();
wait();
wait();
set_command(READ_FUSE);
BS1_L;
BS2_L;
if (read_data() == FUSE_L) break;
}
if (retry >= 8) error();
wait();
wait();
// ヒュ〖ズ惧疤バイト今哈み
for (retry = 0; retry < 8; retry++){
set_command(WRITE_FUSE);
set_data(FUSE_H);
BS1_H;
BS2_L;
write_puls();
wait();
wait();
set_command(READ_FUSE);
BS1_H;
BS2_H;
if (read_data() == FUSE_H) break;
}
if (retry >= 8) error();
wait();
wait();
// 姜わった
outp(0x00, DDRB);
cbi(DDRC, 0);
cbi(DDRC, 1);
LED_ON;
RESET_L;
outp(0x00, PORTB); // PB5×0 L
cbi(DDRC, 0);
cbi(DDRC, 1);
for(;;);
}
// エラ〖山绩
void error(void){
int t;
outp(0x00, DDRB);
cbi(DDRC, 0);
cbi(DDRC, 1);
LED_ON;
RESET_L;
outp(0x00, PORTB); // PB5×0 L
cbi(DDRC, 0);
cbi(DDRC, 1);
for (;;){
LED_ON;
for (t=0; t<200; t++){
wait();
}
LED_OFF;
for (t=0; t<200; t++){
wait();
}
}
}
// 今哈みパルス券栏
void write_puls(void){
WR_L;
wait0();
WR_H;
while(!(inp(PINC) & (1<<RDY)));
outp(0, DDRB); // デ〖タポ〖ト掐蜗肋年
cbi(DDRC, 0);
cbi(DDRC, 1);
}
// コマンドセット
void set_command(uchar com){
WR_H;
OE_H;
XA1_H;
XA0_L;
BS1_L;
BS2_L;
outp(0xFF, DDRB);
sbi(DDRC, 0);
sbi(DDRC, 1);
outp((com & 0x3F), PORTB);
outp((inp(PORTC) & 0xFC)|((com & 0xC0) >> 6), PORTC);
XTAL1_H;
wait0();
XTAL1_L;
wait0();
}
// 8bitデ〖タセット
void set_data(uchar data){
XA1_L;
XA0_H;
outp(0xFF, DDRB);
sbi(DDRC, 0);
sbi(DDRC, 1);
outp((data & 0x3F), PORTB);
outp((inp(PORTC) & 0xFC)|((data & 0xC0) >> 6), PORTC);
XTAL1_H;
wait0();
XTAL1_L;
wait0();
}
// 8bitデ〖タ粕みだし
uchar read_data(void){
uchar data;
outp(0, DDRB);
cbi(DDRC, 0);
cbi(DDRC, 1);
outp(0xFF, PORTB); // プルアップ
sbi(PORTC, 0);
sbi(PORTC, 1);
OE_L;
wait0();
data = (inp(PINC) & 0x03) << 6;
data |= inp(PINB) & 0x3F;
OE_H;
return data;
}
// 16×32μS箕粗略ち
void wait0(void){
uchar t;
t = inp(TCNT0);
while(inp(TCNT0) == t);
t = inp(TCNT0);
while(inp(TCNT0) == t);
}
// 腆1mS箕粗略ち
void wait(void){
int i;
for (i = 0; i < 32; i++){
wait0();
}
}
简易并行编程器实物图
-----此内容被andy于2005-07-18,18:09:55编辑过 |
|