求高手帮忙,本人不会汇编,希望有人帮忙把以下汇编程序翻译成C语言,谢谢!
电子密码锁程序:en bit p3.0;
rw bit p3.1;
rs bit p3.2;
display equ p0;
speaker bit p1.0;
led bit p1.2;
open bit p1.1;
returnbit bit 20h.1;
ORG 0000h;
LJMP start;
ORG 000bh;
LJMP intermit_t0;
ORG 001bh;
LJMP intermit_t1;
ORG 0030h;
start:
MOV sp,#60h;
lcall sys_initialization;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;主程序
main0: lcall strat_display;
main:
MOV 52h,#0; 52h判断输入错误次数储存地址
setb led;
setb tr0;
lcall key;
cjne a,#'A',next1;
LJMP set_password;
next1: cjne a,#'B',next2;
LJMP input_password;
next2: ajmp main;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;系统初始化
sys_initialization:
clr led;
clr open;
clr speaker;
MOV 34h,#'1';
MOV 35h,#'2';
MOV 36h,#'3';
MOV 37h,#'4';
MOV 38h,#'5';
MOV 39h,#'6';
;存放初始密码
MOV r7,#12;
MOV r0,#40h;
loop: MOV @r0,#10h;
inc r0;
djnz r7,loop;
;密码键值存放区清零完毕
lcall delay0_1s;
MOV p0,#03h;
call write_instruction; 液晶软复位
MOV p0,#01h;
call write_instruction;
MOV p0,#3fh;
call write_instruction;
MOV p0,#0fh;
call write_instruction;
MOV p0,#06h;
call write_instruction;
;液晶初始化完毕
MOV r4,#10;
MOV tmod,#11h;
MOV th0,#3ch;
MOV tl0,#0b0h;
setb ea;
setb et0;
;定时器T0,0.5S定时中断初始化完毕
ret;
;系统初始化完毕
;;;;;;;;;;;;;;;;;;;;;;中断服务程序
intermit_t0:
push acc;
push psw;
MOV th0,#3ch;
MOV tl0,#0b0h;
djnz r4,return;
cpl led;
MOV r4,#10;
return: pop psw;
pop acc;
reti;
intermit_t1:
push acc;
push psw;
MOV th1,#9eh;
MOV tl1,#58h;
djnz r4,return_t1;
cpl led;
cpl speaker;
MOV r4,#10;
return_t1:pop psw;
pop acc;
reti;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;键盘扫描
key: call ks;
jnz k1;
jmp key;
k1:
call delay;
call ks;
jnz k2;
jmp key;
k2:
clr tr0;
clr led;
MOV r2,#0feh;
MOV r6,#00h;
k3: MOV a,r2;
MOV p2,a;
MOV a,p2;
jb acc.4,l1;
MOV a,#0;
LJMP lk;
l1: jb acc.5,l2;
MOV a,#4;
LJMP lk;
l2: jb acc.6,l3;
MOV a,#8;
LJMP lk;
l3: jb acc.7,next_key;
MOV a,#12;
lk: add a,r6;
MOV r6,a;
k4: call ks;
jnz k4;
MOV a,r6;
MOV dptr,#table0;
MOVc a,@a+dptr;
MOV 50h,a; 查表取值存入50h,保护键值
ret;
next_key: inc r6;
MOV a,r2;
jnb acc.7,key;
rl a;
MOV r2,a;
jmp k3;
;;;;;;;;;;;;;;;;;;;;;;;;;;
ks: MOV p2,#0f0h;
MOV a,p2;
xrl a,#0f0h;
ret;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;设置密码程序
set_password:
call clear_display;
MOV dptr,#table4;
call input_hint;
MOV r0,#40h;
call password;
jbc returnbit,set_password;
;先输入原密码完毕
MOV r5,#6;
MOV r0,#40h;
MOV r1,#34h;
input_compere:
MOV a,@r0;
xrl a,@r1;
jnz input_error;
inc r0;
inc r1;
nop;
nop;
djnz r5,input_compere;
;验证输入密码完毕
jmp set_password0;
input_error:
setb speaker;
setb led;
call clear_display;
MOV dptr,#table5;
call input_hint;
call delay1_5s;
clr speaker;
clr led;
inc 52h;
MOV a,52h;
cjne a,#3,set_password;
sjmp $;
;输入密码错误次数超过3次,锁死
set_password0:
call clear_display;
MOV dptr,#table2;
call input_hint;
MOV r0,#40h;
call password;
jbc returnbit,set_password;
;第一次输入新密码完毕
call clear_display;
MOV dptr,#table3;
call input_hint;
call delay1_5s;
;显示再次输入新密码完毕
call clear_display;
MOV dptr,#table4;
call input_hint;
MOV r0,#46h;
call password;
jbc returnbit,set_password;
;第二次输入新密码完毕
MOV r5,#6;
MOV r0,#40h;
MOV r1,#46h;
set_compere:
MOV a,@r0;
xrl a,@r1;
jnz set_error;
inc r0;
inc r1;
djnz r5,set_compere;
MOV 34h,40h;
MOV 35h,41h;
MOV 36h,42h;
MOV 37h,43h;
MOV 38h,44h;
MOV 39h,45h;
;存入新密码完毕
jmp main0;
;设置新密码成功,返回主程序
set_error:
setb speaker;
setb led;
call clear_display;
MOV dptr,#table5;
call input_hint;
call delay1_5s;
clr speaker;
clr led;
LJMP set_password0;
;前后两次输入新密码不一致,返回重设
;;;;;;;;;;;;;;;;;;输入密码开锁程序
input_password:
call clear_display;
MOV dptr,#table4;
call input_hint;
MOV r0,#40h;
call password;
jbc returnbit,input_password;
;输入原密码完毕
MOV r5,#6;
MOV r0,#40h;
MOV r1,#34h;
input_compere0:
MOV a,@r0;
xrl a,@r1;
jnz input_error22;
inc r0;
inc r1;
nop;
nop;
djnz r5,input_compere0;
;验证输入密码完毕
jmp display_right;
input_error22:
setb speaker;
setb led;
call clear_display;
MOV dptr,#table5;
call input_hint;
call delay1_5s;
clr speaker;
clr led;
inc 52h;
MOV a,52h;
cjne a,#3,input_password;
sjmp $;
;输入密码错误超过3次,锁死
display_right:
call clear_display;
MOV dptr,#table6;
call input_hint;
;显示输入密码正确提示完毕
setb open; 开锁
next_key1:call key;
nop;
nop;
cjne a,#'F',next_key1;
clr open; 按下关锁键,关锁
jmp main0; 返回主程序
;;;;;;;;;;;;;;;;;;;;;;;;
strat_display:
MOV p0,#80h;
call write_instruction;
MOV dptr,#table1;
call input_hint;
MOV p0,#0c0h;
call write_instruction;
MOV dptr,#table11;
call input_hint;
ret;
clear_display:
MOV display,#01h;
call write_instruction;
MOV p0,#06h;
call write_instruction;
ret;
input_hint:
MOV r5,#16;
MOV a,#00h;
all_or_not:
MOVc a,@a+dptr;
MOV display,a;
call writedata;
inc dptr;
clr a;
nop;
nop;
djnz r5,all_or_not;
ret;
password:
MOV r5,#6;
MOV r1,#0c0h;
MOV a,r1;
MOV p0,a;
call write_instruction;
loop1: call key;
nop;
nop;
cjne a,#'C',next_to;
setb returnbit;
jmp endt;
next_to:
MOV a,50h;
MOV @r0,a;
MOV display,#'*';a;
call writedata;
inc r1;
inc r0;
djnz r5,loop1;
endt: ret;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;写数据指令
writedata: SETB rs;
CLR rw;
clr en;
setb en;
nop;
nop;
clr en;
call delay;
ret;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;写指令
write_instruction:
CLR rs;
CLR rw;
clr en;
setb en;
nop;
nop;
clr en;
call delay;
ret;
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;延时程序
delay1_5s: push 07h;
push 02h;
push 03h;
MOV r7,#15;
del22s: MOV r3,#0;
del11s: MOV r2,#0;
djnz r2,$;
djnz r3,del11s;
djnz r7,del22s;
pop 03h;
pop 02h;
pop 07h;
ret;
delay0_1s: push 02h;
push 03h;
MOV r3,#0;
del21s: MOV r2,#0;
nop;
nop;
djnz r2,$;
djnz r3,del21s;
pop 03h;
pop 02h;
ret;
delay: push 07h;
push 06h;
MOV r7,#10;
d1: MOV r6,#248;
nop
nop
djnz r6,$;
djnz r7,d1;
pop 06h;
pop 07h;
ret
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
table0: db 'C','B','0','A';
db 'D','9','8','7';
db 'E','6','5','4';
db 'F','3','2','1';
table1: db 'PASSWORD: A SET ';
table11: db ' B OPEN';
table2: db 'SET PASSWORD: ';
table3: db 'INPUT AGAIN! ';
table4: db 'INPUT PASSWROD: ';
table5: db 'PASSWORD ERROR! ';
table6: db 'PASSWORD OK!!! ';
;;;;;;;;;;;;;;;;;;;;;;;;;;
end
本文来自:proteus仿真论坛(http://proteus.),详细出处参考:http://proteus.