亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? avr304.asm

?? 南描述了如何在AT90S1200上實現(xiàn)輪詢(polled)軟件UART
?? ASM
字號:
;**** A P P L I C A T I O N   N O T E   A V R 3 0 4 ************************
;*
;* Title:		Half Duplex Interrupt Driven Software UART 
;* Version:		1.0
;* Last updated:	97.07.18
;* Target:		AT90Sxxxx (All AVR Devices)
;*
;* Support E-mail:	avr@atmel.com
;*
;* Code Size		:72 words
;* Low Register Usage	:2
;* High Register Usage	:5
;* Interrupt Usage	:External Interrupt,
;*			 Timer/Counter0 overflow interrupt
;*
;* DESCRIPTION
;*
;* This application note describes how to make a half duplex software UART
;* on any AVR device with the 8-bit Timer/Counter0 and External Interrupt.
;* As a lot of control applications communicate in one direction at a time
;* only, a half duplex UART will limit the usage of MCU resources.
;*
;* The constants N and R determine the data rate. R selects clock frequency
;* as described in the T/C Prescaler in the AVR databook. If the T/C pre-
;* scaling factor is denoted C, the following expression yields the data rate:
;*
;*		 XTAL
;*	 BAUD = ------		min. N*C = 17
;*		 N*C		max. N   = 170
;*
;* Absolute minimum value for N*C is 17 (which causes the interrupt flag to be 
;* set again before the interrupt is finished). Absolute maximum is 170.
;* (Caused by the 1.5bit-lenght that is necessary to receive bits correctly.)
;*
;* The UART uses PD2 as receive pin because it utilizes the external interrupt.
;* The transmit-pin is PD4 in this example, but it can be any other pins.
;*
;* Since the UART is half duplex, it can either send or recieve data. It can't
;* do both simoutaneausly. When idle it will automatically recieve incoming
;* data, but if it is transmitting data while incoming data arrives, it will
;* ignore it. Also, if u_transmit is called without waiting for the 'READY' bit
;* in the 'u_status' register to become cleared, it will abort any pending 
;* reception or transmittal.
;*
;*
;* *** Initialization
;*
;*  1. Call uart_init
;*  2. Enable global interrupts (with 'sei')
;*
;* *** Receive
;*
;*  1. Wait until RDR in 'u_status' becomes set
;*  2. Read 'u_buffer'
;*
;* *** Transmit
;*
;* (0. Initialize the UART by executing uart_init and sei)
;*  1. Wait until READY in 'u_status' becomes clear
;*  2. Set 'u_buffer'
;*  3. Call 'u_transmit'
;*
;**************************************************************************

.include "1200def.inc"

;***** BAUD-rate settings

				;BAUD-RATES @1MHz XTAL AND R=1
;.equ	N=104			; 9600
;.equ	N=52			;19200 
.equ	N=26			;38400
.equ	C=1			;Divisor
.equ	R=1			;R=1 when C=1


;***** UART Global Registers

.def	u_buffer	=r14	;Serial buffer
.def	u_sr		=r15	;Status-register storage
.def	u_tmp		=r16	;Scratchregister
.def	u_bit_cnt	=r17	;Bit counter
.def	u_status	=r18	;Status buffer
.def	u_reload	=r19	;Reload-register (internal - do not use)
.def	u_transmit	=r20	;Data to transmit


;***** Bit positions in the Status-register

.equ	RDR=0			;Receive data ready bit
.equ	TD=6			;Transmitting data (internal - read-only)
.equ	BUSY=7			;Busy-flag (internal - read-only)


;**************************************************************************
;*
;*	PROGRAM START - EXECUTION STARTS HERE
;*
;**************************************************************************
	.cseg

	.org $0000
	rjmp	start			;Reset handler

	.org INT0addr
	rjmp	ext_int0		;External interrupt handler

	.org OVF0addr
	rjmp	tim0_ovf		;Timer0 overflow handler

	.org ACIaddr
	reti				;Analog comparator handler (Not Used)



