📄 testuart.s
字号:
.module testuart.c
.area text(rom, con, rel)
.dbfile D:\avr_prm\testuart.c
.dbfunc e getcrc _getcrc fS
; j -> R22,R23
; i -> R22,R23
; acc -> R20,R21
; len -> R18,R19
; s -> R16,R17
.even
_getcrc::
xcall push_gset2
.dbline -1
.dbline 38
; //ICC-AVR application builder : 2006-7-17 15:54:53
; // Target : M16
; // Crystal: 1.0000Mhz
;
; #include <iom16v.h>
; #include <macros.h>
;
; //定义MCU与LCD的接口
; #define LCD_EN_PORT PORTB
; #define LCD_RW_PORT PORTB
; #define LCD_RS_PORT PORTB
; #define LCD_DATA_PORT PORTA
; #define LCD_DATA_DDR DDRA
; #define LCD_DATA_PIN PINA
;
; //定义ms7512b与MCU的接口
; #define MS7512B_RS_PORT PORTC
; #define MS7512B_MOD1_PORT PORTC
; //#define MS7512B_MOD2_PORT PORTC
; //定义发送判断接口
; #define SWITCH_PORT PORTB
; //定义LED控制口
; #define LED_CONTROL_PORT PORTD
; //定义LCD键盘控制口
; #define LCD_KEY_PORT PORTD
;
; #define LCD_KEY 0x40 //portd6 in
; #define LED_CONTROL 0x80 //portd7 out
; #define MS7512B_MOD1 0x01 //portc0 out
; //#define MS7512B_MOD2 0x02 //portc1 out
; #define MS7512B_RS 0x02 //portc1 out
; #define SWITCH_EN 0x10 //portB4 in
; #define LCD_EN 0x01 //portB0 out
; #define LCD_RW 0x02 //portB1 out/in
; #define LCD_RS 0x04 //portB2 out
; #define LCD_DATA 0xf0 //portA4/5/6/7 out
; short getcrc(unsigned char *s, short len)
; {
.dbline 39
; short acc=0,i,j=0;
clr R20
clr R21
.dbline 39
clr R22
clr R23
xjmp L3
L2:
.dbline 41
; while(len--)
; {
.dbline 42
; acc=acc^(*s++<<8);
movw R30,R16
ld R2,Z+
movw R16,R30
clr R3
mov R3,R2
clr R2
eor R20,R2
eor R21,R3
.dbline 43
; for(i=0;i++<8;)
clr R22
clr R23
xjmp L8
L5:
.dbline 44
; if(acc&0x8000)
sbrs R21,7
rjmp L9
.dbline 45
; acc=(acc<<1)^0x1021;
ldi R24,4129
ldi R25,16
movw R2,R20
lsl R2
rol R3
eor R2,R24
eor R3,R25
movw R20,R2
xjmp L10
L9:
.dbline 47
; else
; acc=acc<<1;
lsl R20
rol R21
L10:
L6:
.dbline 43
L8:
.dbline 43
movw R2,R22
subi R22,255 ; offset = 1
sbci R23,255
movw R24,R2
cpi R24,8
ldi R30,0
cpc R25,R30
brlt L5
.dbline 48
L3:
.dbline 40
movw R2,R18
subi R18,1
sbci R19,0
tst R2
brne L2
tst R3
brne L2
X0:
.dbline 49
; }
; return(acc);
movw R16,R20
.dbline -2
L1:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r j 22 S
.dbsym r i 22 S
.dbsym r acc 20 S
.dbsym r len 18 S
.dbsym r s 16 pc
.dbend
.dbfunc e makecrc _makecrc fV
; crcin -> R10,R11
; len -> R22,R23
; s -> R20,R21
.even
_makecrc::
xcall push_gset3
movw R22,R18
movw R20,R16
.dbline -1
.dbline 52
; }
; void makecrc(unsigned char *s,int len)
; {
.dbline 54
; short crcin;
; crcin = getcrc(s,len);
movw R18,R22
movw R16,R20
xcall _getcrc
movw R10,R16
.dbline 55
; s[len]=crcin>>8;
movw R30,R22
add R30,R20
adc R31,R21
movw R2,R10
mov R2,R3
clr R3
sbrc R2,7
com R3
std z+0,R2
.dbline 56
; s[len+1]=crcin%256;
ldi R18,256
ldi R19,1
xcall mod16s
movw R30,R22
add R30,R20
adc R31,R21
std z+1,R16
.dbline -2
L11:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r crcin 10 S
.dbsym r len 22 I
.dbsym r s 20 pc
.dbend
.dbfunc e checkcrc _checkcrc fI
; crcin -> R20,R21
; len -> R10,R11
; s -> R22,R23
.even
_checkcrc::
xcall push_gset3
movw R10,R18
movw R22,R16
.dbline -1
.dbline 61
;
; }
;
; int checkcrc(unsigned char *s,int len)
; {
.dbline 63
; short crcin;
; crcin= getcrc(s,len);
movw R18,R10
movw R16,R22
xcall _getcrc
movw R20,R16
.dbline 64
; if(((0xffff&crcin)==((0xffff&(s[len]<<8))+(0xff&(s[len+1])))))
movw R2,R10
add R2,R22
adc R3,R23
movw R30,R2
ldd R24,z+1
clr R25
andi R25,0
movw R30,R2
ldd R2,z+0
clr R3
mov R3,R2
clr R2
add R2,R24
adc R3,R25
cp R16,R2
cpc R17,R3
brne L13
.dbline 65
; return (1);
ldi R16,1
ldi R17,0
xjmp L12
L13:
.dbline 66
; else return (0);
clr R16
clr R17
.dbline -2
L12:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r crcin 20 S
.dbsym r len 10 I
.dbsym r s 22 pc
.dbend
.dbfunc e delay_nus _delay_nus fV
; i -> R20,R21
; n -> R16,R17
.even
_delay_nus::
xcall push_gset1
.dbline -1
.dbline 71
;
; }
;
; void delay_nus(unsigned int n)//n微秒延时函数
; {
.dbline 73
; unsigned int i;
; for (i=0;i<n;i++)
clr R20
clr R21
xjmp L19
L16:
.dbline 74
.dbline 75
nop
.dbline 76
L17:
.dbline 73
subi R20,255 ; offset = 1
sbci R21,255
L19:
.dbline 73
cp R20,R16
cpc R21,R17
brlo L16
.dbline -2
L15:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 16 i
.dbend
.dbfunc e delay_hus _delay_hus fV
; i -> R20,R21
; j -> R22,R23
; n -> R16,R17
.even
_delay_hus::
xcall push_gset2
.dbline -1
.dbline 80
; {
; asm("nop");
; }
; }
;
; void delay_hus(unsigned int n)//n毫秒
; {
.dbline 83
; unsigned int i;
; unsigned int j;
; for (i=0;i<n;i++)
clr R20
clr R21
xjmp L24
L21:
.dbline 84
; {
.dbline 85
; for(j=0;j<1000;j++)
clr R22
clr R23
xjmp L28
L25:
.dbline 86
nop
L26:
.dbline 85
subi R22,255 ; offset = 1
sbci R23,255
L28:
.dbline 85
cpi R22,232
ldi R30,3
cpc R23,R30
brlo L25
.dbline 87
L22:
.dbline 83
subi R20,255 ; offset = 1
sbci R21,255
L24:
.dbline 83
cp R20,R16
cpc R21,R17
brlo L21
.dbline -2
L20:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r j 22 i
.dbsym r n 16 i
.dbend
.dbfunc e USART_Transmit _USART_Transmit fV
; data -> R16
.even
_USART_Transmit::
.dbline -1
.dbline 92
; asm("nop");
; }
; }
;
;
; void USART_Transmit(unsigned char data)
; {
L30:
.dbline 93
L31:
.dbline 93
; while(!(UCSRA&(1<<UDRE)));
sbis 0xb,5
rjmp L30
.dbline 95
; //PORTD=0x00;
; UDR=data;
out 0xc,R16
.dbline -2
L29:
.dbline 0 ; func end
ret
.dbsym r data 16 c
.dbend
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 99
; }
;
; void port_init(void)
; {
.dbline 100
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 101
; DDRA = 0x00;
out 0x1a,R2
.dbline 102
; PORTB=0xFF; //与下一句同时起作用
ldi R24,255
out 0x18,R24
.dbline 104
; //SFIOR&=~BIT(2); //置SFIOR的PDU上拉电阻有效。与上一句一起生效。
; SFIOR&=~BIT(2); //置SFIOR的PDU上拉电阻有效。与上一句一起生效。
in R24,0x30
andi R24,251
out 0x30,R24
.dbline 105
; DDRB = 0x00;
out 0x17,R2
.dbline 106
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 107
; DDRC = 0x00;
out 0x14,R2
.dbline 110
; //PORTD = 0x80;
; // DDRD = 0x80;
; PORTD=0xc0; //与下一句同时起作用
ldi R24,192
out 0x12,R24
.dbline 112
; //SFIOR&=~BIT(2); //置SFIOR的PDU上拉电阻有效。与上一句一起生效。
; SFIOR&=~BIT(2); //置SFIOR的PDU上拉电阻有效。与上一句一起生效
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -