Atmel 89

55

FF

8955--5

1E

55

05

AT89LV55

1

65

FF

AT89S8252

1

72

AT89LS8252

1

82

, , . 89 6. 0FFH, , .

MS DOS. Windows , MS DOS . - , .

- , FLASH- 10...15 . , , , . ( ) .

, , " ". ( " "). ( " ") , :

  堠 FLASH 039A = FF ?! 6

, FLASH- ( ) 39 0FFH 6, .


6.2. .

Borland C++


// AT89C51/C52/C1051/C1052 .


#include <stdio.h>

#include <string.h>

#include <graph.h>

#include <dos.h>


#define FALSE 0

#define TRUE -1


//#define PBASE 0x378 // LPT1

//#define PBASE 0x278 // LPT2

//#define PDATA (PBASE+0)

//#define PSTAT (PBASE+1)

//#define PCTRL (PBASE+2)


#define CHIPSIZE 2048 // AT89C1052 FLASH-


#define TCVT (1.19318) //

// 1E6


// ( P3.6; P3.5; P3.4; P3.3).


#define WRITE_DATA 0xe

#define READ_DATA 0xc

#define WRITE_LOCK_1 0xf

#define WRITE_LOCK_2 0x3

#define CHIP_ERASE 0x1

#define READ_SIGNATURE 0x0


typedef unsigned char BYTE;

typedef unsigned int WORD;

typedef unsigned int BOOLEAN;

typedef unsigned long int BIGINT;


BOOLEAN load_data( char *, BYTE *, int * );

BOOLEAN save_data( char *, BYTE *, int );

void erase( BYTE * );

void program( BYTE *, BYTE *, int );

void xread( BYTE *, BYTE *, int );

BOOLEAN verify( BYTE *, BYTE *, int );

BOOLEAN blank( BYTE * );

void signature( BYTE * );

void lock( BYTE *, int );

void reset( BYTE * );

void set_function( BYTE );

void set_data( BYTE );

BYTE get_data( void );

void enable_address( BYTE * );

void disable_address( BYTE * );

void enable_data( BYTE * );

void disable_data( BYTE * );

void enable_RST( BYTE * );

void disable_RST( BYTE * );

void pulse_RST( BYTE*, int );

void pulse_XTAL1( BYTE*, int );

void pulse( BYTE *, int );

void delay( BIGINT );

extern void tinit( void );

extern void tend( void );

extern void tread( void );

extern void disable_traps( void );

extern void enable_traps( void );


WORD pctrl, pdata; // //LPT-

BIGINT tcount = 0L; //



main(argc, argv)

int argc;

char *argv[];

{

FILE *fptr;

int fsize;

BYTE pgmdata[CHIPSIZE], control = 0;

char *pch, fname[20];

WORD far *p_lpt1 = (WORD far *)0x00400008;

WORD far *p_lpt2 = (WORD far *)0x0040000a;


if ((argc > 1) && ((pch = strpbrk( argv[1], "12" )) != NULL)) {

switch (*pch) {

case '1': // LPT1

pdata = *p_lpt1;

pctrl = *p_lpt1 + 2;

break;

case '2': // LPT2

pdata = *p_lpt2;

pctrl = *p_lpt2 + 2;

break;

}

if (pdata == 0) { //

puts( "SPP ." );

exit( 255 );

}

} else

puts(


tinit(); //

disable_traps(); // ctl-C ctl-break


while (TRUE) {

_clearscreen( _GCLEARSCREEN );


puts( " \t\tD\n" );

puts( " \tF" );

puts( " \tG" );

puts( " \t\tH\n" );

puts( ": \t\tI\n" );

puts( " \t\tJ\n" );

puts( " Lock Bit 1\tL" );

puts( " Lock Bit 2\tN\n" );

puts( "\t\t\tX\n\n" );


printf( " : " );

gets( pch );

*pch |= 0x20; //

switch (*pch) {

case 'd': //

erase( &control );

break;

case 'f': //

printf( " : " );

gets( fname );

fsize = CHIPSIZE;

if (load_data( fname, pgmdata, &fsize ))

program( &control, pgmdata, fsize );

else {

_clearscreen( _GCLEARSCREEN );

puts( " ." );

puts( "\n Enter ..." );

gets( pch );

}

break;

case 'g': //

printf( " : " );

gets( fname );

fsize = CHIPSIZE;

if (load_data( fname, pgmdata, &fsize )) {

if (!verify( &control, pgmdata, fsize )) {

puts( "\n Enter ..." );

gets( pch );

}

} else {

_clearscreen( _GCLEARSCREEN );

puts( " ." );

puts( "\n Enter ..." );

gets( pch );

}

break;

case 'h': //

printf( " : " );

gets( fname );

xread( &control, pgmdata, CHIPSIZE );

if (!save_data( fname, pgmdata, CHIPSIZE )) {

_clearscreen( _GCLEARSCREEN );

puts(" .");

puts( "\ Enter ..." );

gets( pch );

}

break;

case 'i': // :

_clearscreen( _GCLEARSCREEN );

if (blank( &control ))

puts( " " );

: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10