d[i]=tm[j];
j--;
}
}
//把显示位5-9位的10进制数转换成为16进制数
unsignedintinput(void){
unsignedintdd,dat;
dd=10000;dat=0;
for(i=5;i<10;i++){
dat+=dd*temp;
dd/=10;
}
return(dat);
}
/* 89C51系列CPU编程器接收CPU程序*/
#include
#include
#include
#definee8
#definep9
#definel10
sbitled=P3^2;
sbitp27=P2^7;
sbitp26=P2^6;
sbitp36=P3^6;
sbitp37=P3^7;
sbitrst=P3^3;
sbitale=P3^5;
sbitvpp=P3^4;
bitb_break;
unsignedintadds;
// 13.8mS
voidint_t0(void)interrupt1{
TH0=-100;
b_break=1;
}
voidwait(unsignedcharw){
unsignedintt=w*184;
b_break=0;
TL0=-t%256-1;TH0=-t/256;
while(b_break==0){}
}
voidnop(void){
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
}
unsignedcharcommand(void){
TH0=-100;b_break=0;
while(RI==0){if(b_break==1)return(0);}
RI=0;
return(SBUF);
}
voidearsure(unsignedcharcpu){
switch(cpu){
case1:
//89C51
case2:
rst=p26=1;p27=p36=p37=0;nop();vpp=1;nop();
ale=0;wait(110);ale=1;nop();
break;
case3:
case4:
break;
case5:
case6:
break;
}
}
voidprogram(unsignedcharcpu){
unsignedintbdataadds=0;
unsignedchard;
switch(cpu){
case1:
//89C51
case2:
p36=p37=1;rst=1;
while
(1){
TH0=-100;b_break=0;
while(RI==0){if(b_break==1)return;}
RI=0;
d=SBUF;
//address
P0=adds%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;
case3:
case4:
case5:
case6:
break;
}
}
voidlock(unsignedcharcpu){
unsignedchari;
switch(cpu){
case1:
//89c51
case2:
//lock1
rst=p26=p36=p27=p37=1;nop();
vpp=1;
nop();
ale=0;
// for(i=0;i<6;i++)wait(100);
wait
(1);
ale=1;
nop();
vpp=0;
nop();
//lock2
rst=p26=p27=1;p36=p37=0;nop();
vpp=1;
nop();
ale=0;
// for(i=0;i<6;i++)wait(100);
wait
(1);
ale=1;
nop();
vpp=0;
nop();
//lock3
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();
break;
case3:
case4:
case5:
case6:
break;
}
}
voidmain(void){
unsignedchardisp,flash,temp,cpu;
EA=1;
SCON=0xd8;PCON=0x80;
TMOD=0x21;
TL1=TH1=0xff;TR1=1;
TH0=-100;ET0=TR0=1;
flash=0x80;
while
(1){
temp=command();
switch(temp){
case0:
case1:
//89c51
case2:
//89C52
case3:
//80f51
case4:
//80F52
case5:
//87F51
case6:
cpu=temp;SBUF=temp;break;//87f52
casee:
SBUF=temp;earsure(cpu);break; //erasure
casep:
SBUF=temp;program(cpu);break; //program
casel:
lock(cpu);SBUF=temp;break; //lock
default:
SBUF=temp;break;
}
b_break=0;
if((++disp)>flash){disp=0;led=!
led;}
}
}
//HT1380实时时钟驱动程序
sbitclock_dat=P0^1;
sbitclock_clk=P0^2;
sbitclock_rst=P0^3;
sbita0=ACC^0;
sbita1=ACC^1;
sbita2=ACC^2;
sbita3=ACC^3;
sbita4=ACC^4;
sbita5=ACC^5;
sbita6=ACC^6;
sbita7=ACC^7;
voidclock_out(unsignedchardd){
ACC=dd;
clock_dat=a0;clock_clk=1;clock_clk=0;
clock_dat=a1;clock_clk=1;clock_clk=0;
clock_dat=a2;clock_clk=1;clock_clk=0;
clock_dat=a3;clock_clk=1;clock_clk=0;
clock_dat=a4;clock_clk=1;clock_clk=0;
clock_dat=a5;clock_clk=1;clock_clk=0;
clock_dat=a6;clock_clk=1;clock_clk=0;
clock_dat=a7;clock_clk=1;clock_clk=0;
}
unsignedcharclock_in(void){
clock_dat=1;
a0=clock_dat;
clock_clk=1;clock_clk=0;a1=clock_dat;
clock_clk=1;clock_clk=0;a2=clock_dat;
clock_clk=1;clock_clk=0;a3=clock_dat;
clock_clk=1;clock_clk=0;a4=clock_dat;
clock_clk=1;clock_clk=0;a5=clock_dat;
clock_clk=1;clock_clk=0;a6=clock_dat;
clock_clk=1;clock_clk=0;a7=clock_dat;
return(ACC);
}
unsignedcharread_clock(unsignedcharord){
unsignedchardd=0;
clock_clk=0;
clock_rst=0;
clock_rst=1;
clock_out(ord);
dd=clock_in();
clock_rst=0;
clock_clk=1;
return(dd);
}
voidwrite_clock(unsignedcharord,unsignedchardd){
clock_clk=0;
clock_rst=0;
clock_rst=1;
clock_out(ord);
clock_out(dd);
clock_rst=0;
clock_clk=1;
}
/*单个汉字库字摸提取程序,tc2.0编译*/
#include"stdio.h"
#include"dos.h"
#include"process.h"
#include"string.h"
voidmain(void){
longintnum_bytes,qm,wm;
unsignedchard,i,j,k,a[132],b[132];
unsignedchar*data;
unsignedchar*hz;
staticunsigned chardd[103];
FILE*fp;
if((fp=fopen("hzk16f","rb"))==NULL){
printf("can'topenhzk16\n");
exit
(1);
}
clrscr();
while
(1){
data=(unsignedchar*)malloc(33);
printf("pleaseinput:
\n");
scanf("%s",dd); /*输入一个汉字*/
qm=*dd; /*通过区位码计算其在hzk16f文件中的偏移地址*/
qm=qm-161;
if(qm>87)exit(0);
wm=*(dd+1);
wm=wm-161;
if(wm>94)exit(0);
num_bytes=((long)qm*94+wm)*32;
fseek(fp,num_bytes,SEEK_SET);
fgets(data,33,fp);
for(i=0;i<32;i++)b[i]=*data++;
for(i=0;i<32;i+=2)a[i/2]=b[i];
for(i=0;i<32;i+=2)a[i/2+16]=b[i+1];
for(i=8;i<16;i++)b[i]=a[i];
for(i=8;i<16;i++)a[i]=a[i+8];
for(i=8;i<16;i++)a[i+8]=b[i];
/*转换,hzf16f在电脑的储存格式是以行为字节计算的,一般的lcd都采用以列为字节计算*/
for(k=0;k<32;k+=8){
for(j=0;j<8;j++){
d=0;
for(i=0;i<8;i++){
if(a[i+k]>=0x80){
switch(i){
case0:
d+=1;break;
case1:
d+=2;break;
case2:
d+=4;break;
case3:
d+=8;break;
case4:
d+=0x10;break;
case5:
d+=0x20;break;
case6:
d+=0x40;break;
case7:
d+=0x80;break;
}
}
}
for(i=0;i<8;i++)a[i+k]<<=1;
b[j+k]=d;
}
}
clrscr();
printf("/*%s:
*/\n",dd); /*输出0x00格式的16进制数*/
for(k=0;k<32;k+=8){
for(j=0;j<8;j++)printf("0x%x,",b[j+k]);
printf("\n");
}
getch();
}
}
//按键扫描驱动程序
unsignedcharkey,key_h,kpush;
unsignedintkey_l;
//按键连接到p1.0、p1.1、p1.2
voidint_t0(void)interrupt1{
unsignedchardd,i;
TL0=TL0+30;TH0=0xfb; //800
/* 按键判别 */
if((P1&0x7)==0x7){
if((key_l>30)&&(key_l<800)&&(key_h>30)){
//释放按键,如果之前按键时间少于1秒,读入键值
key=kpush;
}
if((++key_h)>200)key_h=200;
key_l=0;
if(key>=0x80)key=0;
//如果之前的按键为长按1秒,清除键值
}else{
kpush=P1&0x7;
key_l++;
if((key_l>800)&&(key_h>30)){
//如果按键超过1秒,键值加0x80标志长按键
key=kpush|0x80;
key_h=0;
key_l=0;
}
}
}
voidmain(void){
TMOD=0x1;TR0=1;ET0=1;EA=1;
while
(1){
while(!
key){}
switch(key){
case1:
break;
case2:
break;
}
}
//串行驱动led显示,
//一个74hc595位移寄存器驱动三极管驱动led位,
//两个74hc595驱动led段,方式位5位x8段x2=10个数码管
//5分频,每次扫描时间位1.25ms
//定义特殊符号
#definenul0xf
#defineqc0xc
#defineqb0xb
#defineq_0xa
#defineq__0xd
#defineq___0xe
#defineqp0x10
#defineqe0x11
#defineqj0x12
#defineqn0x13
#defineqf0x14
#defineqa0x15
#defineqr0x16
#defineqd0x17
#definequ0x18
#defineql0x19
#defineqh0x1a
#defineqwen0x1b
#defineq