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

📄 serial.asm

📁 DS1820 1-wire temp sensor AVR asm Program
💻 ASM
字号:
;************************************************
;* Serial driver routines for AVR's		*
;*						*
;* Copyright 2001-2003 Wayne Peacock		*
;* Wayne Peacock 7th July 2001			*
;* Version 1.01 				*
;************************************************
;* See Schematic for Hardware connections	*
;* 						*
;* Disclaimer:					*
;* The Author takes no responsibility for the 	*
;* use of this code. Use at your own risk!	*
;* 						*
;* This code or part there of is licensed only 	*
;* for private use and NOT for commercial use.	*
;* 						*
;* Please contact the author 'Wayne Peacock' 	*
;* <wpeacock@senet.com.au> before using the code*
;* or part there of in a commercial project.	*
;************************************************
         
; Requires the following 
;.def	text	= r0			; Text MUST be 0 (Data Out)
;.def	data	= r19			; (Data In)

;	Zreg				; Pointer to Data
	
;************************************************
;* RS232 Init	(4 Mhz)				*
;************************************************

comm_init:

	ldi	data, 0x19		; Set to 9600BPS at 4Mhz (19200 @ 8)
	out	UBRR, data
	
	; (7) RXCIE: RX Complete Interrupt Enable
	; (4) RXEN: Receiver Enable
	; (3) TXEN: Transmitter Enable
	
	ldi	data, 0b10011000	; Normal operation RX and TX enabled
	out	UCR, data
	
	cbi	USR, TXC		; Clear Transmit Complete
	ret		
	
;************************************************
;* RS232 Write Char				*
;* Input:	data				*
;* Output:	none				*
;************************************************

comm_write:

	; Check UART Data Register Empty
	
	sbis	USR, UDRE		; Skip if UDRE set
	rjmp	comm_write		; Repeat until ready!
	
	; Write Data
	out	UDR,data		; Load Data into UDR
	ret


;************************************************
;* RS232 Get Char				*
;* Input:	none				*
;* Output:	data				*
;************************************************

comm_read:

	; Wait for Data
	sbis	USR, RXC		; Repeat until char present
	rjmp	comm_read

	in	data,UDR		; Get char
	ret

;************************************************
;* RS232 Echo Data				*
;* Input:	none				*
;* output:	text				*
;************************************************

echo:
	; Wait for Data
	sbis	USR, RXC		; Repeat until char
	ret

	in	data,UDR		; Get char

	; Check UART Data Register Empty
	
s2:	sbis	USR, UDRE		; Skip if UDRE set
	rjmp	s2			; Repeat until ready!
	
	; Write Data
	out	UDR,data		; Load Data into UDR
	ret

;************************************************
;* RS232-WriteString(*Zreg) 0x00 to End		*
;* Input: 	Data at address of Z pointer	*
;* Returns:	None				*
;* Requires:	text (Must be r0)		*
;************************************************

comm_wstr:			
	lpm				; Load Program Memory (Get from Flash!)
	tst 	text			; Check for more characters
	breq	comm_wstr2		; End of Text
	
	; Check UART Data Register Empty
	
comm_wstr1:
	sbis	USR, UDRE		; Skip if UDRE set
	rjmp	comm_wstr1		; Repeat until ready!
	
	; Write Data
	out	UDR,text		; Load Data into UDR
	
	
	adiw	ZL,1			; Inc Z pointer
	rjmp	comm_wstr		; Repeat until 00		

comm_wstr2:	
	ret				; Finished here
	
;**** End of File ****

⌨️ 快捷键说明

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