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

📄 datalog.asm

📁 proteus 仿真实例
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;--------------------------------------------------------------------
ATA_Reg8_Read
	btfss	PORTC, 5	; Wait until ready
	bra	ATA_Reg8_Read
	andlw	B'00011111'	; Set address
	movwf	PORTC
	bcf	LATE, 0		; DIOR low
	nop			; Wait
	nop
	movf	PORTB, W	; Get data
	movwf	TMP1
	bsf	LATE, 0		; DIOR high
	return

; +-----------------------------------+
; | PORTC 4-0 to ATA register - Read  |
; +------+----------------------------+
; | Addr | Register                   |
; +------+----------------------------+
; | 0x0E | Alternate status           |
; | 0x0F | Drive address              |
; | 0x10 | Data (16 bit reg)          |
; | 0x11 | Features                   |
; | 0x12 | Sector count               |
; | 0x13 | LBA 0-7                    |
; | 0x14 | LBA 8-15                   |
; | 0x15 | LBA 16-23                  |
; | 0x16 | LBA 24-27                  |
; | 0x17 | Status                     |
; +------+----------------------------+

;====================================================================
; Write a register to the ATA drive (8 bit)
;--------------------------------------------------------------------
; W    contains address
; TMP1 contains data
;--------------------------------------------------------------------
ATA_Reg8_Write
	btfss	PORTC, 5	; Wait until ready
	bra	ATA_Reg8_Write
	andlw	B'00011111'	; Set address
	movwf	PORTC
	movf	TMP1, W		; Set data
	movwf	PORTB
	clrf	TRISB		; Port for output
	bcf	LATE, 1		; DIOW low
	nop			; Wait
	nop
	bsf	LATE, 1		; DIOW high
	setf	TRISB		; Port for input
	return

; +-----------------------------------+
; | PORTC 4-0 to ATA register - Write |
; +------+----------------------------+
; | Addr | Register                   |
; +------+----------------------------+
; | 0x0E | Device control             |
; | 0x10 | Data (16 bit reg)          |
; | 0x11 | Features                   |
; | 0x12 | Sector count               |
; | 0x13 | LBA 0-7                    |
; | 0x14 | LBA 8-15                   |
; | 0x15 | LBA 16-23                  |
; | 0x16 | LBA 24-27                  |
; | 0x17 | Command                    |
; +------+----------------------------+

;====================================================================
; Read a register from the ATA drive (16 bit)
;--------------------------------------------------------------------
; W    contains address
; TMP1 contains data low
; TMP2 contains data high
;--------------------------------------------------------------------
ATA_Reg16_Read
	btfss	PORTC, 5	; Wait until ready
	bra	ATA_Reg16_Read
	andlw	B'00011111'	; Set address
	movwf	PORTC
	bcf	LATE, 0		; DIOR low
	nop			; Wait
	nop
	movf	PORTB, W	; Get data
	movwf	TMP1
	movf	PORTD, W
	movwf	TMP2
	bsf	LATE, 0		; DIOR high
	return

;====================================================================
; Write a register to the ATA drive (16 bit)
;--------------------------------------------------------------------
; W    contains address
; TMP1 contains data low
; TMP2 contains data high
;--------------------------------------------------------------------
ATA_Reg16_Write
	btfss	PORTC, 5	; Wait until ready
	bra	ATA_Reg16_Write
	andlw	B'00011111'	; Set address
	movwf	PORTC
	movf	TMP1, W		; Set data
	movwf	PORTB
	movf	TMP2, W
	movwf	PORTD
	clrf	TRISB		; Port for output
	clrf	TRISD
	bcf	LATE, 1		; DIOW low
	nop			; Wait
	nop
	bsf	LATE, 1		; DIOW high
	setf	TRISB		; Ports for input
	setf	TRISD
	return

;====================================================================
; Output string routines
;--------------------------------------------------------------------
OUT_VERSION
	movlw	UPPER(MSG_VERSION)
	movwf	TBLPTRU
	movlw	HIGH(MSG_VERSION)
	movwf	TBLPTRH
	movlw	LOW(MSG_VERSION)
	movwf	TBLPTRL
	goto	UART_Puts
