📄 leson2.s
字号:
.module leson2.c
.area text(rom, con, rel)
.dbfile F:\lesson\leson2.c
.dbfunc e WDT_off _WDT_off fV
.even
_WDT_off::
.dbline -1
.dbline 12
; #include <io2313v.h>
; #include <macros.h>
; #define uint unsigned int
; #define uchar unsigned char
; //#define LED_SET PORTD |= (1 << PD5) //位置高
; //#define LED_CLR PORTD &= ~(1 << PD5) //位置低
; //#define LED_COM PORTD ^= (1 << PD5) //位取反
; //#define LED_R PIND & (1 << PD5) //位读取
;
;
; void WDT_off(void)
; {
.dbline 16
; //__disable_interrupt();
; //__watchdog_reset();
; //#asm("cli");
; SREG &= ~(1 << (SREG&0x80));
in R17,0x3f
andi R17,128
ldi R16,1
rcall lsl8
mov R2,R16
com R2
in R3,0x3f
and R3,R2
out 0x3f,R3
.dbline 18
; // Clear WDRF in MCUSR
; MCUSR &= ~(1<<(MCUSR&0x08));
in R17,0x34
andi R17,8
ldi R16,1
rcall lsl8
mov R2,R16
com R2
in R3,0x34
and R3,R2
out 0x34,R3
.dbline 21
; // Write logical one to WDCE and WDE
; // Keep old prescaler setting to prevent unintentional time-out
; WDTCSR |= (1<<(WDTCSR&0x10)) | (1<<(WDTCSR&0x08));
in R17,0x21
andi R17,8
ldi R16,1
rcall lsl8
mov R2,R16
in R17,0x21
andi R17,16
ldi R16,1
rcall lsl8
mov R3,R16
or R3,R2
in R2,0x21
or R2,R3
out 0x21,R2
.dbline 23
; // Turn off WDT
; WDTCSR = 0x00;
clr R2
out 0x21,R2
.dbline 24
; SREG |= (1 << (SREG&0x80));
in R17,0x3f
andi R17,128
ldi R16,1
rcall lsl8
in R2,0x3f
or R2,R16
out 0x3f,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e USART_Init _USART_Init fV
; baud -> R20,R21
.even
_USART_Init::
rcall push_gset1
mov R20,R16
mov R21,R17
.dbline -1
.dbline 30
; //#asm("sei");
; //__enable_interrupt();
; }
;
; void USART_Init(unsigned int baud)
; {
.dbline 32
; /* Set baud rate */
; UBRRH = (unsigned char)(baud>>8);
mov R2,R20
mov R3,R21
mov R2,R3
clr R3
out 0x2,R2
.dbline 33
; UBRRL = (unsigned char)baud;
out 0x9,R20
.dbline 35
; /* Enable receiver and transmitter */
; UCSRB = (1<<(UCSRB&0x10))|(1<<(UCSRB&0x08));
in R17,0xa
andi R17,8
ldi R16,1
rcall lsl8
mov R2,R16
in R17,0xa
andi R17,16
ldi R16,1
rcall lsl8
mov R3,R16
or R3,R2
out 0xa,R3
.dbline 37
; /* Set frame format: 8data, 2stop bit */
; UCSRC = (1<<(UCSRC&0x08))|(3<<(UCSRC&0x02));
in R17,0x3
andi R17,2
ldi R16,3
rcall lsl8
mov R2,R16
in R17,0x3
andi R17,8
ldi R16,1
rcall lsl8
mov R3,R16
or R3,R2
out 0x3,R3
.dbline -2
L2:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r baud 20 i
.dbend
.dbfunc e USART_Transmit _USART_Transmit fV
; data -> R20
.even
_USART_Transmit::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 43
; //U2X=0;
; }
;
;
; void USART_Transmit( unsigned char data )
; {
L4:
.dbline 45
L5:
.dbline 45
; /* Wait for empty transmit buffer */
; while ( !( UCSRA & (1<<(UCSRA&0x20))) );
in R17,0xb
andi R17,32
ldi R16,1
rcall lsl8
in R2,0xb
and R2,R16
breq L4
.dbline 47
; /* Put data into buffer, sends the data */
; UDR = data; //Transmit 8 data bits
out 0xc,R20
.dbline -2
L3:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e USART_Receive _USART_Receive fc
.even
_USART_Receive::
.dbline -1
.dbline 66
; }
;
; /*
; void USART_Transmit( unsigned int data )
; {
; //Wait for empty transmit buffer
; while (!( UCSRA & (1<<UDRE)));
; // Copy 9th bit to TXB8
; UCSRB &= ~(1<<TXB8);
; if ( data & 0x0100 )
; UCSRB |= (1<<TXB8);
; // Put data into buffer, sends the data
; UDR = data; //Transmit 9 data bits
; }
; */
;
;
; unsigned char USART_Receive( void )
; {
L8:
.dbline 68
L9:
.dbline 68
; // Wait for data to be received
; while ( !(UCSRA & (1<<(UCSRA&0x80))) );
in R17,0xb
andi R17,128
ldi R16,1
rcall lsl8
in R2,0xb
and R2,R16
breq L8
.dbline 70
; //Get and return received data from buffer
; return UDR; //Receive 8 data bits
in R16,0xc
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay _delay fV
; i -> R20,R21
; j -> R22,R23
; ms -> R16,R17
.even
_delay::
rcall push_gset2
.dbline -1
.dbline 94
; }
;
; /*
; unsigned int USART_Receive( void )
; {
; unsigned char status, resh, resl;
; // Wait for data to be received
; while ( !(UCSRA & (1<<RXC)) );
; // Get status and 9th bit, then data
; // from buffer
; status = UCSRA;
; resh = UCSRB;
; resl = UDR;
; // If error, return -1
; if ( status & (1<<FE)|(1<<DOR)|(1<<UPE) )
; return -1;
; // Filter the 9th bit, then return
; resh = (resh >> 1) & 0x01;
; return ((resh << 8) | resl); //Receive 9 data bits
; }
; */
;
; void delay(uint ms)
; {
.dbline 96
; uint i,j;
; for(i=0;i<ms;i++)
clr R20
clr R21
rjmp L15
L12:
.dbline 97
; {
.dbline 98
clr R22
clr R23
rjmp L19
L16:
.dbline 98
L17:
.dbline 98
subi R22,255 ; offset = 1
sbci R23,255
L19:
.dbline 98
cpi R22,117
ldi R30,4
cpc R23,R30
brlo L16
.dbline 99
L13:
.dbline 96
subi R20,255 ; offset = 1
sbci R21,255
L15:
.dbline 96
cp R20,R16
cpc R21,R17
brlo L12
.dbline -2
L11:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r j 22 i
.dbsym r ms 16 i
.dbend
.dbfunc e senddata _senddata fV
; i -> R20
; data -> R22,R23
.even
_senddata::
rcall push_gset2
mov R22,R16
mov R23,R17
.dbline -1
.dbline 103
; for(j=0;j<1141;j++);
; }
; }
;
; void senddata(uint data)
; {
.dbline 105
; uchar i;
; for(i=0;i<15;i++)
clr R20
rjmp L24
L21:
.dbline 106
; {
.dbline 107
; PORTD&=~(1<<(PORTD&0x10));
in R17,0x12
andi R17,16
ldi R16,1
rcall lsl8
mov R2,R16
com R2
in R3,0x12
and R3,R2
out 0x12,R3
.dbline 108
; NOP();
nop
.dbline 109
; if(data&0x8000)
sbrs R23,7
rjmp L25
.dbline 110
; PORTD|=(1<<(PORTD&0x20)); //置位操作
in R17,0x12
andi R17,32
ldi R16,1
rcall lsl8
in R2,0x12
or R2,R16
out 0x12,R2
rjmp L26
L25:
.dbline 112
; else
; PORTD&=~(1<<(PORTD&0x20)); //清零操作
in R17,0x12
andi R17,32
ldi R16,1
rcall lsl8
mov R2,R16
com R2
in R3,0x12
and R3,R2
out 0x12,R3
L26:
.dbline 114
in R17,0x12
andi R17,16
ldi R16,1
rcall lsl8
in R2,0x12
or R2,R16
out 0x12,R2
.dbline 115
nop
.dbline 116
lsl R22
rol R23
.dbline 117
L22:
.dbline 105
inc R20
L24:
.dbline 105
cpi R20,15
brlo L21
.dbline 118
;
; PORTD|=(1<<(PORTD&0x10));
; NOP();
; data=data<<1;
; }
; PORTD|=(1<<(PORTD&0x08));
in R17,0x12
andi R17,8
ldi R16,1
rcall lsl8
in R2,0x12
or R2,R16
out 0x12,R2
.dbline 119
; NOP();
nop
.dbline 120
; NOP();
nop
.dbline 121
; NOP();
nop
.dbline 122
; PORTD&=~(1<<(PORTD&0x08));
in R17,0x12
andi R17,8
ldi R16,1
rcall lsl8
mov R2,R16
com R2
in R3,0x12
and R3,R2
out 0x12,R3
.dbline -2
L20:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r data 22 i
.dbend
.dbfunc e main _main fV
; k -> R20,R21
; i -> R10
; j -> R22,R23
.even
_main::
.dbline -1
.dbline 130
;
;
; //PORTD|=(1<<PORTD5); //置位操作
; //PORTD&=~(1<<PORTD5); //清零操作
; }
;
; void main()
; {
.dbline 132
; uchar i;
; uint j=0x0001;
ldi R22,1
ldi R23,0
.dbline 133
; uint k=0x7fff;
ldi R20,32767
ldi R21,127
.dbline 135
;
; DDRD=0x38;
ldi R24,56
out 0x11,R24
.dbline 137
;
; WDT_off();
rcall _WDT_off
.dbline 138
; USART_Init(9600);
ldi R16,9600
ldi R17,37
rcall _USART_Init
rjmp L29
L28:
.dbline 141
;
; while(1)
; {
.dbline 143
;
; USART_Transmit(0x55);
ldi R16,85
rcall _USART_Transmit
.dbline 145
;
; for(i=0;i<15;i++)
clr R10
rjmp L34
L31:
.dbline 146
.dbline 147
mov R16,R22
mov R17,R23
rcall _senddata
.dbline 148
ldi R16,200
ldi R17,0
rcall _delay
.dbline 149
lsl R22
rol R23
.dbline 150
subi R22,255 ; offset = 1
sbci R23,255
.dbline 151
L32:
.dbline 145
inc R10
L34:
.dbline 145
mov R24,R10
cpi R24,15
brlo L31
.dbline 153
; {
; senddata(j);
; delay(200);
; j=j<<1;
; j=j+1;
; }
;
; for(i=0;i<15;i++)
clr R10
rjmp L38
L35:
.dbline 154
.dbline 155
mov R16,R20
mov R17,R21
rcall _senddata
.dbline 156
ldi R16,200
ldi R17,0
rcall _delay
.dbline 157
lsr R21
ror R20
.dbline 158
L36:
.dbline 153
inc R10
L38:
.dbline 153
mov R24,R10
cpi R24,15
brlo L35
.dbline 161
L29:
.dbline 140
rjmp L28
X0:
.dbline -2
L27:
.dbline 0 ; func end
ret
.dbsym r k 20 i
.dbsym r i 10 c
.dbsym r j 22 i
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -