📄 uart3.s
字号:
.module uart3.c
.area text(rom, con, rel)
.dbfile E:\item\GPS-1280\uart3.c
.dbfunc e uart3_register_init _uart3_register_init fV
.even
_uart3_register_init::
.dbline -1
.dbline 12
; #include <iom1280v.h>
; #include <macros.h>
; #include "define.h"
; #include "gps.h"
;
; uart uart3;
;
; uchar uart3_recv_buf[1000];
;
; //-------------------------------------------------------------
; void uart3_register_init(void)
; {
.dbline 14
; //U2X3=1
; UCSR3A=(1<<U2X3);
ldi R24,2
sts 304,R24
.dbline 16
; //异步模式,数据格式:8位数据位,1位停止位,无奇偶校验
; UCSR3C=( (1<<UCSZ31) | (1<<UCSZ30) );
ldi R24,6
sts 306,R24
.dbline 18
; //Focs=14.7456MHZ baudrate=9600
; UBRR3H=0x00;
clr R2
sts 309,R2
.dbline 19
; UBRR3L=191;
ldi R24,191
sts 308,R24
.dbline 21
; //发送和接收使能
; UCSR3B |=(1<<RXEN3);
lds R24,305
ori R24,16
sts 305,R24
.dbline 22
; UCSR3B |=(1<<TXEN3);
lds R24,305
ori R24,8
sts 305,R24
.dbline 24
; //接收中断使能
; UCSR3B |=(1<<RXCIE3);
lds R24,305
ori R24,128
sts 305,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e uart3_init _uart3_init fV
.even
_uart3_init::
.dbline -1
.dbline 28
; }
; //-------------------------------------------------------------
; void uart3_init(void)
; {
.dbline 29
; uart3_register_init();
xcall _uart3_register_init
.dbline 31
;
; uart3.state = UART_STATE_NULL;
clr R2
sts _uart3,R2
.dbline 32
; uart3.time = UART_TIME;
ldi R24,136
ldi R25,19
ldi R26,0
ldi R27,0
sts _uart3+1+1,R25
sts _uart3+1,R24
sts _uart3+1+2+1,R27
sts _uart3+1+2,R26
.dbline 33
; uart3.last_recv_len = 0;
clr R3
sts _uart3+5+1,R3
sts _uart3+5,R2
.dbline 34
; uart3.recv_len = 0;
sts _uart3+7+1,R3
sts _uart3+7,R2
.dbline 35
; uart3.send_len = 0;
sts _uart3+9+1,R3
sts _uart3+9,R2
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 216
jmp _uart3_rx_isr
.area text(rom, con, rel)
.dbfile E:\item\GPS-1280\uart3.c
.dbfunc e uart3_rx_isr _uart3_rx_isr fV
.even
_uart3_rx_isr::
st -y,R2
st -y,R24
st -y,R25
st -y,R30
st -y,R31
in R2,0x3f
st -y,R2
.dbline -1
.dbline 40
; }
; //-------------------------------------------------------------
; #pragma interrupt_handler uart3_rx_isr:iv_USART3_RXC
; void uart3_rx_isr(void)
; {
.dbline 41
; uart3_recv_buf[uart3.recv_len]=UDR3;
ldi R24,<_uart3_recv_buf
ldi R25,>_uart3_recv_buf
lds R30,_uart3+7
lds R31,_uart3+7+1
add R30,R24
adc R31,R25
lds R2,310
std z+0,R2
.dbline 42
; (uart3.recv_len)++;
lds R24,_uart3+7
lds R25,_uart3+7+1
adiw R24,1
sts _uart3+7+1,R25
sts _uart3+7,R24
.dbline -2
L7:
.dbline 0 ; func end
ld R2,y+
out 0x3f,R2
ld R31,y+
ld R30,y+
ld R25,y+
ld R24,y+
ld R2,y+
reti
.dbend
.dbfunc e uart0_check_rev_data _uart0_check_rev_data fc
.even
_uart0_check_rev_data::
.dbline -1
.dbline 46
; }
; //-------------------------------------------------------------
; bool uart0_check_rev_data(void)
; {
.dbline 47
; if((uart3.last_recv_len) != (uart3.recv_len)){
lds R2,_uart3+7
lds R3,_uart3+7+1
lds R4,_uart3+5
lds R5,_uart3+5+1
cp R4,R2
cpc R5,R3
breq L11
X0:
.dbline 47
.dbline 48
; (uart3.last_recv_len) = (uart3.recv_len);
lds R2,_uart3+7
lds R3,_uart3+7+1
sts _uart3+5+1,R3
sts _uart3+5,R2
.dbline 49
; return true;
ldi R16,1
xjmp L10
L11:
.dbline 51
; }
; return false;
clr R16
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e uart3_function _uart3_function fc
.even
_uart3_function::
xcall push_xgset300C
.dbline -1
.dbline 55
; }
; //-------------------------------------------------------------
; unsigned char uart3_function(void)
; {
.dbline 56
; switch(uart3.state)
lds R20,_uart3
clr R21
cpi R20,0
cpc R20,R21
breq L21
X1:
cpi R20,1
ldi R30,0
cpc R21,R30
breq L26
X2:
cpi R20,2
ldi R30,0
cpc R21,R30
brne X8
xjmp L30
X8:
X3:
cpi R20,3
ldi R30,0
cpc R21,R30
brne X9
xjmp L38
X9:
X4:
xjmp L18
L21:
.dbline 59
; {
; case UART_STATE_NULL:
; uart3.state = UART_STATE_CHECK_RECV;
ldi R24,1
sts _uart3,R24
.dbline 60
; uart3.time = UART_TIME;
ldi R24,136
ldi R25,19
ldi R26,0
ldi R27,0
sts _uart3+1+1,R25
sts _uart3+1,R24
sts _uart3+1+2+1,R27
sts _uart3+1+2,R26
.dbline 61
; uart3.last_recv_len = 0;
clr R2
clr R3
sts _uart3+5+1,R3
sts _uart3+5,R2
.dbline 62
; uart3.recv_len = 0;
sts _uart3+7+1,R3
sts _uart3+7,R2
.dbline 63
; uart3.send_len = 0;
sts _uart3+9+1,R3
sts _uart3+9,R2
.dbline 64
; break;
xjmp L19
L26:
.dbline 67
;
; case UART_STATE_CHECK_RECV:
; if(uart0_check_rev_data()==TRUE){
xcall _uart0_check_rev_data
cpi R16,1
breq X10
xjmp L19
X10:
X5:
.dbline 67
.dbline 68
; uart3.state = UART_STATE_RECVING_DATA;
ldi R24,2
sts _uart3,R24
.dbline 69
; uart3.time = UART_TIME;
ldi R24,136
ldi R25,19
ldi R26,0
ldi R27,0
sts _uart3+1+1,R25
sts _uart3+1,R24
sts _uart3+1+2+1,R27
sts _uart3+1+2,R26
.dbline 70
; }else{
.dbline 70
.dbline 71
; }
.dbline 72
; break;
xjmp L19
L30:
.dbline 75
;
; case UART_STATE_RECVING_DATA:
; if(uart0_check_rev_data()){
xcall _uart0_check_rev_data
tst R16
breq L31
X6:
.dbline 75
.dbline 76
; uart3.time = UART_TIME;
ldi R24,136
ldi R25,19
ldi R26,0
ldi R27,0
sts _uart3+1+1,R25
sts _uart3+1,R24
sts _uart3+1+2+1,R27
sts _uart3+1+2,R26
.dbline 77
; }else{
xjmp L19
L31:
.dbline 77
.dbline 78
; (uart3.time)--;
ldi R24,1
ldi R25,0
ldi R26,0
ldi R27,0
lds R4,_uart3+1+2
lds R5,_uart3+1+2+1
lds R2,_uart3+1
lds R3,_uart3+1+1
sub R2,R24
sbc R3,R25
sbc R4,R26
sbc R5,R27
sts _uart3+1+1,R3
sts _uart3+1,R2
sts _uart3+1+2+1,R5
sts _uart3+1+2,R4
.dbline 79
; if(!(uart3.time)){
clc
tst R2
cpc R3,R2
cpc R4,R2
cpc R5,R2
brne L19
X7:
.dbline 79
.dbline 80
; uart3.state = UART_STATE_DISPOSE_DATA;
ldi R24,3
sts _uart3,R24
.dbline 81
; }
.dbline 82
; }
.dbline 83
; break;
xjmp L19
L38:
.dbline 86
;
; case UART_STATE_DISPOSE_DATA:
; uart3.last_recv_len =0;
clr R2
clr R3
sts _uart3+5+1,R3
sts _uart3+5,R2
.dbline 87
; uart3.state = UART_STATE_NULL;
sts _uart3,R2
.dbline 89
; //add function here
; CLI();
cli
.dbline 90
; gps_function(uart3_recv_buf,uart3.recv_len);
lds R18,_uart3+7
lds R19,_uart3+7+1
ldi R16,<_uart3_recv_buf
ldi R17,>_uart3_recv_buf
xcall _gps_function
.dbline 92
; //set recv lengh zero
; uart3.recv_len = 0;
clr R2
clr R3
sts _uart3+7+1,R3
sts _uart3+7,R2
.dbline 93
; SEI();
sei
.dbline 95
; //uart3.state = UART_STATE_CHECK_RECV;
; break;
xjmp L19
L18:
.dbline 98
;
; default:
; uart3.state = UART_STATE_NULL;
clr R2
sts _uart3,R2
.dbline 99
; break;
L19:
.dbline 101
; }
; return 1;
ldi R16,1
.dbline -2
L17:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbend
.dbfunc e uart3_data_send _uart3_data_send fV
; i -> R20,R21
; sendLen -> R18,R19
; pbuf -> R16,R17
.even
_uart3_data_send::
st -y,R20
st -y,R21
.dbline -1
.dbline 105
; }
; //-------------------------------------------------------------
; void uart3_data_send(unsigned char *pbuf,unsigned int sendLen)
; {
.dbline 107
; unsigned int i;
; for(i=0;i<sendLen;i++)
clr R20
clr R21
xjmp L46
L47:
.dbline 109
; {
; while(!(UCSR3A & (1<<UDRE3))); // 等待发送缓冲寄存器空
L48:
.dbline 109
lds R2,304
sbrs R2,5
rjmp L47
X11:
.dbline 110
; UDR3=* (pbuf+i);
movw R30,R20
add R30,R16
adc R31,R17
ldd R2,z+0
sts 310,R2
.dbline 111
; }
L44:
.dbline 107
subi R20,255 ; offset = 1
sbci R21,255
L46:
.dbline 107
cp R20,R18
cpc R21,R19
brlo L48
X12:
.dbline 112
; return;
.dbline -2
L42:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r i 20 i
.dbsym r sendLen 18 i
.dbsym r pbuf 16 pc
.dbend
.dbfunc e uart3_send_char _uart3_send_char fV
; c -> R16
.even
_uart3_send_char::
.dbline -1
.dbline 116
; }
; //-------------------------------------------------------------
; void uart3_send_char(unsigned char c)
; {
L51:
.dbline 117
; while(!(UCSR3A & (1<<UDRE3))); // 等待发送缓冲寄存器空
L52:
.dbline 117
lds R2,304
sbrs R2,5
rjmp L51
X13:
.dbline 118
; UDR3=c;
sts 310,R16
.dbline 119
; return;
.dbline -2
L50:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.area bss(ram, con, rel)
.dbfile E:\item\GPS-1280\uart3.c
_uart3_recv_buf::
.blkb 1000
.dbsym e uart3_recv_buf _uart3_recv_buf A[1000:1000]c
_uart3::
.blkb 11
.dbstruct 0 11 _uart
.dbfield 0 state c
.dbfield 1 time l
.dbfield 5 last_recv_len i
.dbfield 7 recv_len i
.dbfield 9 send_len i
.dbend
.dbsym e uart3 _uart3 S[_uart]
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -