AT89C51芯片燒錄驅(qū)動源程序
以下是C51BOX編程器插件的AT89C51芯片燒錄驅(qū)動源程序:“AT89C51.C”中的內(nèi)容
用戶只需用C51實現(xiàn)芯片的幾個讀寫函數(shù),就可以支持一種新的芯片。
其它庫函數(shù)和通訊協(xié)議代碼都在OBJ中,不用修改。
/*--------------------------------------------------------------------------
AT89C51.C
AT89C51的燒錄驅(qū)動程序
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字節(jié)
{
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字節(jié)
{
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)//讀一個字節(jié)
{
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)//往指定地址寫一個字節(jié)
{
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();
}