OUT_HELP
	movlw	UPPER(MSG_HELP)
	movwf	TBLPTRU
	movlw	HIGH(MSG_HELP)
	movwf	TBLPTRH
	movlw	LOW(MSG_HELP)
	movwf	TBLPTRL
	goto	UART_Puts
OUT_COMMAND
	movlw	UPPER(MSG_COMMAND)
	movwf	TBLPTRU
	movlw	HIGH(MSG_COMMAND)
	movwf	TBLPTRH
	movlw	LOW(MSG_COMMAND)
	movwf	TBLPTRL
	goto	UART_Puts
OUT_CRLF
	movlw	UPPER(MSG_CRLF)
	movwf	TBLPTRU
	movlw	HIGH(MSG_CRLF)
	movwf	TBLPTRH
	movlw	LOW(MSG_CRLF)
	movwf	TBLPTRL
	goto	UART_Puts
OUT_UNKNOWN
	movlw	UPPER(MSG_UNKNOWN)
	movwf	TBLPTRU
	movlw	HIGH(MSG_UNKNOWN)
	movwf	TBLPTRH
	movlw	LOW(MSG_UNKNOWN)
	movwf	TBLPTRL
	goto	UART_Puts
OUT_LOG
	movlw	UPPER(MSG_LOG)
	movwf	TBLPTRU
	movlw	HIGH(MSG_LOG)
	movwf	TBLPTRH
	movlw	LOW(MSG_LOG)
	movwf	TBLPTRL
	goto	UART_Puts
OUT_DUMP
	movlw	UPPER(MSG_DUMP)
	movwf	TBLPTRU
	movlw	HIGH(MSG_DUMP)
	movwf	TBLPTRH
	movlw	LOW(MSG_DUMP)
	movwf	TBLPTRL
	goto	UART_Puts

;====================================================================
; Output value to USART as two hexadecimal digits
;--------------------------------------------------------------------
; W contains value to be output
;--------------------------------------------------------------------
OUT_HEX
	movwf	TMP1
	swapf	TMP1, W
	rcall	OUT_HEX_SUB1
	movf	TMP1, W
OUT_HEX_SUB1
	andlw	0x0F
	addlw	0xF6
	btfsc	STATUS, C
	addlw	0x07
	addlw	0x3A
	bra	UART_Putch

;====================================================================
; Start logging
;--------------------------------------------------------------------
LOG_START
	rcall	LOG_RESET
	rcall	INIT_ADC
	rcall	INIT_TIMER
	rcall	START_TIMER
	bsf	RCON, IPEN	; Enable interrupt priority
	bsf	INTCON, GIEH	; Enable high prority interrupts
	bsf	INTCON, GIEL	; Enable low prority interrupts
	return

;====================================================================
; Stop logging
;--------------------------------------------------------------------
LOG_STOP
	bcf	INTCON, 7	; Disable interrupts
	rcall	STOP_TIMER
	rcall	STOP_ADC
	rcall	ATA_Block_Write	; Flush buffer to disk
LOG_UPDATE
	movff	FSR2L, END_POSL	; Copy over to end log pointers
	movff	FSR2H, END_POSH
	movff	ATA_A0, END_ATA_A0
	movff	ATA_A1, END_ATA_A1
	movff	ATA_A2, END_ATA_A2
	movff	ATA_A3, END_ATA_A3
	return

;====================================================================
; Reset log ready for start of logging
;--------------------------------------------------------------------
LOG_RESET
	lfsr	FSR2, ATA_BUF	; Point to start of data capture buffer
	rcall	ATA_A_RESET
	return

;====================================================================
; Initialise ADC converter
;--------------------------------------------------------------------
INIT_ADC
	movlw	B'00001110'
	movwf	ADCON1
	movlw	B'11000001'
	movwf	ADCON0
	bcf	IPR1, ADIP	; Low priority
	bcf	PIR1, ADIF	; Clear any pending interrupt
	bsf	PIE1, ADIE	; Enable ADC conversion interrupt

	return

;====================================================================
; Initialise timer 0
;--------------------------------------------------------------------
INIT_TIMER
	movlw	B'01000110'
	movwf	T0CON
	movlw	D'1'		; Setup countdown on TMR0 for ADC trigger
	movwf	T0COUNT
	bcf	INTCON, TMR0IF	; Clear any pending TMR0 overflow interrupt
	bsf	INTCON, TMR0IE	; Enable timer 0 overflow interrupt
	return

;====================================================================
; Start timer 0
;--------------------------------------------------------------------
START_TIMER
	bsf	T0CON, 7	; Start timer 0
	return

;====================================================================
; Stop timer 0
;--------------------------------------------------------------------
STOP_TIMER
	bcf	INTCON, TMR0IE	; Disable timer 0 overflow interrupt
	bcf	INTCON, TMR0IF	; Clear any pending TMR0 overflow interrupt
	bcf	T0CON, 7	; Stop timer 0
	return

;====================================================================
; Stop ADC conversion
;--------------------------------------------------------------------
STOP_ADC
	bcf	PIE1, ADIE	; Diasable ADC conversion interrupt
	bcf	PIR1, ADIF	; Clear any pending interrupt
	bcf	ADCON0, ADON	; Turn off ADC module
	return

;====================================================================
; Dump data from ATA to USART in hex
;--------------------------------------------------------------------
DUMP_ALL
	rcall	ATA_A_RESET
	lfsr	FSR2, ATA_BUF_END
	movlw	0x10
	movwf	OUT_COUNT

	movf	ATA_A3, W	; Exit if no data to display
	iorwf	ATA_A2, W
	iorwf	ATA_A1, W
	iorwf	ATA_A0, W
	btfss	STATUS, Z
	bra	DUMP_ALL_JP1
	movlw	HIGH(ATA_BUF)
	cpfseq	END_POSH
	bra	DUMP_ALL_JP1
	movlw	LOW(ATA_BUF)
	cpfseq	END_POSL
	bra	DUMP_ALL_JP1
	bra	DUMP_ALL_EXIT

DUMP_ALL_LP1
	movlw	HIGH(ATA_BUF_END)	; Check if next sector required
	cpfseq	FSR2H
	bra	DUMP_ALL_JP2
	movlw	LOW(ATA_BUF_END)
	cpfseq	FSR2L
	bra	DUMP_ALL_JP2
	rcall	ATA_A_INC
DUMP_ALL_JP1
	rcall	ATA_Block_Read		; Get a new sector
	lfsr	FSR2, ATA_BUF		; Point buffer to start of sector
DUMP_ALL_JP2

	movlw	0x20
	rcall	UART_Putch

	movff	POSTINC2, TMP2
	movf	POSTINC2, W
	rcall	OUT_HEX
	movf	TMP2, W
	rcall	OUT_HEX

	decfsz	OUT_COUNT
	bra	DUMP_ALL_JP3
	movlw	0x10
	movwf	OUT_COUNT
	rcall	OUT_CRLF
DUMP_ALL_JP3
	movf	END_POSH, W		; Check not at the end of data
	cpfseq	FSR2H
	bra	DUMP_ALL_LP1
	movf	END_POSL, W
	cpfseq	FSR2L
	bra	DUMP_ALL_LP1
	movf	END_ATA_A3, W
	cpfseq	ATA_A3
	bra	DUMP_ALL_LP1
	movf	END_ATA_A2, W
	cpfseq	ATA_A2
	bra	DUMP_ALL_LP1
	movf	END_ATA_A1, W
	cpfseq	ATA_A1
	bra	DUMP_ALL_LP1
	movf	END_ATA_A0, W
	cpfseq	ATA_A0
	bra	DUMP_ALL_LP1
DUMP_ALL_EXIT
	return

;====================================================================
; Program messages
;--------------------------------------------------------------------
MSG_VERSION
	DATA	"Labcenter Data Logger v1.0\r\n", 0
MSG_COMMAND
	DATA	"\r\nCommand? ", 0
MSG_CRLF
	DATA	"\r\n", 0
MSG_HELP
	DATA	"Help:\r\nH - This help\r\nV - Version\r\nL - Start logging\r\nD - Dump log\r\n", 0
MSG_UNKNOWN
	DATA	"Unknown command.\r\n", 0
MSG_LOG
	DATA	"Logging...\r\nPress any key to stop.", 0
MSG_DUMP
	DATA	"Start of dump.\r\n", 0
;====================================================================
END

⌨️ 快捷键说明

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