📄 双足机器人.lst
字号:
__start:
__text_start:
0032 E5CF LDI R28,0x5F
0033 E0D4 LDI R29,4
0034 BFCD OUT 0x3D,R28
0035 BFDE OUT 0x3E,R29
0036 51C0 SUBI R28,0x10
0037 40D0 SBCI R29,0
0038 EA0A LDI R16,0xAA
0039 8308 STD Y+0,R16
003A 2400 CLR R0
003B E6EF LDI R30,0x6F
003C E0F0 LDI R31,0
003D E010 LDI R17,0
003E 37EB CPI R30,0x7B
003F 07F1 CPC R31,R17
0040 F011 BEQ 0x0043
0041 9201 ST R0,Z+
0042 CFFB RJMP 0x003E
0043 8300 STD Z+0,R16
0044 E5E4 LDI R30,0x54
0045 E0F0 LDI R31,0
0046 E6A0 LDI R26,0x60
0047 E0B0 LDI R27,0
0048 E010 LDI R17,0
0049 36E3 CPI R30,0x63
004A 07F1 CPC R31,R17
004B F021 BEQ 0x0050
004C 95C8 LPM
004D 9631 ADIW R30,1
004E 920D ST R0,X+
004F CFF9 RJMP 0x0049
0050 940E03EF CALL _main
_exit:
0052 CFFF RJMP _exit
FILE: C:\DOCUME~1\eda\桌面\双足机器人.c
(0001) //电机在第一次使用之前,都得先调零,即调用stop()子程序旋转调整螺丝直到其转速为零
(0002) //PD6\7分别控制左、右电机为白线。红黑先分别接电源和地
(0003) //电机转速通过脉冲信号控制,
(0004) //1.5ms停转、1.3ms正转、1.7ms为反转(都为高电平)中间插入20ms的低电平
(0005) //PC3,4控制显示,PC3传送数据,PC4为时钟信号线
(0006) // PC0 1分别为探测光源的左 右端口,
(0007) //创建时间:2005年7月28日19:44~8。10
(0008) #include "iom16v.h"
(0009) #include "macros.h"
(0010) unsigned char turn_state0=0,turn_state1=0,sec,second,mini,minute=0,minisecond,number[12]={0x88,0xbb,0xc1,0x91,0xb2,0x94,0x84,0xb9,0x80,0x90,0x00,0xff};
(0011) unsigned int left,right,zhong,interval;
(0012) void delay_us(unsigned int time)
(0013) {//微秒级延时程序
(0014) do
(0015) {
(0016) time--;
_delay_us:
time --> R16
0053 5001 SUBI R16,1
0054 4010 SBCI R17,0
(0017) }
(0018) while (time>1);
0055 E081 LDI R24,1
0056 E090 LDI R25,0
0057 1780 CP R24,R16
0058 0791 CPC R25,R17
0059 F3C8 BCS 0x0053
005A 9508 RET
_delay_ms:
time --> R20
005B 940E0473 CALL push_gset1
005D 01A8 MOVW R20,R16
(0019) }
(0020)
(0021) void delay_ms(unsigned int time)
(0022) {//毫秒级延时程序
005E C005 RJMP 0x0064
(0023) while(time!=0)
(0024) {
(0025) delay_us(1000);
005F EE08 LDI R16,0xE8
0060 E013 LDI R17,3
0061 DFF1 RCALL _delay_us
(0026) time--;
0062 5041 SUBI R20,1
0063 4050 SBCI R21,0
0064 3040 CPI R20,0
0065 0745 CPC R20,R21
0066 F7C1 BNE 0x005F
0067 940E0476 CALL pop_gset1
0069 9508 RET
_delay_20ms:
time --> R20
006A 940E0473 CALL push_gset1
(0027) }
(0028) }
(0029)
(0030)
(0031) /////////////////小车运动////////////////////////////////////////
(0032) void delay_20ms()//延时20ms,用于插入低电平
(0033) {//毫秒级延时程序
(0034) unsigned char time=20;
006C E144 LDI R20,0x14
006D C004 RJMP 0x0072
(0035) while(time!=0)
(0036) {
(0037) delay_us(126);
006E E70E LDI R16,0x7E
006F E010 LDI R17,0
0070 DFE2 RCALL _delay_us
(0038) time--;
0071 954A DEC R20
0072 2344 TST R20
0073 F7D1 BNE 0x006E
0074 940E0476 CALL pop_gset1
0076 9508 RET
_delay_stop:
time --> R20
0077 940E0473 CALL push_gset1
(0039) }
(0040) }
(0041) void delay_stop()//延时1.5m,用于停转
(0042) {//毫秒级延时程序
(0043) unsigned char time=1;
0079 E041 LDI R20,1
007A C004 RJMP 0x007F
(0044) while(time!=0)
(0045) {
(0046) // delay_us(183);
(0047) delay_us(160);
007B EA00 LDI R16,0xA0
007C E010 LDI R17,0
007D DFD5 RCALL _delay_us
(0048) time--;
007E 954A DEC R20
007F 2344 TST R20
0080 F7D1 BNE 0x007B
0081 940E0476 CALL pop_gset1
0083 9508 RET
_delay_conver:
time --> R20
0084 940E0473 CALL push_gset1
(0049) }
(0050) }
(0051) void delay_conver()//延时0.4ms,用于正反转变换
(0052) {//毫秒级延时程序
(0053) unsigned char time=1;
0086 E041 LDI R20,1
0087 C004 RJMP 0x008C
(0054) while(time!=0)
(0055) {
(0056) delay_us(43);
0088 E20B LDI R16,0x2B
0089 E010 LDI R17,0
008A DFC8 RCALL _delay_us
(0057) time--;
008B 954A DEC R20
008C 2344 TST R20
008D F7D1 BNE 0x0088
008E 940E0476 CALL pop_gset1
0090 9508 RET
_delay_turn:
time --> R20
0091 940E0473 CALL push_gset1
(0058) }
(0059) }
(0060) void delay_turn()//延时0.2ms,用于转向
(0061) {//毫秒级延时程序
(0062) unsigned char time=1;
0093 E041 LDI R20,1
0094 C004 RJMP 0x0099
(0063) while(time!=0)
(0064) {
(0065) delay_us(20);
0095 E104 LDI R16,0x14
0096 E010 LDI R17,0
0097 DFBB RCALL _delay_us
(0066) time--;
0098 954A DEC R20
0099 2344 TST R20
009A F7D1 BNE 0x0095
009B 940E0476 CALL pop_gset1
009D 9508 RET
_delay_run:
time --> R20
009E 940E0473 CALL push_gset1
(0067) }
(0068) }
(0069) void delay_run()//延时1.3m,用于正转
(0070) {//毫秒级延时程序
(0071) unsigned char time=1;
00A0 E041 LDI R20,1
00A1 C004 RJMP 0x00A6
(0072) while(time!=0)
(0073) {
(0074) delay_us(140);
00A2 E80C LDI R16,0x8C
00A3 E010 LDI R17,0
00A4 DFAE RCALL _delay_us
(0075) time--;
00A5 954A DEC R20
00A6 2344 TST R20
00A7 F7D1 BNE 0x00A2
00A8 940E0476 CALL pop_gset1
00AA 9508 RET
_delay_back:
time --> R20
00AB 940E0473 CALL push_gset1
(0076) }
(0077) }
(0078) void delay_back()//延时1.7m,用于反转
(0079) {//毫秒级延时程序
(0080) unsigned char time=1;
00AD E041 LDI R20,1
00AE C004 RJMP 0x00B3
(0081) while(time!=0)
(0082) {
(0083) delay_us(180);
00AF EB04 LDI R16,0xB4
00B0 E010 LDI R17,0
00B1 DFA1 RCALL _delay_us
(0084) time--;
00B2 954A DEC R20
00B3 2344 TST R20
00B4 F7D1 BNE 0x00AF
00B5 940E0476 CALL pop_gset1
00B7 9508 RET
(0085) }
(0086) }
(0087) void stop(void)
(0088) {
(0089) PORTD&=0x3f;
_stop:
00B8 B382 IN R24,0x12
00B9 738F ANDI R24,0x3F
00BA BB82 OUT 0x12,R24
(0090) delay_20ms();
00BB DFAE RCALL _delay_20ms
(0091) PORTD|=0xc0;
00BC B382 IN R24,0x12
00BD 6C80 ORI R24,0xC0
00BE BB82 OUT 0x12,R24
(0092) delay_stop();
00BF DFB7 RCALL _delay_stop
00C0 9508 RET
(0093) }
(0094) void run(void)
(0095) {
(0096) PORTD&=0x3f;
_run:
00C1 B382 IN R24,0x12
00C2 738F ANDI R24,0x3F
00C3 BB82 OUT 0x12,R24
(0097) delay_20ms();
00C4 DFA5 RCALL _delay_20ms
(0098)
(0099) PORTD|=0x80;
00C5 9A97 SBI 0x12,7
(0100) delay_run();
00C6 DFD7 RCALL _delay_run
(0101) PORTD&=0x3f;
00C7 B382 IN R24,0x12
00C8 738F ANDI R24,0x3F
00C9 BB82 OUT 0x12,R24
(0102)
(0103)
(0104) PORTD|=0x40;
00CA 9A96 SBI 0x12,6
(0105) delay_back();
00CB DFDF RCALL _delay_back
(0106) PORTD&=0x3f;
00CC B382 IN R24,0x12
00CD 738F ANDI R24,0x3F
00CE BB82 OUT 0x12,R24
(0107)
(0108)
(0109)
(0110) delay_conver();
00CF DFB4 RCALL _delay_conver
00D0 9508 RET
(0111)
(0112) }
(0113) void run_back(void)
(0114) {
(0115) PORTD&=0x3f;
_run_back:
00D1 B382 IN R24,0x12
00D2 738F ANDI R24,0x3F
00D3 BB82 OUT 0x12,R24
(0116) delay_20ms();
00D4 DF95 RCALL _delay_20ms
(0117)
(0118)
(0119) PORTD|=0x80;
00D5 9A97 SBI 0x12,7
(0120) delay_back();
00D6 DFD4 RCALL _delay_back
(0121) PORTD&=0x3f;
00D7 B382 IN R24,0x12
00D8 738F ANDI R24,0x3F
00D9 BB82 OUT 0x12,R24
(0122)
(0123)
(0124) PORTD|=0x40;
00DA 9A96 SBI 0x12,6
(0125) delay_run();
00DB DFC2 RCALL _delay_run
(0126) PORTD&=0x3f;
00DC B382 IN R24,0x12
00DD 738F ANDI R24,0x3F
00DE BB82 OUT 0x12,R24
(0127)
(0128) delay_conver();
00DF DFA4 RCALL _delay_conver
00E0 9508 RET
(0129) }
(0130) void turn_left(void)
(0131) {
(0132) PORTD&=0x3f;
_turn_left:
00E1 B382 IN R24,0x12
00E2 738F ANDI R24,0x3F
00E3 BB82 OUT 0x12,R24
(0133) delay_20ms();
00E4 DF85 RCALL _delay_20ms
(0134) PORTD|=0x80;
00E5 9A97 SBI 0x12,7
(0135) delay_run();
00E6 DFB7 RCALL _delay_run
(0136) PORTD&=0x3f;
00E7 B382 IN R24,0x12
00E8 738F ANDI R24,0x3F
00E9 BB82 OUT 0x12,R24
00EA 9508 RET
(0137) //delay_turn();
(0138) }
(0139) void turn_right(void)
(0140) {
(0141) PORTD&=0x3f;
_turn_right:
00EB B382 IN R24,0x12
00EC 738F ANDI R24,0x3F
00ED BB82 OUT 0x12,R24
(0142) delay_20ms();
00EE DF7B RCALL _delay_20ms
(0143) PORTD|=0x40;
00EF 9A96 SBI 0x12,6
(0144) delay_run();
00F0 DFAD RCALL _delay_run
(0145) PORTD&=0x3f;
00F1 B382 IN R24,0x12
00F2 738F ANDI R24,0x3F
00F3 BB82 OUT 0x12,R24
00F4 9508 RET
_LeftUp:
time --> R20
00F5 940E0473 CALL push_gset1
00F7 2F40 MOV R20,R16
(0146) //delay_turn();
(0147) }
(0148)
(0149) void LeftUp(unsigned char time)//抬左脚
(0150) {
00F8 C00A RJMP 0x0103
(0151) while(time>1)
(0152) {
(0153) time--;
00F9 954A DEC R20
(0154)
(0155) PORTD&=0x3f;
00FA B382 IN R24,0x12
00FB 738F ANDI R24,0x3F
00FC BB82 OUT 0x12,R24
(0156) delay_20ms();
00FD DF6C RCALL _delay_20ms
(0157)
(0158)
(0159) PORTD|=0x80;
00FE 9A97 SBI 0x12,7
(0160) delay_run();
00FF DF9E RCALL _delay_run
(0161) PORTD&=0x3f;
0100 B382 IN R24,0x12
0101 738F ANDI R24,0x3F
0102 BB82 OUT 0x12,R24
0103 E081 LDI R24,1
0104 1784 CP R24,R20
0105 F398 BCS 0x00F9
0106 940E0476 CALL pop_gset1
0108 9508 RET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -