⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 robot.asm

📁 用89c2051实现可随机编程的小巧机器人的汇编语言源程序
💻 ASM
字号:
	:89c2051 汇编语言源程序

    ljmp 0003h;
    mov p0,#0fh;
    mov p3,#0c7h;
    mov r0,#30h;
    mov r3,#0h;

start: mov p1,#0ffh     ;初始
       clr p1.7         ;第1行
lcall l0;
      setb p1.7;
      clr p1.6        ;第2行
      jnb p1.2,key5;
      jnb p1.1,key6;
      jnb p1.0,key7;
lcall l0;
      setb p1.6;
      clr p1.5        ;第3行
      jnb p1.2,key9;
      jnb p1.1,keya;
      jnb p1.0,keyb;
lcall l0;
      setb p1.5;
      clr p1.4;   第4行  
      jnb p1.2,keyd;
      jnb p1.1,keye;
      jnb p1.0,keyf;
lcall l0;
      ljmp start ;循环

key5:mov a,#1h;
      push p3;
      lcall sound;
      pop p3;
      ljmp start      ;

key6:mov a,#4h;
      push p3;
      lcall sound;
      pop p3;
      ljmp start;

key9:mov a,#2h;
     push p3;
     lcall sound;
     pop p3;
      ljmp start;
key7: lcall l0;    数据写入程序
      cjne a,#0h,ss;
      ljmp start;
    ss:mov @r0,a;
      inc r3;
      push p3;
      lcall sound;
      pop p3;
      cpl p3.5;
      inc r0;
      mov a,#0h;
      lcall l0;
      ljmp start;
keya:mov a,#5h;
     push p3;
     lcall sound;
     pop p3;
      ljmp start;
keyb: ljmp auto;
keye:mov a,#6h;
      push p3;
      lcall sound;
      pop p3;
      ljmp start;
keyd:mov a,#3h;
     push p3;
     lcall sound;
     pop p3;
     ljmp start;
keyf: inc r3;   数据调出程序
      lcall sound;
      mov r0,#2fh;
  run: lcall sound;
       inc r0;
      mov a,@r0;
      djnz r3,run1;
      lcall sound;
      lcall sound;
      lcall sound;
      lcall sound;
      ljmp start;
  run1:   cjne a,#1h,ma;
      mov p3,#0c7h;
      ljmp time;
   ma:cjne a,#2h,mb;
      mov p3,#0fdh;
      ljmp time;
   mb:cjne a,#3h,mc;
      lcall sound;
      ljmp time;
   mc:cjne a,#4h,md;
      mov p3,#0cch;
      ljmp time;
   md:cjne a,#5h,me;
      mov p3,#46h;
      ljmp time;
   me:cjne a,#6h,time;
      mov p3,#6dh;
  time:
      dec r3;
      inc r0;
      mov a,@r0;
      cjne a,#1h,tm1;
      lcall ti1;
       ljmp run;
  tm1:cjne a,#2h,tm2;
      lcall ti1;
        lcall ti1;
          lcall ti1;
        ljmp run;
  tm2:cjne a,#3h,tm3;
      lcall ti1;
         lcall ti1;
            lcall ti1;
              lcall ti1;
                lcall ti1;
      ljmp run;
  tm3:cjne a,#4h,tm4;
         lcall ti1;
           lcall ti1;
             lcall ti1;
               lcall ti1;
                 lcall ti1;
                   lcall ti1;
                     lcall ti1;
                       lcall ti1;
                         lcall ti1;
                           lcall ti1;
      ljmp run;
  tm4:cjne a,#5h,tm5;
          lcall ti1;
           lcall ti1;
             lcall ti1;
               lcall ti1;
                 lcall ti1;
                   lcall ti1;
                     lcall ti1;
                       lcall ti1;
                         lcall ti1;
                           lcall ti1;

         lcall ti1;
           lcall ti1;
             lcall ti1;
               lcall ti1;
                 lcall ti1;
                   lcall ti1;
                     lcall ti1;
                       lcall ti1;
                         lcall ti1;
                           lcall ti1;
         
      ljmp run;
  tm5:  lcall ti1;
           lcall ti1;
             lcall ti1;
               lcall ti1;
                 lcall ti1;
                   lcall ti1;
                     lcall ti1;
                       lcall ti1;
                         lcall ti1;
                           lcall ti1;

         lcall ti1;
           lcall ti1;
             lcall ti1;
               lcall ti1;
                 lcall ti1;
                   lcall ti1;
                     lcall ti1;
                       lcall ti1;
                         lcall ti1;
                           lcall ti1;

         lcall ti1;
           lcall ti1;
             lcall ti1;
               lcall ti1;
                 lcall ti1;
                   lcall ti1;
                     lcall ti1;
                       lcall ti1;
                         lcall ti1;
                           lcall ti1;
     

      ljmp run ;

