📄 usb.asm
字号:
/* ***********************************************************************
**
** Copyright (C) 2002 Jesper Hansen <jesperh@telia.com> and
** Romuald Bialy (MIS) <romek_b@o2.pl>.
**
**
** Yampp-7/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-22 1.0 MIS initial public release
**
*********************************************************************** */
#define __ASSEMBLER__ 1
#define __SFR_OFFSET 0
#include <avr/io.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_DDR,USB_TXRDY ; set as input
cbi USB_DDR,USB_RXRDY ; set as input
ret
;u08 usb_readbyte(void);
.global usb_readbyte
usb_readbyte:
sbic USB_PIN,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_PIN,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:
clr r25
clr r24
usb_rb3:
sbiw r24,1
breq usb_timeout
sbic USB_PIN,USB_RXRDY ; while flag is set
rjmp usb_rb3 ; 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
usb_timeout: 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_PIN,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 + -