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

📄 ide_pins_test.asm

📁 8051和8255一起控制硬盘读写的程序
💻 ASM
字号:
.equ    locat, 0x2000           ;Location for this program;82C55 memory locations.equ    port_a, 0xF800.equ    port_b, 0xF801.equ    port_c, 0xF802.equ    port_abc_pgm, 0xF803;routines within paulmon2..equ    cout, 0x0030            ;Send Acc to serial port.equ    cin, 0x0032             ;Get Acc from serial port.equ    phex, 0x0034            ;Print Hex value of Acc.equ    pstr, 0x0038            ;Print string pointed to by DPTR,.equ    upper, 0x0040           ;Convert Acc to uppercase.equ    newline, 0x0048         ;print CR/LF (13 and 10).equ    pint8u, 0x004D          ;print Acc at an integer, 0 to 255.equ    pint16u, 0x0053         ;print DPTR as an integer, 0 to 65535.equ    cin_filter, 0x0062      ;get a character, but look for esc sequences.org    locat.db     0x80,0x3E,0xE0,0xA5     ;signiture bytes.db     35,255,0,0              ;id (35=prog).db     0,0,0,0                 ;prompt code vector.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;reserved.db     0,0,0,0                 ;user defined.db     255,255,255,255         ;length and checksum (255=unused).db     "Test IDE Pins",0       ;max 31 characters, plus the zero.org    locat+64                ;executable code begins herestartup:	mov	sp, #0x40	mov	dptr, #port_abc_pgm	mov	a, #128	movx	@dptr, a		;make all pins output	mov	r7, #0			;r7 has pin # we're testingmain_loop:	mov	a, r7	acall	print_pinout_diagram	mov	a, r7	acall	update_pins	mov	dptr, #msg_anykey	lcall	pstr	lcall	cin_filtermain1:	cjne	a, #27, main2		;ESC to quit	sjmp	quitmain2:	cjne	a, #8, main3		;left arrow back to previous pin	sjmp	previousmain3:next:	inc	r7	cjne	r7, #24, main_loopquit:	ljmp	0previous:	mov	a, r7	jz	main_loop	dec	r7	sjmp	main_loopmsg_anykey:	.db	"Press any key for next pin, or ESC to quit",0;       +-----+;    1  | . . |   2;    3  | . . |   4;    5  | . . |   6;    7  | . . |   8;    9  | . . |  10;   11  | . . |  12;   13  | . . |  14;   15  | . . |  16;   17  | . . |  18;   19  | .   |  20;   21  | . . |  22;   23  | . . |  24;   25  | . . |  26;   27  | . . |  28;   29  | . . |  30;   31  | . . |  32;   33  | . . |  34;   35  | . . |  36;   37  | . . |  38;   39  | . . |  40;       +-----+print_pinout_diagram:	rl	a	rl	a	rl	a	anl	a, #0xF8	mov	r4, a			;r4 has table offset for bit that's set	lcall	clear_screen	mov	dptr, #msg_pin_1	lcall	pstr	mov	a, r4	add	a, #7	mov	dptr, #table	movc	a, @a+dptr	mov	r6, a			;r6 has pin # that is high	acall	print_int	mov	dptr, #msg_pin_2	lcall	pstr	mov	a, r4	add	a, #table & 255	mov	dpl, a	clr	a	addc	a, #table >> 8	mov	dph, a	lcall	pstr	mov	dptr, #msg_pin_3	lcall	pstr	mov	a, r4	add	a, #4	mov	dptr, #table	movc	a, @a+dptr	add	a, #'A'	lcall	cout	mov	a, #'.'	lcall	cout	mov	a, r4	add	a, #5	movc	a, @a+dptr	add	a, #'0'	lcall	cout	lcall	newline	mov	dptr, #diagram_str_0	lcall	pstr	mov	dptr, #diagram_str_1	lcall	pstr	mov	r0, #0print_pinout_loop:	mov	dptr, #diagram_str_0	lcall	pstr	inc	r0	mov	a, r0	acall	print_int	mov	dptr, #diagram_str_2	lcall	pstr	acall	print_pin	mov	a, #' '	lcall	cout	inc	r0	acall	print_pin	mov	dptr, #diagram_str_3	lcall	pstr	mov	a, r0	acall	print_int	lcall	newline	cjne	r0, #40, print_pinout_loop	mov	dptr, #diagram_str_0	lcall	pstr	mov	dptr, #diagram_str_1	lcall	pstr	retdiagram_str_0:	.db	"    ",0diagram_str_1:	.db	"    +-----+",13,10,0diagram_str_2:	.db	"  | ",0diagram_str_3:	.db	" |  ",0msg_pin_1:	.db	13,10,"IDE Pin ",0msg_pin_2:	.db	" (",0msg_pin_3:	.db	") is high, all others low.  Driven via P",0print_pin:	cjne	r0, #20, print_pin_2	mov	a, #' '			;pin 20 always prints as space	ljmp	coutprint_pin_2:	mov	a, r0	mov	b, r6	cjne	a, b, print_pin_3	mov	a, #'@'			;this is the pin that's high	ljmp	coutprint_pin_3:	mov	a, #'.'			;else print only a dot for low	ljmp	coutprint_int:	mov	b, #10	div	ab	jnz	print_int_2	mov	a, #' '	lcall	cout	sjmp	print_int_3print_int_2:	add	a, #'0'	lcall	coutprint_int_3:	mov	a, b	add	a, #'0'	ljmp	cout	; clears the screen and puts the cursor at the top	; left corner on VT100 compatible terminalsclear_screen:	mov	dptr, #msg_clr	lcall	pstr	mov	r0, #20	mov	r1, #0clr_dly:djnz	r1, clr_dly	djnz	r0, clr_dly	retmsg_clr:.db	27, "[H", 27, "[2J", 0update_pins:	mov	b, a			;b has pin # to set (all others clear)	mov	dptr, #table	mov	r1, #0pins_loop:	inc	dptr			;skip name	inc	dptr	inc	dptr	inc	dptr	clr	a	movc	a, @a+dptr		;fetch port offset	inc	dptr	add	a, #2	mov	r0, a			;use r2/r3/r4 for output data	clr	a	movc	a, @a+dptr		;fetch pin offset	inc	dptr	acall	bitmask	mov	r5, a			;keep bitmask in r5	clr	a	movc	a, @a+dptr		;fetch polarity	inc	dptr	mov	r6, a			;r6 has polarity	inc	dptr			;skip IDE pin number	mov	a, r1	cjne	a, b, pin_clearpin_set:	mov	a, r6			;if this is the pin we are supposed to	cpl	acc.0			;set, then invert it's polarity so the	mov	r6, a			;code below will set instead of clearpin_clear:	cjne	r6, #0, pin_inverterpin_no_inverter:	mov	a, r5	cpl	a	mov	r5, a	mov	a, @r0	anl	a, r5			;clear bit if no inverter	mov	@r0, a	sjmp	pin_nextpin_inverter:	mov	a, @r0	orl	a, r5			;set bit if inverter on this signal	mov	@r0, apin_next:	inc	r1	cjne	r1, #24, pins_loop	; now all 24 bits in r2/r3/r4 should 	mov	dptr, #port_a	mov	a, r2	movx	@dptr, a	mov	dptr, #port_b	mov	a, r3	movx	@dptr, a	mov	dptr, #port_c	mov	a, r4	movx	@dptr, a	retspace:	mov	a, #' '	ljmp	coutbitmask:	anl	a, #7	inc	a	movc	a, @a+pc	ret	.db	1,2,4,8,16,32,64,128	.equ	P_A, 0	.equ	P_B, 1	.equ	P_C, 2table:	;	NAME (4 char)	Port/Pin	Invert		IDE Pin		Invert	.db	"D0",0,0,	P_A,0,	 	0,		17	.db	"D1",0,0,	P_A,1,	 	0,		15	.db	"D2",0,0,	P_A,2,	 	0,		13	.db	"D3",0,0,	P_A,3,	 	0,		11	.db	"D4",0,0,	P_A,4,	 	0,		9	.db	"D5",0,0,	P_A,5,	 	0,		7	.db	"D6",0,0,	P_A,6,	 	0,		5	.db	"D7",0,0,	P_A,7,	 	0,		3	.db	"D8",0,0,	P_B,0,	 	0,		4	.db	"D9",0,0,	P_B,1,	 	0,		6	.db	"D10",0,	P_B,2,	 	0,		8	.db	"D11",0,	P_B,3,	 	0,		10	.db	"D12",0,	P_B,4,	 	0,		12	.db	"D13",0,	P_B,5,	 	0,		14	.db	"D14",0,	P_B,6,	 	0,		16	.db	"D15",0,	P_B,7,	 	0,		18	.db	"A0",0,0,	P_C,0,	 	0,		35	.db	"A1",0,0,	P_C,1,	 	0,		33	.db	"A2",0,0,	P_C,2,	 	0,		36	.db	"CS0",0,	P_C,3,	 	1,		37	.db	"CS1",0,	P_C,4,	 	1,		38	.db	"WR",0,0,	P_C,5,	 	1,		23	.db	"RD",0,0,	P_C,6,	 	1,		25	.db	"RST",0,	P_C,7,	 	1,		1

⌨️ 快捷键说明

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