;**************************************************************************
;*
;* EXT_INT0 - External Interrupt Routine 0
;*
;*
;* DESCRIPTION
;* This routine is executed when a negative edge on the incoming serial
;* signal is detected. It disables further external interrupts and enables
;* timer interrupts (bit-timer) because the UART must now receive the
;* incoming data. 
;*
;* This routine sets bits in the GIMSK, TIFR and TIMSK registers. In this
;* code when the bits are set, it overwrites all other bits. This is done
;* because of the lack of available cycles when it operates at low clock
;* rate and high baudrates.
;*
;*
;* Total number of words	: 12
;* Total number of cycles	: 15 (incl. reti)
;* Low register usage		: 1 (u_sr)
;* High register usage		: 4 (u_bit_cnt,u_tmp,u_status,u_reload)
;*
;**************************************************************************
ext_int0:
	in	u_sr,SREG		;Store Status Register

	ldi	u_status,1<<BUSY	;Set busy-flag (clear all others)

	ldi	u_tmp,(256-(N+N/2)+(29/C));Set timer reload-value (to 1.5
	out	TCNT0,u_tmp		;  bit len). 29 = time delay that
					;  have already been used in this
					;  interrupt plus the time
					;  that will be used by the time
					;  delay between timer interrupt request
					;  and the actual sampling of the first
					;  data bit.

	ldi	u_tmp,1<<TOIE0		;Set bit 1 in u_tmp
	out	TIFR,u_tmp		;   to clear T/C0 overflow flag
	out	TIMSK,u_tmp		;   and enable T/C0 overflow interrupt

	clr	u_bit_cnt		;Clear bit counter
	out	GIMSK,u_bit_cnt		;Disable external interrupt

	ldi	u_reload,(256-N+(8/C))	;Set reload-value (constant).

	out	SREG,u_sr		;Restore SREG
	reti


;**************************************************************************
;*
;* TIM0_OVF - Timer/Counter 0 Overflow Interrupt
;*
;*
;* DESCRIPTION
;* This routine coordinates the transmition and reception of bits. This 
;* routine is automatically executed at a rate equal to the baud-rate. When
;* transmitting, this routine shifts the bits and sends it. When receiving,
;* it samples the bit and shifts it into the buffer.
;*
;* The serial routines uses a status register (u_status): READ-ONLY.
;*		BUSY	This bit indicates whenever the UART is busy
;*		TD	Transmit Data. Set when the UART is transmitting
;*		RDR	Receive Data Ready. Set when new data has arrived
;*			and it is ready for reading.
;*
;* When the RDR flag is set, the (new) data can be read from u_buffer.
;*
;* This routine also sets bits in TIMSK and TIMSK. See ext_int0 description
;*
;* 
;* Total number of words	: 35
;* Total number of cycles	: min. 18, max. 28 - depending on if it is
;*				  receiving or transmitting, what bit is
;*				  pending, etc.
;* Low register usage		: 2 (u_sr,u_buffer)
;* High register usage		: 4 (u_bit_cnt,u_tmp,u_status,u_reload)
;* 
;**************************************************************************
tim0_ovf:
	in	u_sr,SREG		;Store statusregister

	out	TCNT0,u_reload		;Reload timer

	inc	u_bit_cnt		;Increment bit_counter
	sbrs	u_status,TD		;if transmit-bit set
	rjmp	tim0_receive		;    goto receive

	sbrc	u_bit_cnt,3		;if bit 3 in u_bit_cnt (>7) is set
	rjmp	tim0_stopb		;    jump to stop-bit-part

	sbrc	u_buffer,0		;if LSB in buffer is 1
	sbi	PORTD,PD4		;    Set transmit to 1
	sbrs	u_buffer,0		;if LSB in buffer is 0
	cbi	PORTD,PD4		;    Set transmit to 0
	lsr	u_buffer		;Shift buffer right
	
	out	SREG,u_sr		;Restore SREG
	reti

tim0_stopb:
	sbi	PORTD,PD4		;Generate stop-bit

	sbrs	u_bit_cnt,0		;if u_bit_cnt==8 (stop-bit)
	rjmp	tim0_ret		;      jump to exit

tim0_complete:
	ldi	u_tmp,1<<INT0		;(u_bit_cnt==9):
	out	GIMSK,u_tmp		;Enable external interrupt
	clr	u_tmp 
	out	TIMSK,u_tmp		    ;Disable timer interrupt
	cbr	u_status,(1<<BUSY)|(1<<TD)  ;Clear busy-flag and transmit-flag

tim0_ret:
	out	SREG,u_sr		;Restore status register
	reti

tim0_receive:
	sec				;Set carry
	sbis	PIND,2			;if PD2=LOW         <=== SAMPLE HERE
	clc				;    clear carry
	ror	u_buffer		;Shift carry into data
	in	u_tmp,SREG		;Store SREG

	cpi	u_bit_cnt,9		;if u_bit_cnt!=9 (must sample stop-bit)
	brne	tim0_ret		;   exit interrupt

	out	SREG,u_tmp		;Get old SREG
	rol	u_buffer		;Rotate back data (to get rid of the stop-bit)

	sbr	u_status,1<<RDR		;Clear busy-flag
	rjmp	tim0_complete



;**************************************************************************
;*
;* uart_init - Subroutine for UART initialization
;*
;*
;* DESCRIPTION
;* This routine initializes the UART. It sets the timer and enables the
;* external interrupt (receiving). To enable the UART the global interrupt
;* flag must be set (with SEI).
;*
;*
;* Total number of words	: 8
;* Total number of cycles	: 11 (including the RET instructions)
;* Low register usage		: None
;* High register usage		: 2 (u_tmp,u_status)
;* 
;**************************************************************************
uart_init:	
	ldi	u_tmp,R
	out	TCCR0,u_tmp		;Start timer and set clock source
	ldi	u_tmp,1<<INT0
	out	GIMSK,u_tmp		;Enable external interrupt 0
	in	u_tmp,1<<ISC01
	out	MCUCR,u_tmp		;On falling edges
	clr	u_status		;Erase status-byte
	ret



;**************************************************************************
;*
;* uart_transmit - Subroutine for UART transmittal
;*
;*
;* DESCRIPTION
;* This routine initialize the UART to transmit data. The data to be sent
;* must be located in u_transmit. 
;*
;* Warning: This routine cancels all other transmittions or receptions.
;* So be careful. If a byte is being received and the timer interrupt is
;* currently running, the tranmittion may be corrupted. By checking the
;* READY-bit and/or TD-bit in the u_status register for safe transmissions.
;*
;* This routine also sets bits in TIMSK and TIMSK. See ext_int0 description
;*
;*
;* Total number of words	: 13
;* Total number of cycles	: 17 (including RET)
;* Low register usage		: 1 (u_buffer)
;* High register usage		: 4 (u_bit_cnt,u_tmp,u_transmit,u_reload)
;* 
;**************************************************************************
uart_transmit:
	ldi	u_status,(1<<BUSY)|(1<<TD)   ;Set only busy- and transmit flag

	clr	u_tmp
	out	GIMSK,u_tmp		;Disable external interrupt

	ser	u_bit_cnt		;Erase bit-counter (set all bits)
	mov	u_buffer,u_transmit	;Copy transmit-data to buffer

	ldi	u_tmp,1<<TOIE0		;Set bit 1 in u_tmp
	out	TIFR,u_tmp		;  to clear T/C0 overflow flag
	out	TIMSK,u_tmp		;  and enable T/C0 overflow interrupt
	
	ldi	u_reload,(256-N+(8/C))	;Set reload-value
	ldi	u_tmp,(256-N+(14/C))	;Set timer delay to first bit
	out	TCNT0,u_tmp		;Set timer reload-value (1 bit)

	cbi	PORTD,PD4		;Clear output (start-bit)
	ret



;**************************************************************************
;*
;*	Test/Example Program
;*
;* This example program can be used for evaluation of the UART agains a PC
;* running a terminal emulator. If a key is pressed on the PC keyboard, the
;* message 'You typed <characher>' is sent back. The character is also
;* presented on port B.
;*
;**************************************************************************

.def	tmp=r21				;Temp. register
.def	buffer=r22			;Recieved byte
.def	adr=r23				;EEPROM Address

start:	ser	tmp			;Initialize
	out	PORTD,tmp		;Set port D as input with pullups
	sbi	DDRD,DDD4		;    except PD4 -> output with 1's
	out	DDRB,tmp		;Set port B as output with 1's (LED-off)
	out	PORTB,tmp

	rcall	uart_init		;Init UART
	sei				;Enable interrupts

idle:	sbrs	u_status,RDR		;Wait for Character
	rjmp	idle
	mov	buffer,u_buffer		;Get recieved character
	out	PORTB,u_buffer		;Output the byte on port B
	ldi	adr,example_data	;Set/Restore pointer to EEPROM data

loop:	out	EEAR,adr		;Set the EEPROM's address
	sbi	EECR,EERE		;Send the Read strobe
	in	u_transmit,EEDR		;Put the data in the transmit register
	rcall	uart_transmit		;And transmit the data

wait:	sbrc	u_status,TD		;Wait until data is sent
	rjmp	wait

	inc	adr			;Increase pointer
	cpi	adr,example_data+12	;Reached byte 12? (End?)
	breq	idle			;    Yes, wait for new char.

	cpi	adr,example_data+10	;Reached byte 10?
	brne	loop			;    No, jump back

	mov	u_transmit,buffer	;Put data in transmit register
	rcall	uart_transmit		;And transmit it

wait2:	sbrc	u_status,TD		;Wait until data is sent
	rjmp	wait2

	rjmp	loop			;Continue sendig chars


;**************************************************************************
;*
;*	Test/Example program data.
;*
;* This is the data that will be sent back when a character is recieved.
;*
;**************************************************************************
	.eseg
example_data:
	.db	89	;'Y'
	.db	111	;'o'
	.db	117	;'u'
	.db	32	;' '
	.db	116	;'t'
	.db	121	;'y'
	.db	112	;'p'
	.db	101	;'e'
	.db	100	;'d'
	.db	32	;' '
	.db	13	;<CR>
	.db	10	;<LF>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久五月婷婷| 国产老女人精品毛片久久| 玖玖九九国产精品| 99精品国产视频| 欧美不卡123| 天天综合天天做天天综合| 成人午夜激情影院| 欧美精品一区二区在线观看| 亚洲成人tv网| 91麻豆产精品久久久久久 | 国产精品日韩成人| 美腿丝袜亚洲综合| 欧美色网一区二区| 亚洲欧洲制服丝袜| 成人视屏免费看| 日韩精品一区二区三区视频在线观看| 亚洲精品国产成人久久av盗摄| 国产成人在线视频播放| 欧美videossexotv100| 日日摸夜夜添夜夜添亚洲女人| 色香蕉久久蜜桃| 亚洲天堂福利av| av亚洲精华国产精华精华| 久久久精品综合| 国产精品中文有码| 国产人妖乱国产精品人妖| 国内外成人在线| 久久夜色精品国产欧美乱极品| 视频一区二区国产| 欧美老女人第四色| 天堂va蜜桃一区二区三区| 成人av在线一区二区三区| 国产女人水真多18毛片18精品视频 | 日韩精品高清不卡| 欧美一卡二卡在线| 日韩黄色小视频| 91精品国产乱码久久蜜臀| 一区二区三区精品| 欧美日韩亚洲国产综合| 午夜精品免费在线观看| 欧美日韩中字一区| 日韩av中文字幕一区二区| 欧美一区二区三区免费在线看| 久久精品国产色蜜蜜麻豆| 欧美成人精品高清在线播放| 国产又黄又大久久| 国产精品久久久久影院老司 | 欧美酷刑日本凌虐凌虐| 亚洲国产欧美日韩另类综合| 欧美人狂配大交3d怪物一区| 日韩国产在线一| 欧美精品一区二区蜜臀亚洲| 国产乱子伦视频一区二区三区| 中文字幕av免费专区久久| 99精品国产视频| 日本一不卡视频| 国产丝袜在线精品| 日本道免费精品一区二区三区| 亚洲国产成人porn| 久久影院视频免费| 91在线视频18| 老司机精品视频在线| 国产亲近乱来精品视频| 91久久人澡人人添人人爽欧美 | 依依成人精品视频| 日韩欧美成人一区| 不卡一区二区三区四区| 亚洲第一二三四区| 国产视频一区不卡| 欧美日韩国产精品自在自线| 另类小说色综合网站| 中文字幕一区二区三区精华液| 在线观看欧美日本| 国产一区二区三区黄视频 | 韩国午夜理伦三级不卡影院| 亚洲欧美日韩国产成人精品影院| 欧美高清视频不卡网| 成人福利视频在线| 玖玖九九国产精品| 亚洲国产乱码最新视频| 中文字幕欧美国产| 欧美岛国在线观看| 色婷婷av久久久久久久| 国产乱子伦视频一区二区三区| 亚洲国产日韩一级| 亚洲女厕所小便bbb| 久久久噜噜噜久久人人看| 欧美二区三区91| 色噜噜狠狠成人中文综合| 国产伦精一区二区三区| 日日夜夜免费精品视频| 一区二区三区不卡视频| 国产精品狼人久久影院观看方式| 欧美一区二区三区啪啪| 欧美区在线观看| 欧美综合一区二区| 色综合激情久久| 91小视频免费看| 成人av在线资源| 粉嫩蜜臀av国产精品网站| 毛片一区二区三区| 午夜精品一区二区三区电影天堂| 一区二区三区免费| 亚洲日本va在线观看| 国产精品不卡一区二区三区| 久久人人爽人人爽| 久久只精品国产| 26uuu欧美日本| 久久综合九色综合欧美就去吻| 欧美一区二区在线观看| 91精品国产综合久久久蜜臀图片| 欧美性猛交一区二区三区精品| 一本到不卡精品视频在线观看| 成人激情免费电影网址| 99精品热视频| 在线影视一区二区三区| 色噜噜狠狠成人中文综合| 色婷婷精品久久二区二区蜜臀av| 色婷婷国产精品| 99在线精品视频| 色一区在线观看| 欧美亚洲自拍偷拍| 欧美日韩精品一区二区在线播放 | av在线播放不卡| 一本大道久久a久久精二百| 日本乱人伦一区| 欧美精品在线一区二区| 精品入口麻豆88视频| 久久久久久久精| 国产精品视频线看| 亚洲色图另类专区| 偷偷要91色婷婷| 精品影视av免费| 成人性生交大片| 欧洲另类一二三四区| 91精品国产一区二区| 精品国产百合女同互慰| 最近日韩中文字幕| 日韩国产欧美在线播放| 国产真实精品久久二三区| 不卡的电影网站| 欧美人xxxx| 国产精品麻豆欧美日韩ww| 一区二区三区不卡视频| 麻豆国产精品777777在线| 福利视频网站一区二区三区| 欧洲av一区二区嗯嗯嗯啊| 欧美一区二区三区白人| 久久精品人人做人人爽人人| 伊人性伊人情综合网| 麻豆91精品视频| 91欧美一区二区| 欧美不卡一区二区三区四区| 国产精品理论片| 免费观看久久久4p| 91老师国产黑色丝袜在线| 欧美一级日韩一级| 亚洲视频一区在线| 韩国成人福利片在线播放| 色婷婷综合久久久久中文一区二区 | 91国产福利在线| 亚洲人一二三区| 国产精品一区二区免费不卡| 欧美性大战久久久久久久蜜臀 | 中文字幕色av一区二区三区| 日韩电影在线观看一区| av亚洲精华国产精华| 久久伊人中文字幕| 日韩激情av在线| 在线观看一区日韩| 亚洲国产精品av| 经典三级视频一区| 717成人午夜免费福利电影| 亚洲精品成人a在线观看| 国产一区二区福利| 日韩欧美www| 免费成人小视频| 欧美日韩小视频| 亚洲精品欧美激情| 不卡的av电影在线观看| 久久精品欧美一区二区三区不卡| 偷拍与自拍一区| 欧美精品在线观看播放| 亚洲人成亚洲人成在线观看图片| 国产一区二区不卡在线| 日韩亚洲欧美高清| 日韩av电影免费观看高清完整版在线观看| 91麻豆国产在线观看| 中文字幕一区二区三区色视频| 国产sm精品调教视频网站| 久久老女人爱爱| 国产一区二区三区不卡在线观看| 日韩精品一区二区三区中文精品| 天天影视色香欲综合网老头| 在线观看视频一区二区欧美日韩| 亚洲欧美偷拍另类a∨色屁股| 99久久国产综合色|国产精品| 国产精品久久综合| www.在线成人| 国产精品美女久久久久久久久久久|