简介:本文提供给大家一个89C51编程器端驱动程序的例子
/* 89C51系列CPU编程器接收CPU程序*/
#包括
#包括
#包括
#define e 8
#定义p 9
#define l 10
sbit led=P3^2;
sbit p27=P2^7;
sbit p26=P2^6;
sbit p36=P3^6;
sbit p37=P3^7;
sbit rst=P3^3;
sbit ale=P3^5;
比特vpp = P3 ^ 4;
b_break位;
unsigned int添加;
//
// 13.8毫秒
void int_t0(void)中断1 {
TH0 = -100;
b_break = 1;
}
无效等待(无符号字符w){
无符号整数t = w * 184;
b_break = 0;
TL0 = -t%256-1; TH0 = -t / 256;
而(b_break == 0){}
}
无效nop(void){
_bud _(); _ nop _(); _ nop _(); _ nop_();
_bud _(); _ nop _(); _ nop _(); _ nop_();
_bud _(); _ nop _(); _ nop _(); _ nop_();
_bud _(); _ nop _(); _ nop _(); _ nop_();
_bud _(); _ nop _(); _ nop _(); _ nop_();
}
无符号字符命令(无效){
TH0=-100;b_break=0;
while (RI==0) {if (b_break==1) return(0);}
RI=0;
return(SBUF);
}
void earsure(unsigned char cpu) {
switch (cpu) {
case 1: //89C51
情况2:rst = p26 = 1; p27 = p36 = p37 = 0; nop(); vpp = 1; nop();
ale = 0;等待(110); ale = 1; nop();
休息;
情况3:
案例4:休息;
情况5:
案例6:休息;
}
}
无效程序(未签名的char cpu){
unsigned int bdata增加= 0;
未签名的字符d;
开关(cpu){
情况1:// 89C51
情况2:
p36 = p37 = 1; rst = 1;
而(1){
TH0 = -100; b_break = 0;
while(RI == 0){if(b_break == 1)return;}
RI=0;
d = SBUF;
//地址
P0 =增加%256;
P2=adds/256;
p27=1;
//data
P1=d;
nop(); //48clcl
//vpp
vpp=1;
nop(); //48clcl
//ale
ale=0;
wait(1);//100uS
ale=1;
nop(); //10uS
vpp=0;
nop(); //48clcl
p27=0;
nop(); //48clcl
P1=0xff;
TH0=-100;b_break=0;
while (d!=P1) {if (b_break==1) return;} //data polling
SBUF=d;
adds++;
}
break;
case 3:
case 4:
case 5:
case 6:break;
}
}
void lock(unsigned char cpu) {
unsigned char i;
switch (cpu) {
case 1: //89c51
case 2:
//lock 1
rst = p26 = p36 = p27 = p37 = 1; nop();
vpp = 1;
NOP();
但= 0;
// for(i = 0; i <6; i ++)wait(100);
等待(1);
a = 1;
NOP();
vpp = 0;
NOP();
//锁定2
rst = p26 = p27 = 1; p36 = p37 = 0; nop();
vpp = 1;
NOP();
但= 0;
// for(i = 0; i <6; i ++)wait(100);
等待(1);
a = 1;
NOP();
vpp = 0;
NOP();
//锁定3
rst=p26=p36=1;p27=p37=0;nop();
vpp=1;
nop();
ale=0;
// for (i=0;i<6;i++) wait(100);
wait(1);
ale=1;
nop();
vpp=0;
nop();
休息;
情况3:
情况4:
情况5:
案例6:休息;
}
}
void main(void){
unsigned char disp,flash,temp,cpu;
EA = 1;
SCON = 0xd8; PCON = 0x80;
TMOD = 0x21;
TL1 = TH1 = 0xff; TR1 = 1;
TH0 = -100; ET0 = TR0 = 1;
flash = 0x80;
而(1){
temp =命令();
开关(温度){
案例0:
情况1:// 89c51
情况2:// 89C52
情况3:// 80f51
case 4: //80F52
case 5: //87F51
case 6:cpu=temp;SBUF=temp;break;//87f52
case e:SBUF=temp;earsure(cpu);break; //erasure
case p:SBUF=temp;program(cpu);break; //program
case l:lock(cpu);SBUF=temp;break; //lock
default:SBUF=temp;break;
}
b_break = 0;
if((++ disp)> flash){disp = 0; led =!led;}
}
}