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

📄 usbtors232_sk_eng.asm

📁 USB技术大全-54.8M.zip
💻 ASM
📖 第 1 页 / 共 5 页
字号:
HalfInsertPosuvMask:
		lsl	temp2			;nula do dalsieho spodneho bitu masky	;ENG;zero to the next low bit of mask
		dec	bitcount		;az pokial sa nedosiahne hranica posuvania v byte	;ENG;till not reached boundary of shifting in byte
		brne	HalfInsertPosuvMask

		and	temp1,temp2		;odmaskuj aby zostali iba vrchne posunute bity v temp1	;ENG;unmask that remains only high shifted bits in temp1
		com	temp2			;invertuj masku	;ENG;invert mask
		lsr	temp2			;posun masku vpravo - na vlozenie nuloveho bitu	;ENG;shift mask to the right - for insertion of zero bit
		ld	temp0,Y			;nahraj byte ktory este treba posunut od pozicie bitcount do temp0	;ENG;load byte which must be shifted from position bitcount to temp0
		and	temp0,temp2		;odmaskuj aby zostali iba spodne neposunute bity v temp0	;ENG;unmask to remains only low non-shifted bits in temp0
		or	temp1,temp0		;a zluc posunutu a neposunutu cast	;ENG;and put together shifted and nonshifted part

		ld	temp0,Y			;nahraj byte ktory este treba posunut od pozicie bitcount	;ENG;load byte which must be shifted from position bitcount
		rol	temp0			;a posun ho vlavo cez Carry (aby sa nastavilo spravne Carry pre dalsie prenosy)	;ENG;and shift it to the left through Carry (to set right Carry for further carry)
		st	Y+,temp1		;a nahraj spat upraveny byte	;ENG;and load back modified byte
ShiftInsertBufferLoop:
		cpse	USBBufptrY,ByteCount	;ak nie su vsetky cele byty	;ENG;if are not all entire bytes
		rjmp	NoEndShiftInsertBuffer	;tak pokracuj	;ENG;then continue
		ret				;inak skonci	;ENG;otherwise finish
NoEndShiftInsertBuffer:
		ld	temp1,Y			;nahraj byte	;ENG;load byte
		rol	temp1			;a posun vlavo cez Carry (prenos z nizsieho byte a LSB do Carry)	;ENG;and shift to the left through Carry (carry from low byte and LSB to Carry)
		st	Y+,temp1		;a nahraj spat	;ENG;and store back
		rjmp	ShiftInsertBufferLoop	;a pokracuj	;ENG;and continue
;------------------------------------------------------------------------------------------
ShiftDeleteBuffer:	;posuv buffera o jeden bit vlavo od konca az po poziciu: byte-USBBufptrY a bit-bitcount	;ENG;shift buffer one bit to the left from end to position: byte-USBBufptrY and bit-bitcount
		mov	temp0,bitcount		;vypocet: bitcount= 9-bitcount	;ENG;calculation: bitcount= 9-bitcount
		ldi	bitcount,9
		sub	bitcount,temp0		;do bitcount poloha bitu, ktory este treba posunut	;ENG;to bitcount bit position, which must be shifted
		mov	temp0,USBBufptrY	;uschovanie pointera do buffera	;ENG;backup pointera to buffer
		inc	temp0			;pozicia celych bytov do temp0	;ENG;position of completed bytes to temp0
		mov	USBBufptrY,ByteCount	;maximalna pozicia do pointera	;ENG;maximum position to pointer
ShiftDeleteBufferLoop:
		ld	temp1,-Y		;zniz buffer a nahraj byte	;ENG;decrement buffer and load byte
		ror	temp1			;a posun vpravo cez Carry (prenos z vyssieho byte a LSB do Carry)	;ENG;and right shift through Carry (carry from higher byte and LSB to Carry)
		st	Y,temp1			;a nahraj spat	;ENG;and store back
		cpse	USBBufptrY,temp0	;ak nie su vsetky cele byty	;ENG;if there are not all entire bytes
		rjmp	ShiftDeleteBufferLoop	;tak pokracuj	;ENG;then continue

		ld	temp1,-Y		;zniz buffer a nahraj byte ktory este treba posunut od pozicie bitcount	;ENG;decrement buffer and load byte which must be shifted from position bitcount
		ror	temp1			;a posun vpravo cez Carry (prenos z vyssieho byte a LSB do Carry)	;ENG;and right shift through Carry (carry from higher byte and LSB to Carry)
		ser	temp2			;FF do masky - temp2	;ENG;FF to mask - temp2
HalfDeletePosuvMask:
		dec	bitcount		;az pokial sa nedosiahne hranica posuvania v byte	;ENG;till not reached boundary of shifting in byte
		breq	DoneMask
		lsl	temp2			;nula do dalsieho spodneho bitu masky	;ENG;zero to the next low bit of mask
		rjmp	HalfDeletePosuvMask
DoneMask:
		and	temp1,temp2		;odmaskuj aby zostali iba vrchne posunute bity v temp1	;ENG;unmask to remain only high shifted bits in temp1
		com	temp2			;invertuj masku	;ENG;invert mask
		ld	temp0,Y			;nahraj byte ktory este treba posunut od pozicie bitcount do temp0	;ENG;load byte which must be shifted from position bitcount to temp0
		and	temp0,temp2		;odmaskuj aby zostali iba spodne neposunute bity v temp0	;ENG;unmask to remain only low nonshifted bits in temp0
		or	temp1,temp0		;a zluc posunutu a neposunutu cast	;ENG;and put together shifted and nonshifted part
		st	Y,temp1			;a nahraj spat	;ENG;and store back
		ret				;a skonci	;ENG;and finish
;------------------------------------------------------------------------------------------
MirrorInBufferBytes:
		push	USBBufptrY
		push	ByteCount
		ldi	USBBufptrY,InputBufferBegin
		rcall	MirrorBufferBytes
		pop	ByteCount
		pop	USBBufptrY
		ret
;------------------------------------------------------------------------------------------
MirrorBufferBytes:
		add	ByteCount,USBBufptrY	;ByteCount ukazuje na koniec spravy	;ENG;ByteCount shows to the end of message
MirrorBufferloop:
		ld	temp0,Y			;nahraj prijaty byte z buffera	;ENG;load received byte from buffer
		ldi	temp1,8			;pocitadlo bitov	;ENG;bits counter
MirrorBufferByteLoop:
		ror	temp0			;do carry dalsi najnizsi bit	;ENG;to carry next least bit
		rol	temp2			;z carry dalsi bit na obratene poradie	;ENG;from carry next bit to reverse order
		dec	temp1			;bol uz cely byte	;ENG;was already entire byte
		brne	MirrorBufferByteLoop	;ak nie tak opakuj dalsi najnizsi bit	;ENG;if no then repeat next least bit
		st	Y+,temp2		;ulozenie spat ako obrateny byte  a zvys pointer do buffera	;ENG;save back as reversed byte  and increment pointer to buffer
		cp	USBBufptrY,ByteCount	;ak este neboli vsetky	;ENG;if not yet been all
		brne	MirrorBufferloop	;tak opakuj	;ENG;then repeat
		ret				;inak skonci	;ENG;otherwise finish
;------------------------------------------------------------------------------------------
;CheckCRCIn:	;ENG;CheckCRCIn:
;		push	USBBufptrY	;ENG;		kiss	USBBUFPTRY
;		push	ByteCount	;ENG;		kiss	ByteCount
;		ldi	USBBufptrY,InputBuffercompare	;ENG;		ldi	USBBUFPTRY,InputBuffercompare
;		rcall	CheckCRC	;ENG;		rcall	CheckCRC
;		pop	ByteCount	;ENG;		pope	ByteCount
;		pop	USBBufptrY	;ENG;		pope	USBBUFPTRY
;		ret	;ENG;		lip
;------------------------------------------------------------------------------------------
AddCRCOut:
		push	USBBufptrY
		push	ByteCount
		ldi	USBBufptrY,OutputBufferBegin
		rcall	CheckCRC
		com	temp0			;negacia CRC	;ENG;negation of CRC
		com	temp1
		st	Y+,temp1		;ulozenie CRC na koniec buffera (najskor MSB)	;ENG;save CRC to the end of buffer (at first MSB)
		st	Y,temp0			;ulozenie CRC na koniec buffera (potom LSB)	;ENG;save CRC to the end of buffer (then LSB)
		dec	USBBufptrY		;pointer na poziciu CRC	;ENG;pointer to CRC position
		ldi	ByteCount,2		;otocit 2 byty CRC	;ENG;reverse bits order in 2 bytes CRC
		rcall	MirrorBufferBytes	;opacne poradie bitov CRC (pri vysielani CRC sa posiela naskor MSB)	;ENG;reverse bits order in CRC (transmiting CRC - MSB first)
		pop	ByteCount
		pop	USBBufptrY
		ret
;------------------------------------------------------------------------------------------
CheckCRC:	;vstup: USBBufptrY = zaciatok spravy	,ByteCount = dlzka spravy	;ENG;input: USBBufptrY = begin of message	,ByteCount = length of message
		add	ByteCount,USBBufptrY	;ByteCount ukazuje na koniec spravy	;ENG;ByteCount points to the end of message
		inc	USBBufptrY		;nastav pointer na zaciatok spravy - vynechat SOP	;ENG;set the pointer to message start - omit SOP
		ld	temp0,Y+		;nahraj PID do temp0	;ENG;load PID to temp0
						;a nastav pointer na zaciatok spravy - vynechat aj PID	;ENG;and set the pointer to start of message - omit also PID
		cpi	temp0,DATA0PID		;ci je DATA0 pole	;ENG;if is DATA0 field
		breq	ComputeDATACRC		;pocitaj CRC16	;ENG;compute CRC16
		cpi	temp0,DATA1PID		;ci je DATA1 pole	;ENG;if is DATA1 field
		brne	CRC16End		;ak nie tak skonci 	;ENG;if no then finish
ComputeDATACRC:
		ser	temp0			;inicializacia zvysku LSB na 0xff	;ENG;initialization of remaider LSB to 0xff
		ser	temp1			;inicializacia zvysku MSB na 0xff			;ENG;initialization of remaider MSB to 0xff
CRC16Loop:
		ld	temp2,Y+		;nahraj spravu do temp2 a zvys pointer do buffera	;ENG;load message to temp2 and increment pointer to buffer
		ldi	temp3,8			;pocitadlo bitov v byte - temp3	;ENG;bits counter in byte - temp3
CRC16LoopByte:
		bst	temp1,7			;do T uloz MSB zvysku (zvysok je iba 16 bitovy - 8 bit vyssieho byte)	;ENG;to T save MSB of remainder (remainder is only 16 bits - 8 bit of higher byte)
		bld	bitcount,0		;do bitcount LSB uloz T - MSB zvysku	;ENG;to bitcount LSB save T - of MSB remainder
		eor	bitcount,temp2		;XOR bitu spravy a bitu zvysku - v LSB bitcount	;ENG;XOR of bit message and bit remainder - in LSB bitcount
		rol	temp0			;posun zvysok dolava - nizsi byte (dva byty - cez carry)	;ENG;shift remainder to the left - low byte (two bytes - through carry)
		rol	temp1			;posun zvysok dolava - vyssi byte (dva byty - cez carry)	;ENG;shift remainder to the left - high byte (two bytes - through carry)
		cbr	temp0,1			;znuluj LSB zvysku	;ENG;znuluj LSB remains
		lsr	temp2			;posun spravu doprava	;ENG;shift message to right
		ror	bitcount		;vysledok XOR-u bitov z LSB do carry	;ENG;result of XOR bits from LSB to carry
		brcc	CRC16NoXOR		;ak je XOR bitu spravy a MSB zvysku = 0 , tak nerob XOR	;ENG;if is XOR bitmessage and MSB of remainder = 0 , then no XOR
		ldi	bitcount,CRC16poly>>8	;do bitcount CRC polynom - vrchny byte	;ENG;to bitcount CRC polynomial - high byte
		eor	temp1,bitcount		;a urob XOR zo zvyskom a CRC polynomom - vrchny byte	;ENG;and make XOR from remains and CRC polynomial - high byte
		ldi	bitcount,CRC16poly	;do bitcount CRC polynom - spodny byte	;ENG;to bitcount CRC polynomial - low byte
		eor	temp0,bitcount		;a urob XOR zo zvyskom a CRC polynomom - spodny byte	;ENG;and make XOR of remainder and CRC polynomial - low byte
CRC16NoXOR:
		dec	temp3			;boli uz vsetky bity v byte	;ENG;were already all bits in byte
		brne	CRC16LoopByte		;ak nie, tak chod na dalsi bit	;ENG;unless, then go to next bit
		cp	USBBufptrY,ByteCount	;bol uz koniec spravy	;ENG;was already end-of-message
		brne	CRC16Loop		;ak nie tak opakuj	;ENG;unless then repeat
CRC16End:
		ret				;inak skonci (v temp0 a temp1 je vysledok)	;ENG;otherwise finish (in temp0 and temp1 is result)
;------------------------------------------------------------------------------------------
LoadDescriptorFromROM:
		lpm				;nahraj z pozicie ROM pointera do R0	;ENG;load from ROM position pointer to R0
		st	Y+,R0			;R0 uloz do buffera a zvys buffer	;ENG;R0 save to buffer and increment buffer
		adiw	ZH:ZL,1			;zvys ukazovatel do ROM	;ENG;increment index to ROM
		dec	ByteCount		;pokial nie su vsetky byty	;ENG;till are not all bytes
		brne	LoadDescriptorFromROM	;tak nahravaj dalej	;ENG;then load next
		rjmp	EndFromRAMROM		;inak skonci	;ENG;otherwise finish
;------------------------------------------------------------------------------------------
LoadDescriptorFromROMZeroInsert:
		lpm				;nahraj z pozicie ROM pointerra do R0	;ENG;load from ROM position pointer to R0
		st	Y+,R0			;R0 uloz do buffera a zvys buffer	;ENG;R0 save to buffer and increment buffer

		bst	RAMread,3		;ak je 3 bit jednotkovy - nebude sa vkladat nula	;ENG;if bit 3 is one - don't insert zero
		brtc	InsertingZero		;inak sa bude vkladat nula	;ENG;otherwise zero will be inserted
		adiw	ZH:ZL,1			;zvys ukazovatel do ROM	;ENG;increment index to ROM
		lpm				;nahraj z pozicie ROM pointerra do R0	;ENG;load from ROM position pointer to R0
		st	Y+,R0			;R0 uloz do buffera a zvys buffer	;ENG;R0 save to buffer and increment buffer
		clt				;a znuluj	;ENG;and clear
		bld	RAMread,3		;treti bit v RAMread - aby sa v dalsom vkladali nuly	;ENG;the third bit in RAMread - for to the next zero insertion will be made
		rjmp	InsertingZeroEnd	;a pokracuj	;ENG;and continue
InsertingZero:
		clr	R0			;na vkladanie nul	;ENG;for insertion of zero
		st	Y+,R0			;nulu uloz do buffera a zvys buffer	;ENG;zero save to buffer and increment buffer
InsertingZeroEnd:
		adiw	ZH:ZL,1			;zvys ukazovatel do ROM	;ENG;increment index to ROM
		subi	ByteCount,2		;pokial nie su vsetky byty	;ENG;till are not all bytes
		brne	LoadDescriptorFromROMZeroInsert	;tak nahravaj dalej	;ENG;then load next
		rjmp	EndFromRAMROM		;inak skonci	;ENG;otherwise finish
;------------------------------------------------------------------------------------------
LoadDescriptorFromSRAM:
		ld	R0,Z			;nahraj z pozicie RAM pointerra do R0	;ENG;load from position RAM pointer to R0
		st	Y+,R0			;R0 uloz do buffera a zvys buffer	;ENG;R0 save to buffer and increment buffer
		adiw	ZH:ZL,1			;zvys ukazovatel do RAM	;ENG;increment index to RAM
		dec	ByteCount		;pokial nie su vsetky byty	;ENG;till are not all bytes
		brne	LoadDescriptorFromSRAM	;tak nahravaj dalej	;ENG;then load next
		rjmp	EndFromRAMROM		;inak skonci	;ENG;otherwise finish
;------------------------------------------------------------------------------------------
LoadDescriptorFromEEPROM:
		out	EEARL,ZL		;nastav adresu EEPROM Lo	;ENG;set the address EEPROM Lo
		out	EEARH,ZH		;nastav adresu EEPROM Hi	;ENG;set the address EEPROM Hi
		sbi	EECR,EERE		;vycitaj EEPROM do registra EEDR	;ENG;read EEPROM to register EEDR
		in	R0,EEDR			;nahraj z EEDR do R0	;ENG;load from EEDR to R0
		st	Y+,R0			;R0 uloz do buffera a zvys buffer	;ENG;R0 save to buffer and increment buffer
		adiw	ZH:ZL,1			;zvys ukazovatel do EEPROM	;ENG;increment index to EEPROM
		dec	ByteCount		;pokial nie su vsetky byty	;ENG;till are not all bytes
		brne	LoadDescriptorFromEEPROM;tak nahravaj dalej	;ENG;then load next
		rjmp	EndFromRAMROM		;inak skonci	;ENG;otherwise finish
;------------------------------------------------------------------------------------------
LoadXXXDescriptor:
		ldi	temp0,SOPbyte			;SOP byte	;ENG;SOP byte
		sts	OutputBufferBegin,temp0		;na zaciatok vysielacieho buffera dat SOP	;ENG;to begin of tramsmiting buffer store SOP
		ldi	ByteCount,8			;8 bytov nahrat	;ENG;8 byte store
		ldi	USBBufptrY,OutputBufferBegin+2	;do vysielacieho buffera	;ENG;to transmitting buffer

		and	RAMread,RAMread			;ci sa bude citat z RAM alebo ROM-ky alebo EEPROM-ky	;ENG;if will be reading from RAM or ROM or EEPROM
		brne	FromRAMorEEPROM			;0=ROM,1=RAM,2=EEPROM,4=ROM s vkladanim nuly	;ENG;0=ROM,1=RAM,2=EEPROM,4=ROM with zero insertion (string)
FromROM:
		rjmp	LoadDescriptorFromROM		;nahrat descriptor z ROM-ky	;ENG;load descriptor from ROM
FromRAMorEEPROM:
		sbrc	RAMread,2			;ak RAMread=4	;ENG;if RAMREAD=4
		rjmp	LoadDescriptorFromROMZeroInsert	;citaj z ROM s vkladanim nuly	;ENG;read from ROM with zero insertion
		sbrc	RAMread,0			;ak RAMread=1	;ENG;if RAMREAD=1
		rjmp	LoadDescriptorFromSRAM		;nahraj data zo SRAM-ky	;ENG;load data from SRAM
		rjmp	LoadDescriptorFromEEPROM	;inak cit

⌨️ 快捷键说明

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