📄 interface.s
字号:
.module interface.c
.area text(rom, con, rel)
.dbfile E:\单片机\源程序\Snail_mkII\STK500_V2\ICC\interface.c
.dbfunc e interface_init _interface_init fV
.even
_interface_init::
.dbline -1
.dbline 95
; /** \file
; <b>USB receive and transmit</b><br>
; Autor: Matthias Wei遝r<br>
; Copyright 2005: Matthias Wei遝r<br>
; License: QPL (see license.txt)
; <hr>
; */
;
; #include <iccioavr.h>
; #include "tools.h"
; #include "interface.h"
;
; #include "config.h"
;
; unsigned char checksum;
;
; #ifdef CONFIG_INTERFACE_USB
;
; //Hardware
; #define USB_TXE (PINB&BIT6_POS)
; #define USB_RXF (PINC&BIT3_POS)
; #define USB_RD_ON PORTC&=BIT1_NEG
; #define USB_RD_OFF PORTC|=BIT1_POS
; #define USB_WR_ON PORTC|=BIT2_POS
; #define USB_WR_OFF PORTC&=BIT2_NEG
;
; /**
; Initializes the usb interface
; */
; void interface_init(void)
; {
; PORTC |= BIT1_POS; //USB_RD inactive
; DDRC |= BIT1_POS|BIT2_POS; //USB_RD, USB_WR as output
; }
;
; /**
; Reads a byte from the USB interface
;
; @return received character or -1 if no character has been received
; */
; signed int interface_getc(void)
; {
; unsigned char t;
;
; if (!USB_RXF)
; {
; USB_RD_ON;
; asm("NOP");
; t = PIND;
; USB_RD_OFF;
;
; return t;
; }
; else return -1;
; }
;
; /**
; Writes a byte to the USB
;
; @param t Byte to be written
; */
; void interface_putc(unsigned char t)
; {
; while (USB_TXE);
;
; //PORTD auf Ausgang
; DDRD = 0xFF;
; //Daten auf den Port
; PORTD = t;
;
; USB_WR_ON;
; USB_WR_OFF;
;
; //PORTC auf Eingang
; DDRD = 0x00;
; //Pull-Ups ein
; PORTD = 0xFF;
;
; checksum ^= t;
; }
;
; #endif
;
; #ifdef CONFIG_INTERFACE_RS232
;
; #define USART_BAUD_RATE 115200
; #define USART_BAUD_SELECT (F_CPU/(USART_BAUD_RATE*16l)-1)
;
; /**
; Initializes the rs232 interface
;
; Autor: Lukas Salzburger
; */
; void interface_init(void)
; {
.dbline 96
; UCSRB = (1<<RXEN) | (1<<TXEN);
ldi R24,24
out 0xa,R24
.dbline 97
; UBRRL = (unsigned char) USART_BAUD_SELECT;
ldi R24,7
out 0x9,R24
.dbline 98
; UBRRH = (unsigned char) (USART_BAUD_SELECT>>8);
clr R2
out 0x20,R2
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e interface_getc _interface_getc fI
.even
_interface_getc::
.dbline -1
.dbline 109
; }
;
; /**
; Reads a byte from the UART interface
;
; Autor: Lukas Salzburger
;
; @return received character or -1 if no character has been received
; */
; signed int interface_getc(void)
; {
.dbline 111
;
; if (UCSRA & (1<<RXC))
sbis 0xb,7
rjmp L4
X0:
.dbline 112
; {
.dbline 113
; return UDR;
in R16,0xc
clr R17
xjmp L3
L4:
.dbline 115
; }
; else return -1;
ldi R16,-1
ldi R17,-1
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbend
.dbfunc e interface_putc _interface_putc fV
; t -> R16
.even
_interface_putc::
.dbline -1
.dbline 126
; }
;
; /**
; Writes a byte to the UART
;
; Autor: Lukas Salzburger
;
; @param t Byte to be written
; */
; void interface_putc(unsigned char t)
; {
L7:
.dbline 128
;
; while (!(UCSRA & (1<<UDRE)));
L8:
.dbline 128
sbis 0xb,5
rjmp L7
X1:
.dbline 130
;
; UDR = t;
out 0xc,R16
.dbline 131
; checksum ^= t;
lds R2,_checksum
eor R2,R16
sts _checksum,R2
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbsym r t 16 c
.dbend
.dbfunc e interface_print _interface_print fV
; s -> R20,R21
.even
_interface_print::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 142
; }
;
; #endif
;
; /**
; Writes a string to USB
;
; @param s The string to be send
; */
; void interface_print(unsigned char *s)
; {
xjmp L12
L11:
.dbline 144
; while (*s)
; {
.dbline 145
; interface_putc(*s);
movw R30,R20
ldd R16,z+0
xcall _interface_putc
.dbline 146
; s++;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 147
; }
L12:
.dbline 143
movw R30,R20
ldd R2,z+0
tst R2
brne L11
X2:
.dbline -2
L10:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r s 20 pc
.dbend
.dbfunc e interface_put16 _interface_put16 fV
; t -> R20,R21
.even
_interface_put16::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 157
; }
;
; /**
; Sends a 16 bit value over the USB
; MSB first
;
; @param t Value to be send
; */
; void interface_put16(unsigned int t)
; {
.dbline 158
; interface_putc((t>>8)&0xFF);
movw R16,R20
mov R16,R17
clr R17
andi R17,0
xcall _interface_putc
.dbline 159
; interface_putc((t>>0)&0xFF);
movw R16,R20
andi R17,0
xcall _interface_putc
.dbline -2
L14:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r t 20 i
.dbend
.dbfunc e interface_reset_check _interface_reset_check fV
.even
_interface_reset_check::
.dbline -1
.dbline 166
; }
;
; /**
; Resets the checksum accumulator
; */
; void interface_reset_check(void)
; {
.dbline 167
; checksum=0;
clr R2
sts _checksum,R2
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e interface_send_check _interface_send_check fV
.even
_interface_send_check::
.dbline -1
.dbline 174
; }
;
; /**
; Sends the accumulated checksum
; */
; void interface_send_check(void)
; {
.dbline 175
; interface_putc(checksum);
lds R16,_checksum
xcall _interface_putc
.dbline 176
; checksum=0;
clr R2
sts _checksum,R2
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile E:\单片机\源程序\Snail_mkII\STK500_V2\ICC\interface.c
_checksum::
.blkb 1
.dbsym e checksum _checksum c
; }
;
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -