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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usbtiny2313.asm

?? AVR的USB開發源代碼 USB-RS232轉換
?? ASM
?? 第 1 頁 / 共 5 頁
字號:
		mov	ByteCount,InputBufferLength	;length of input buffer
		rcall	DecodeNRZI		;transfer NRZI coding to bits
		rcall	MirrorInBufferBytes	;invert bits order in bytes
		rcall	BitStuff		;removal of bitstuffing
		;rcall	CheckCRCIn		;check CRC
		rcall	PrepareUSBOutAnswer	;prepare answers to transmitting buffer
		ldi	ActionFlag,DoReadySendAnswer
		rjmp	Main
;********************************************************************
;* Main program END
;********************************************************************
;------------------------------------------------------------------------------------------
;********************************************************************
;* Interrupt0 interrupt handler
;********************************************************************
INT0Handler:					;interrupt INT0
		in	backupSREG,SREG
		push	temp0
		push	temp1

		ldi	temp0,3			;counter of duration log0
		ldi	temp1,2			;counter of duration log1
		;waiting for begin packet
CheckchangeMinus:
		sbis	inputport,DATAminus	;waiting till change D- to 1
		rjmp	CheckchangeMinus
CheckchangePlus:
		sbis	inputport,DATAplus	;waiting till change D+ to 1
		rjmp	CheckchangePlus
DetectSOPEnd:
		sbis	inputport,DATAplus
		rjmp	Increment0		;D+ =0
Increment1:
		ldi	temp0,3			;counter of duration log0
		dec	temp1			;how many cycles takes log1
		nop
		breq	USBBeginPacket		;if this is end of SOP - receive packet
		rjmp	DetectSOPEnd
Increment0:
		ldi	temp1,2			;counter of duration log1
		dec	temp0			;how many cycles take log0
		nop
		brne	DetectSOPEnd		;if there isn't SOF - continue
		rjmp	EndInt0HandlerPOP2
EndInt0Handler:
		pop	ACC
		pop	RS232BufptrX
		pop	temp3
		pop	temp2
EndInt0HandlerPOP:
		pop	USBBufptrY
		pop	ByteCount
		mov	bitcount,backupbitcount	;restore bitcount register
EndInt0HandlerPOP2:
		pop	temp1
		pop	temp0
		out	SREG,backupSREG
		ldi	shiftbuf,1<<INTF0	;zero interruptu flag INTF0
		out	GIFR,shiftbuf
		reti				;otherwise finish (was only SOF - every millisecond)

USBBeginPacket:
		mov	backupbitcount,bitcount	;backup bitcount register
		in	shiftbuf,inputport	;if yes load it as zero bit directly to shift register
USBloopBegin:
		push	ByteCount		;additional backup of registers (save of time)
		push	USBBufptrY
		ldi	bitcount,6		;initialization of bits counter in byte
		ldi	ByteCount,MAXUSBBYTES	;initialization of max number of received bytes in packet
		ldi	USBBufptrY,InputShiftBufferBegin	;set the input buffer
USBloop1_6:
		in	inputbuf,inputport
		cbr	inputbuf,USBpinmask	;unmask low 2 bits
		breq	USBloopEnd		;if they are zeros - end of USB packet
		ror	inputbuf		;transfer Data+ to shift register
		rol	shiftbuf
		dec	bitcount		;decrement bits counter
		brne	USBloop1_6		;if it isn't zero - repeat filling of shift register
		nop				;otherwise is necessary copy shift register to buffer
USBloop7:
		in	inputbuf,inputport
		cbr	inputbuf,USBpinmask	;unmask low 2 bits
		breq	USBloopEnd		;if they are zeros - end of USB packet
		ror	inputbuf		;transfer Data+ to shift register
		rol	shiftbuf
		ldi	bitcount,7		;initialization of bits counter in byte
		st	Y+,shiftbuf		;copy shift register into buffer and increment pointer to buffer
USBloop0:					;and start receiving next byte
		in	shiftbuf,inputport	;zero bit directly to shift register
		cbr	shiftbuf,USBpinmask	;unmask low 2 bits
		breq	USBloopEnd		;if they are zeros - end of USB packet
		dec	bitcount		;decrement bits counter
		nop				;
		dec	ByteCount		;if not reached maximum buffer
		brne	USBloop1_6		;then receive next

		rjmp	EndInt0HandlerPOP	;otherwise repeat back from begin

USBloopEnd:
		cpi	USBBufptrY,InputShiftBufferBegin+3	;if at least 3 byte not received
		brcs	EndInt0HandlerPOP	;then finish
		lds	temp0,InputShiftBufferBegin+0	;identifier of packet to temp0
		lds	temp1,InputShiftBufferBegin+1	;address to temp1
		brne	TestDataPacket		;if is length different from 3 - then this can be only DataPaket
TestIOPacket:
;		cp	temp1,MyAddress		;if this isn't assigned (address) for me
;		brne	TestDataPacket		;then this can be still DataPacket
TestSetupPacket:;test to SETUP packet
		cpi	temp0,nNRZISETUPPID
		brne	TestOutPacket		;if this isn't Setup PID - decode other packet
		cp	temp1,MyInAddress	;if this isn't assigned (address) for me
		brne	TestDataPacket		;then this can be still DataPacket
		ldi	State,SetupState
		rjmp	EndInt0HandlerPOP	;if this is Setup PID - receive consecutive Data packet
TestOutPacket:	;test for OUT packet
		cpi	temp0,nNRZIOUTPID
		brne	TestInPacket		;if this isn't Out PID - decode other packet
		cp	temp1,MyOutAddress	;if this isn't assigned (address) for me
		brne	TestDataPacket		;then this can be still DataPacket
		ldi	State,OutState
		rjmp	EndInt0HandlerPOP	;if this is Out PID - receive consecutive Data packet
TestInPacket:	;test on IN packet
		cpi	temp0,nNRZIINPID
		brne	TestDataPacket		;if this isn't In PID - decode other packet
		cp	temp1,MyInAddress	;if this isn't assigned (address) for me
		breq	AnswerToInRequest
TestDataPacket:	;test for DATA0 and DATA1 packet
		cpi	temp0,nNRZIDATA0PID
		breq	Data0Packet		;if this isn't Data0 PID - decode other packet
		cpi	temp0,nNRZIDATA1PID
		brne	NoMyPacked		;if this isn't Data1 PID - decode other packet
Data0Packet:
		cpi	State,SetupState	;if was state Setup
		breq	ReceiveSetupData	;receive it
		cpi	State,OutState		;if was state Out
		breq	ReceiveOutData		;receive it
NoMyPacked:
		ldi	State,BaseState		;zero state
		rjmp	EndInt0HandlerPOP	;and receive consecutive Data packet

AnswerToInRequest:
		push	temp2			;backup next registers and continue
		push	temp3
		push	RS232BufptrX
		push	ACC
		cpi	ActionFlag,DoReadySendAnswer	;if isn't prepared answer
		brne	NoReadySend		;then send NAK
		rcall	SendPreparedUSBAnswer	;transmitting answer back
		cpi	State,AddressChangeState ;if state is AddressChange
		breq	SetMyNewUSBAddress	;then is necessary to change USB address
		ldi	State,InState
		ldi	ActionFlag,DoPrepareOutContinuousBuffer
		rjmp	EndInt0Handler		;and repeat - wait for next response from USB
ReceiveSetupData:
		push	temp2			;backup next registers and continue
		push	temp3
		push	RS232BufptrX
		push	ACC
		rcall	SendACK			;accept Setup Data packet
		rcall	FinishReceiving		;finish receiving
		ldi	ActionFlag,DoReceiveSetupData
		rjmp	EndInt0Handler
ReceiveOutData:
		push	temp2			;backup next registers and continue
		push	temp3
		push	RS232BufptrX
		push	ACC
		cpi	ActionFlag,DoReceiveSetupData	;if is currently in process command Setup
		breq	NoReadySend		;then send NAK
		rcall	SendACK			;accept Out packet
		clr	ActionFlag
		rjmp	EndInt0Handler
NoReadySend:
		rcall	SendNAK			;still I am not ready to answer
		rjmp	EndInt0Handler		;and repeat - wait for next response from USB
;------------------------------------------------------------------------------------------
SetMyNewUSBAddress:		;set new USB address in NRZI coded
		lds	MyInAddress,MyInAddressSRAM
		lds	MyOutAddress,MyOutAddressSRAM
		rjmp	EndInt0Handler
;------------------------------------------------------------------------------------------
FinishReceiving:		;corrective actions for receive termination
		cpi	bitcount,7		;transfer to buffer also last not completed byte
		breq	NoRemainingBits		;if were all bytes transfered, then nothing transfer
		inc	bitcount
ShiftRemainingBits:
		rol	shiftbuf		;shift remaining not completed bits on right position
		dec	bitcount
		brne	ShiftRemainingBits
		st	Y+,shiftbuf		;and copy shift register bo buffer - not completed byte
NoRemainingBits:
		mov	ByteCount,USBBufptrY
		subi	ByteCount,InputShiftBufferBegin-1	;in ByteCount is number of received bytes (including not completed bytes)

		mov	InputBufferLength,ByteCount		;and save for use in main program
		ldi	USBBufptrY,InputShiftBufferBegin	;pointer to begin of receiving shift buffer
		ldi	RS232BufptrX,InputBufferBegin+1		;data buffer (leave out SOP)
MoveDataBuffer:
		ld	temp0,Y+
		st	X+,temp0
		dec	ByteCount
		brne	MoveDataBuffer

		ldi	ByteCount,nNRZISOPbyte
		sts	InputBufferBegin,ByteCount		;like received SOP - it is not copied from shift buffer
		ret
;------------------------------------------------------------------------------------------
;********************************************************************
;* Other procedures
;********************************************************************
;------------------------------------------------------------------------------------------
USBReset:		;initialization of USB state engine
		ldi	temp0,nNRZIADDR0	;initialization of USB address
		mov	MyOutAddress,temp0
		mov	MyInAddress,temp0
		clr	State			;initialization of state engine
		clr	BitStuffInOut
		clr	OutBitStuffNumber
		clr	ActionFlag
		clr	RAMread			;will be reading from ROM
		clr	ConfigByte		;unconfigured state
		ret
;------------------------------------------------------------------------------------------
SendPreparedUSBAnswer:	;transmitting by NRZI coding OUT buffer with length OutputBufferLength to USB
		mov	ByteCount,OutputBufferLength		;length of answer
SendUSBAnswer:	;transmitting by NRZI coding OUT buffer to USB
		ldi	USBBufptrY,OutputBufferBegin		;pointer to begin of transmitting buffer
SendUSBBuffer:	;transmitting by NRZI coding given buffer to USB
		ldi	temp1,0			;incrementing pointer (temporary variable)
		mov	temp3,ByteCount		;byte counter: temp3 = ByteCount
		ldi	temp2,0b00000011	;mask for xoring
		ld	inputbuf,Y+		;load first byte to inputbuf and increment pointer to buffer
						;USB as output:
		cbi	outputport,DATAplus	;down DATAPLUS : idle state of USB port
		sbi	outputport,DATAminus	;set DATAMINUS : idle state of USB port
		sbi	USBdirection,DATAplus	;DATAPLUS as output
		sbi	USBdirection,DATAminus	;DATAMINUS as output

		in	temp0,outputport	;idle state of USB port to temp0
SendUSBAnswerLoop:
		ldi	bitcount,7		;bits counter
SendUSBAnswerByteLoop:
		nop				;delay because timing
		ror	inputbuf		;to carry transmiting bit (in direction first LSB then MSB)
		brcs	NoXORSend		;if that it is one - don't change USB state
		eor	temp0,temp2		;otherwise state will be changed
NoXORSend:
		out	outputport,temp0	;send out to USB
		dec	bitcount		;decrement bits counter - according to carry flag
		brne	SendUSBAnswerByteLoop	;if bits counter isn't zero - repeat transmiting with next bit
		sbrs	inputbuf,0		;if is transmiting bit one - don't change USB state
		eor	temp0,temp2		;otherwise state will be changed
NoXORSendLSB:
		dec	temp3			;decrement bytes counter
		ld	inputbuf,Y+		;load next byte and increment pointer to buffer
		out	outputport,temp0	;transmit to USB
		brne	SendUSBAnswerLoop	;repeat for all buffer (till temp3=0)

		mov	bitcount,OutBitStuffNumber	;bits counter for bitstuff
		cpi	bitcount,0		;if not be needed bitstuff
		breq	ZeroBitStuf
SendUSBAnswerBitstuffLoop:
		ror	inputbuf		;to carry transmiting bit (in direction first LSB then MSB)
		brcs	NoXORBitstuffSend	;if is one - don't change state on USB
		eor	temp0,temp2		;otherwise state will be changed
NoXORBitstuffSend:
		out	outputport,temp0	;transmit to USB
		nop				;delay because of timing
		dec	bitcount		;decrement bits counter - according to carry flag
		brne	SendUSBAnswerBitstuffLoop	;if bits counter isn't zero - repeat transmiting with next bit
		ld	inputbuf,Y		;delay 2 cycle
ZeroBitStuf:
		nop				;delay 1 cycle
		cbr	temp0,3
		out	outputport,temp0	;transmit EOP on USB

		ldi	bitcount,5		;delay counter: EOP shouls exists 2 bits (16 cycle at 12MHz)
SendUSBWaitEOP:
		dec	bitcount
		brne	SendUSBWaitEOP

		sbi	outputport,DATAminus	;set DATAMINUS : idle state on USB port
		sbi	outputport,DATAminus	;delay 2 cycle: Idle should exists 1 bit (8 cycle at 12MHz)
		cbi	USBdirection,DATAplus	;DATAPLUS as input
		cbi	USBdirection,DATAminus	;DATAMINUS as input
		cbi	outputport,DATAminus	;reset DATAMINUS : the third state on USB port
		ret
;------------------------------------------------------------------------------------------
ToggleDATAPID:
		lds	temp0,OutputBufferBegin+1	;load last PID
		cpi	temp0,DATA1PID			;if last was DATA1PID byte
		ldi	temp0,DATA0PID
		breq	SendData0PID			;then send zero answer with DATA0PID
		ldi	temp0,DATA1PID			;otherwise send zero answer with DATA1PID
SendData0PID:
		sts	OutputBufferBegin+1,temp0	;DATA0PID byte
		ret
;------------------------------------------------------------------------------------------
ComposeZeroDATA1PIDAnswer:
		ldi	temp0,DATA0PID			;DATA0 PID - in the next will be toggled to DATA1PID in load descriptor
		sts	OutputBufferBegin+1,temp0	;load to output buffer
ComposeZeroAnswer:

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
1区2区3区精品视频| 国产精品影视网| 91福利国产成人精品照片| 亚洲与欧洲av电影| 国产精品美女久久久久久久网站| 日韩欧美一级在线播放| av动漫一区二区| 欧美精品aⅴ在线视频| 成人av资源在线观看| 精品一区二区三区欧美| 青青草91视频| 奇米在线7777在线精品| 香蕉加勒比综合久久| 一区二区三区加勒比av| 亚洲另类在线一区| 亚洲欧美另类图片小说| 亚洲视频免费在线| 日韩理论在线观看| 久久精品视频一区二区三区| 制服.丝袜.亚洲.中文.综合| 欧美影院精品一区| 欧美日韩一卡二卡三卡 | 欧美国产精品一区二区| 久久综合99re88久久爱| 精品sm在线观看| 久久久久久久av麻豆果冻| 国产日韩欧美一区二区三区综合| 久久久久久黄色| 日韩美女精品在线| 亚洲成人激情av| 九九在线精品视频| 风流少妇一区二区| 色婷婷一区二区三区四区| 精品视频1区2区3区| 91精品国产乱| 久久久久久久久99精品| 91精品久久久久久久久99蜜臂| 日韩一区二区三区电影在线观看 | 一区二区三区高清| 亚洲成av人片www| 激情另类小说区图片区视频区| 国产一区二区视频在线播放| 成人午夜激情影院| 欧美在线视频日韩| 欧美xxxx老人做受| 18成人在线观看| 日本sm残虐另类| 丁香婷婷综合色啪| 国产精品久久久久久久午夜片| 亚洲女同一区二区| 亚洲成人一区在线| 美女视频黄a大片欧美| 91亚洲国产成人精品一区二三| 欧美三级视频在线播放| 久久久久九九视频| 亚洲福利一区二区三区| 国产精品亚洲午夜一区二区三区 | 亚洲国产一区视频| 久久99精品国产91久久来源| 99精品久久只有精品| 精品少妇一区二区三区日产乱码| 中文字幕第一区| 美女被吸乳得到大胸91| 91一区在线观看| 欧美精品一区二| 日本美女一区二区三区| 97精品国产露脸对白| 精品剧情在线观看| 水蜜桃久久夜色精品一区的特点| 欧美bbbbb| 欧美在线免费观看亚洲| 1000部国产精品成人观看| 激情文学综合插| 欧美一区二区三区免费大片 | 精品国产亚洲在线| 伊人色综合久久天天人手人婷| 国产老肥熟一区二区三区| 欧美一区二区三区免费视频| 一区二区三区 在线观看视频| 成人丝袜18视频在线观看| 日韩一区二区三区视频在线观看| 一区二区不卡在线播放 | 美女网站色91| 欧美乱妇一区二区三区不卡视频| 樱桃国产成人精品视频| 成人免费va视频| 欧美经典一区二区三区| 国产综合成人久久大片91| 日韩一区二区三区视频| 一级日本不卡的影视| 色天使色偷偷av一区二区| 亚洲激情图片一区| 欧美性xxxxxxxx| 天天亚洲美女在线视频| 2023国产一二三区日本精品2022| 久久国产剧场电影| 久久奇米777| 国产大片一区二区| 久久麻豆一区二区| 国产一区久久久| 欧美va亚洲va| 丁香婷婷综合激情五月色| 中文一区在线播放| 9l国产精品久久久久麻豆| 一区在线观看免费| 欧美在线不卡一区| 天天av天天翘天天综合网色鬼国产| 不卡在线视频中文字幕| 夜夜夜精品看看| 日韩精品一区二区三区四区视频| 九九视频精品免费| 精品久久久久久久久久久久久久久久久 | 国产乱色国产精品免费视频| 久久久午夜电影| 97精品电影院| 亚洲最新视频在线播放| 欧美一级片在线| 国产成人免费视频网站高清观看视频| 中文字幕乱码一区二区免费| 99久久久久久| 日韩专区一卡二卡| 久久亚洲一区二区三区四区| 国产毛片精品国产一区二区三区| 国产精品久久久一本精品| 99精品视频在线播放观看| 午夜精品久久久久影视| 久久综合色婷婷| 一本一道综合狠狠老| 丝袜亚洲另类欧美综合| 国产欧美综合色| 欧美精品777| av一区二区三区在线| 免费看欧美美女黄的网站| 亚洲人成网站影音先锋播放| 日韩精品一区二区三区在线| 色婷婷久久久综合中文字幕| 久久精品国产久精国产| 亚洲精品国产a久久久久久| 精品国产一区二区亚洲人成毛片| 麻豆精品视频在线观看免费| 亚洲天堂久久久久久久| 亚洲精品在线网站| 欧美网站大全在线观看| 国产风韵犹存在线视精品| 午夜欧美电影在线观看| 亚洲视频你懂的| 久久精品综合网| 欧美成人一区二区三区| 欧美探花视频资源| 色综合一区二区三区| 久久99精品国产麻豆婷婷| 亚洲高清免费在线| 一区二区三区欧美| 中文字幕在线一区免费| 久久综合色天天久久综合图片| 欧美电影影音先锋| 91视频免费看| 成人高清视频免费观看| 国模少妇一区二区三区| 蜜臀av性久久久久蜜臀av麻豆| 亚洲高清免费在线| 一区二区三区色| 亚洲另类中文字| 亚洲免费在线观看| 国产精品不卡在线| 蜜臀91精品一区二区三区| 亚洲激情图片qvod| 午夜欧美在线一二页| 久久66热偷产精品| 国产成人精品免费在线| 色婷婷久久综合| 在线成人av影院| 久久久久99精品一区| 国产精品私人影院| 亚洲综合激情另类小说区| 琪琪久久久久日韩精品| 国产精品夜夜嗨| 91国产福利在线| 欧美成人一级视频| 17c精品麻豆一区二区免费| 亚洲午夜免费电影| 精品一区二区三区视频在线观看| 成人app网站| 91精品蜜臀在线一区尤物| 国产欧美日韩在线| 亚洲黄网站在线观看| 看电影不卡的网站| 成人av影视在线观看| 欧美日韩成人一区二区| 国产日韩av一区二区| 亚洲成人资源网| 国产精品一级黄| 欧美久久久久久蜜桃| 国产拍欧美日韩视频二区| 午夜欧美大尺度福利影院在线看| 国产制服丝袜一区| 6080日韩午夜伦伦午夜伦| 国产精品拍天天在线| 日本麻豆一区二区三区视频| 91免费观看在线|