auto:    自动运行子程序
    lcall test;
    lcall sound;
    lcall walk;
    mov p3,#0fdh;
    lcall ti3;
    mov p3,#0c7h;
    lcall ti10;
    mov p3,#46h;
    lcall ti3;
    mov p3,#0d6h;
    lcall ti3;
    mov p3,#0c7h;
    lcall ti5;
    lcall walk;
    mov p3,#0c7h;
    lcall ti10;
    lcall sound;
    mov p3,#77h;
    lcall ti5;
    mov p3,#0e7h;
    lcall ti5;
    mov p3,#0fdh;
    lcall sound;
    lcall ti5;
    mov p3,#0c7h;
    lcall ti10;
    mov p3,#0dfh;
    lcall ti3;
    lcall sound;
    mov p3,#0fdh;
    lcall ti10;
    mov p3,#0d6h;
    lcall ti3;
    mov p3,#0c7h;
    lcall ti5;
    mov p3,#0c7h;
    lcall ti10;
    mov p3,#46h;
    lcall ti3;
ljmp auto;

keys: mov p1,#0ffh     ;初始(运行时开关检测程序)
      clr p1.7         ;第1行
      lcall l0;
      setb p1.7;
      clr p1.6        ;2行
      jnb p1.3,key_4   ;4键按下
      lcall l0;
      setb p1.6;
      clr p1.5;
      jnb p1.3,key_8   ;8键按下
      lcall l0;
      setb p1.5;
      clr p1.4;
      jnb p1.3,key_c   ;c键按下
      jnb p1.0,key_f;
      lcall l0;
  ret ;循环

key_c:lcall sound;
      mov p3,#46h;
      lcall delay;
      mov p3,#77h;
      lcall delay;
      mov p3,#0fdh;
      lcall delay;
      ljmp keys    ;
key_4:lcall sound;
      mov p3,#0e7h;
      lcall delay;
      mov p3,#46h;
      lcall delay;
      mov p3,#6dh;
      lcall delay;
      mov p3,#0fdh;
      lcall delay;
      mov p3,#0cch;
      lcall delay;
      mov p3,#0fdh;
      lcall delay;
      ljmp keys;
key_8:lcall sound;
      mov p3,#0e7h;
      lcall delay;
      mov p3,#046h;
      lcall delay;
      mov p3,#0cch;
      lcall delay;
      mov p3,#0fdh;
      lcall delay;
      mov p3,#06dh;
      lcall delay;
      mov p3,#0fdh;
      lcall delay;
      ljmp keys;
key_f:lcall sound;
      lcall test;
      ljmp start;

l0:
  mov b,#0ffh;
  l1:nop;
     nop;
   djnz b,l1;
ret;
walk: 走步动作子程序
    mov p3,#6dh; go-1
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-2
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-3
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-4
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-5
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-6
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-7
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-8
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-9
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
    mov p3,#6dh; go-10
    lcall ti1;
    mov p3,#0cch;
    lcall ti1;
   ret;
sound: 鸣叫子程序
    mov r1,#0ffh;
 w4:nop;
    mov p3,#0dfh;
    mov r2,#0ffh;
 w5:nop;
    nop;
    djnz r2,w5;
    mov r2,#0ffh;
 w6:nop;
    nop;
    djnz r2,w6;
    mov r2,#0ffh;
 w7:nop;
    nop;
    djnz r2,w7;
    mov p3,#0c7h;
    nop;
    djnz r1,w4;
  ret;
test: mov p3,#0ffh; 指示灯测试子程序
      lcall ti3;
      mov p3,#11101111b;
      lcall ti3;
      mov p3,#11110111b;
      lcall ti3;
      mov p3,#11010111b;
      lcall ti3;
      mov p3,#11001111b;
      lcall ti3;
    ret;

ti1:  延时子程序
    mov r5,#08fh;
 w0:nop;
    lcall keys;
    nop;
    djnz r5,w0;
 ret;
ti3:
    lcall ti1;
    lcall ti1;
    lcall ti1;
   ret;
ti5:
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
   ret;
ti10:
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    lcall ti1;
    
   ret;
ti30:
    lcall ti10;
    lcall ti10;
    lcall ti10;
   ret;
ti50:
   lcall ti10;    
   lcall ti10; 
   lcall ti10;
   lcall ti10;
   lcall ti10;
ret;
delay:
    mov r6,#1fh;
wa: nop;
    mov r7,#0ffh;
wb: nop;
    mov r4,#0ffh;
wc: nop;
    djnz r4,wc;
    djnz r7,wb;
    djnz r6,wa;
  ret;
end





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -