| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 951 人关注过本帖
标题:求高手帮忙,本人不会汇编,希望有人帮忙把以下汇编程序翻译成C语言,谢谢! ...
只看楼主 加入收藏
heizai23
Rank: 1
等 级:新手上路
帖 子:3
专家分:5
注 册:2010-10-29
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
求高手帮忙,本人不会汇编,希望有人帮忙把以下汇编程序翻译成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.
搜索更多相关主题的帖子: 密码锁 翻译 speaker display C语言 
2011-12-07 10:53
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:14 
回复 楼主 heizai23
打算给多少?

总有那身价贱的人给作业贴回复完整的代码
2011-12-07 11:47
heizai23
Rank: 1
等 级:新手上路
帖 子:3
专家分:5
注 册:2010-10-29
收藏
得分:0 
回复 2楼 embed_xuel
200个币
2011-12-08 15:09
mobilephone
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-1-29
收藏
得分:0 
C51还是AVR?写的很好。用汇编写就是了。
2012-01-29 22:19
快速回复:求高手帮忙,本人不会汇编,希望有人帮忙把以下汇编程序翻译成C语言, ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022454 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved