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

📄 usb.asm

📁 老外个人做的MP3/优盘。使用ATMEL MEGA系列的MCU
💻 ASM
字号:
/* ***********************************************************************
**
**  Copyright (C) 2002  Jesper Hansen <jesperh@telia.com> and 
**			Romuald Bialy (MIS) <romek_b@o2.pl>.
**
**
**  Yampp-3/USB - low level support library
**
**
*************************************************************************
**
**   This file is part of the yampp system.
**
**  This program is free software; you can redistribute it and/or
**  modify it under the terms of the GNU General Public License
**  as published by the Free Software Foundation; either version 2
**  of the License, or (at your option) any later version.
**
**  This program is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU General Public License for more details.
**
**  You should have received a copy of the GNU General Public License
**  along with this program; if not, write to the Free Software Foundation, 
**  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
**
*************************************************************************
**
**  Revision History
**
**  when         what  who	why
**
**  2002-09-01   1.0   MIS      initial public release
**
*********************************************************************** */

#define __ASSEMBLER__ 1
#define __SFR_OFFSET 0
#include <avr/io.h>
//#include <io-avr.h>

#define __tmp_reg__		r0
#define __zero_reg__	r1

#define USB_ASM
#include "usb.h"



;void usb_init(void);
	.global usb_init
usb_init:
		cbi		USB_PORT-1,USB_TXRDY		; set as input
		cbi		USB_PORT-1,USB_RXRDY		; set as input
		ret

;u08 usb_readbyte(void);
	.global usb_readbyte
usb_readbyte:
		sbic 	USB_PORT-2,USB_RXRDY		; while flag is set
 		rjmp 	usb_readbyte				; wait for bit to be cleared

  		ldi 	r31,hi8(USB_ADDR)
 		ldi 	r30,lo8(USB_ADDR)
		
 		ld		r24,Z
		clr		r25

		ret

;					r24
;void usb_writebyte(u08 b);
	.global usb_writebyte
usb_writebyte:
		sbic 	USB_PORT-2,USB_TXRDY	; while flag is set
 		rjmp 	usb_writebyte			; wait for bit to be cleared

  		ldi 	r31,hi8(USB_ADDR)
 		ldi 	r30,lo8(USB_ADDR)
 		
 		st		Z,r24
 		
		ret
		
;					r25/r24		r23/r22
;u08 usb_readblock(u08* ptr, u16 length);
	.global usb_readblock
usb_readblock:
		push	r28
		push	r29
		
		movw	r30,r24		; pointer to Z
		movw	r26,r22		; count to X
		
  		ldi 	r29,hi8(USB_ADDR)
 		ldi 	r28,lo8(USB_ADDR)	; USB access in Y
usb_rb2:
		sbic 	USB_PORT-2,USB_RXRDY	; while flag is set
 		rjmp 	usb_rb2					; wait for bit to be cleared

		ld		r24,Y		; get USB byte
		st		Z+,r24		; store in RAM
		sbiw	r26,1		; dec count
		brne	usb_rb2		; loop
		
		pop		r29
		pop		r28
		
		ret


;					r25/r24		r23/r22
;u08 usb_writeblock(u08* ptr, u16 length);
	.global usb_writeblock
usb_writeblock:
		push	r28
		push	r29

		mov		r31,r25
		mov		r30,r24		; pointer to Z
		
		mov		r27,r23
		mov		r26,r22		; count to X
		
  		ldi 	r29,hi8(USB_ADDR)
 		ldi 	r28,lo8(USB_ADDR)	; USB access in Y

usb_wr2:
		sbic 	USB_PORT-2,USB_TXRDY	; while flag is set
 		rjmp 	usb_wr2					; wait for bit to be cleared

		ld		r25,Z+		; read from RAM
		st		Y,r25		; send byte to USB
		
		sbiw	r26,1		; dec loop
		brne	usb_wr2
		
		pop		r29
		pop		r28

		ret

⌨️ 快捷键说明

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