AT89C51芯片烧录驱动源程序
扫描二维码
随时随地手机看文章
以下是C51BOX编程器插件的AT89C51芯片烧录驱动源程序:“AT89C51.C”中的内容
用户只需用C51实现芯片的几个读写函数,就可以支持一种新的芯片。
其它库函数和通讯协议代码都在OBJ中,不用修改。
/*--------------------------------------------------------------------------
AT89C51.C
AT89C51的烧录驱动程序
Copyright (c) 1999-2003 http://www.c51bbs.com/
All rights reserved.
--------------------------------------------------------------------------*/
#include
#include "Plug3LIB.H"
//-----------------------------------------------------------------------------------------------
#define DATA P1
#define AL P0
#define AH P2
#define P37 P3_7
#define P36 P3_6
#define P27 P2_7
#define P26 P2_6
#define PROG P3_3
#define PSEN P3_4
#define GET12V P3_5
//-----------------------------------------------------------------------------------------------
Byte ReadFID(void)//读工厂ID,1字节
{
Byte ID=0;
PSEN=0;
PROG=1;
DATA=0xFF;
P26=0;P27=0;P36=0;P37=0;
AH=0;AL=0x30;
Delay5us();
ID=DATA;
return ID;
}
//-----------------------------------------------------------------------------------------------
Word ReadID(void)//读芯片ID,2字节
{
Word ID=0;
PSEN=0;
PROG=1;
DATA=0xFF;
P26=0;P27=0;P36=0;P37=0;
AH=0x00;AL=0x31;
Delay5us();
ID=DATA;ID<<=8;
AH=0x00;AL=0x32;
Delay5us();
ID|=DATA;
return ID;
}
//-----------------------------------------------------------------------------------------------
Byte ReadByte(Word address)//读一个字节
{
PSEN=0;
PROG=1;
DATA=0xFF;
P26=0;P27=0;P36=1;P37=1;
AL=address;
AH=address>>8;
Delay5us();
return DATA;
}
//-----------------------------------------------------------------------------------------------
void ChipErase(void)//整片删除
{
PSEN=0;
PROG=0;
GET12V=0;
P26=1;P27=0;P36=0;P37=0;
Delay1ms(10);
PROG=1;
GET12V=1;
}
//-----------------------------------------------------------------------------------------------
void WriteLockBit(Byte No)//写加密位,No是加密位的序号,1/2/3可选
{
PROG=1;
PSEN=0;
DATA=0xFF;
if (No==1) {P26=1;P27=1;P36=1;P37=1;}
if (No==2) {P26=1;P27=1;P36=0;P37=0;}
if (No==3) {P26=1;P27=0;P36=1;P37=0;}
Delay5us();//P2.7 (ENABLE) High to VPP
GET12V=0;
Delay5us();Delay5us();//VPP Setup to PROG Low
PROG=0;
Delay5us();//PROG Width
PROG=1;
Delay5us();Delay5us();//VPP Hold after PROG
GET12V=1;
Delay1ms(2);
}
//-----------------------------------------------------------------------------------------------
void ByteProgram(Word address,Byte ch)//往指定地址写一个字节
{
PROG=1;
PSEN=0;
P26=0;P27=1;P36=1;P37=1;
Delay5us();//P2.7 (ENABLE) High to VPP
AL=address;
AH=(address>>8)|0x80;//或0x80是为了保证P27仍为高
DATA=ch;
GET12V=0;
Delay5us();Delay5us();//VPP Setup to PROG Low
PROG=0;
Delay5us();//PROG Width
PROG=1;
Delay5us();Delay5us();//VPP Hold after PROG
GET12V=1;
DATA=0xFF;
while(ReadByte(address)!=ch);
}
//-----------------------------------------------------------------------------------------------
void main(void)
{
McuIni();
Protocol();
}