📄 spi_slave.lis
字号:
.module SPI_slave.c
.area text(rom, con, rel)
0000 .dbfile F:\IccAvr_Pro\SPI_slave.c
.area vector(rom, abs)
.org 40
0028 0C940000 jmp _spi_stc_isr
.area text(rom, con, rel)
0000 .dbfunc e spi_stc_isr _spi_stc_isr fV
.even
0000 _spi_stc_isr::
0000 2A92 st -y,R2
0002 3A92 st -y,R3
0004 0A93 st -y,R16
0006 1A93 st -y,R17
0008 8A93 st -y,R24
000A 9A93 st -y,R25
000C EA93 st -y,R30
000E FA93 st -y,R31
0010 2FB6 in R2,0x3f
0012 2A92 st -y,R2
0014 .dbline -1
0014 .dbline 15
0014 ;
0014 ; #include "SPI_slave.h"
0014 ; #include "qep.h"
0014 ; unsigned char SPI_rx_buf[SPI_size];
0014 ; unsigned char SPI_tx_buf[SPI_size];
0014 ; unsigned char rx_index;
0014 ; unsigned char tx_index,SPI_tx_flag,SPI_rx_flag;
0014 ; unsigned char temp;
0014 ; extern int qep_cnt[QEP_size];
0014 ; extern unsigned char pwm_value[2];
0014 ; extern unsigned char pwm_flag;
0014 ;
0014 ; #pragma interrupt_handler spi_stc_isr:11
0014 ; void spi_stc_isr(void)
0014 ; {
0014 .dbline 17
0014 ;
0014 ; if(SPI_tx_flag)
0014 20900200 lds R2,_SPI_tx_flag
0018 2220 tst R2
001A 81F0 breq L2
001C .dbline 18
001C ; {
001C .dbline 19
001C ; SPDR=SPI_tx_buf[tx_index++];
001C 20900300 lds R2,_tx_index
0020 3324 clr R3
0022 822D mov R24,R2
0024 8F5F subi R24,255 ; addi 1
0026 80930300 sts _tx_index,R24
002A 80E0 ldi R24,<_SPI_tx_buf
002C 90E0 ldi R25,>_SPI_tx_buf
002E E22D mov R30,R2
0030 FF27 clr R31
0032 E80F add R30,R24
0034 F91F adc R31,R25
0036 2080 ldd R2,z+0
0038 2FB8 out 0xf,R2
003A .dbline 20
003A ; }
003A 02C0 xjmp L3
003C L2:
003C .dbline 21
003C ; else SPDR=0xee;
003C 8EEE ldi R24,238
003E 8FB9 out 0xf,R24
0040 L3:
0040 .dbline 23
0040 ;
0040 ; temp=SPDR;
0040 2FB0 in R2,0xf
0042 20920000 sts _temp,R2
0046 .dbline 24
0046 ; if(temp==0xaa||temp==0x55)
0046 822D mov R24,R2
0048 8A3A cpi R24,170
004A 11F0 breq L6
004C 8535 cpi R24,85
004E 19F4 brne L4
0050 L6:
0050 .dbline 25
0050 ; SPI_rx_flag=1;
0050 81E0 ldi R24,1
0052 80930100 sts _SPI_rx_flag,R24
0056 L4:
0056 .dbline 27
0056 ;
0056 ; if(tx_index>=SPI_size)
0056 80910300 lds R24,_tx_index
005A 8330 cpi R24,3
005C 28F0 brlo L7
005E .dbline 28
005E ; {
005E .dbline 29
005E ; tx_index=0;
005E 2224 clr R2
0060 20920300 sts _tx_index,R2
0064 .dbline 30
0064 ; SPI_tx_flag=0;
0064 20920200 sts _SPI_tx_flag,R2
0068 .dbline 31
0068 ; }
0068 L7:
0068 .dbline 32
0068 ; if(SPI_rx_flag)
0068 20900100 lds R2,_SPI_rx_flag
006C 2220 tst R2
006E 09F4 brne X3
0070 6EC0 xjmp L9
0072 X3:
0072 .dbline 33
0072 ; {
0072 .dbline 34
0072 ; SPI_rx_buf[rx_index]=temp;
0072 80E0 ldi R24,<_SPI_rx_buf
0074 90E0 ldi R25,>_SPI_rx_buf
0076 E0910400 lds R30,_rx_index
007A FF27 clr R31
007C E80F add R30,R24
007E F91F adc R31,R25
0080 20900000 lds R2,_temp
0084 2082 std z+0,R2
0086 .dbline 35
0086 ; if (rx_index<SPI_size) rx_index++;
0086 80910400 lds R24,_rx_index
008A 8330 cpi R24,3
008C 20F4 brsh L11
008E .dbline 35
008E 8F5F subi R24,255 ; addi 1
0090 80930400 sts _rx_index,R24
0094 5CC0 xjmp L12
0096 L11:
0096 .dbline 37
0096 ; else
0096 ; {
0096 .dbline 38
0096 ; rx_index=0;
0096 2224 clr R2
0098 20920400 sts _rx_index,R2
009C .dbline 39
009C ; SPI_rx_flag=0;
009C 20920100 sts _SPI_rx_flag,R2
00A0 .dbline 40
00A0 ; switch(SPI_rx_buf[0])
00A0 00910800 lds R16,_SPI_rx_buf
00A4 1127 clr R17
00A6 0535 cpi R16,85
00A8 E0E0 ldi R30,0
00AA 1E07 cpc R17,R30
00AC 09F4 brne X4
00AE 44C0 xjmp L33
00B0 X4:
00B0 0535 cpi R16,85
00B2 E0E0 ldi R30,0
00B4 1E07 cpc R17,R30
00B6 0CF4 brge X5
00B8 4AC0 xjmp L14
00BA X5:
00BA L37:
00BA 0A3A cpi R16,170
00BC E0E0 ldi R30,0
00BE 1E07 cpc R17,R30
00C0 09F0 breq L16
00C2 45C0 xjmp L14
00C4 X0:
00C4 .dbline 41
00C4 ; {
00C4 L16:
00C4 .dbline 43
00C4 ; case 0xaa:
00C4 ; switch(SPI_rx_buf[1])
00C4 00910900 lds R16,_SPI_rx_buf+1
00C8 1127 clr R17
00CA 0030 cpi R16,0
00CC 0107 cpc R16,R17
00CE 49F0 breq L21
00D0 X1:
00D0 0130 cpi R16,1
00D2 E0E0 ldi R30,0
00D4 1E07 cpc R17,R30
00D6 81F0 breq L23
00D8 0230 cpi R16,2
00DA E0E0 ldi R30,0
00DC 1E07 cpc R17,R30
00DE E1F0 breq L27
00E0 36C0 xjmp L14
00E2 X2:
00E2 .dbline 44
00E2 ; {
00E2 L21:
00E2 .dbline 46
00E2 ; case 0x00:
00E2 ; qep_cnt[0]=0;
00E2 2224 clr R2
00E4 3324 clr R3
00E6 30920100 sts _qep_cnt+1,R3
00EA 20920000 sts _qep_cnt,R2
00EE .dbline 47
00EE ; qep_cnt[1]=0;
00EE 30920300 sts _qep_cnt+2+1,R3
00F2 20920200 sts _qep_cnt+2,R2
00F6 .dbline 48
00F6 ; break;
00F6 2BC0 xjmp L14
00F8 L23:
00F8 .dbline 50
00F8 ; case 0x01:
00F8 ; SPI_tx_buf[0]=0x55;
00F8 85E5 ldi R24,85
00FA 80930500 sts _SPI_tx_buf,R24
00FE .dbline 51
00FE ; SPI_tx_buf[1]=(*(unsigned char*)(qep_cnt));
00FE E0E0 ldi R30,<_qep_cnt
0100 F0E0 ldi R31,>_qep_cnt
0102 2080 ldd R2,z+0
0104 20920600 sts _SPI_tx_buf+1,R2
0108 .dbline 52
0108 ; SPI_tx_buf[2]=(*((unsigned char*)(qep_cnt)+1));
0108 20900100 lds R2,_qep_cnt+1
010C 20920700 sts _SPI_tx_buf+2,R2
0110 .dbline 53
0110 ; SPI_tx_flag=1;
0110 81E0 ldi R24,1
0112 80930200 sts _SPI_tx_flag,R24
0116 .dbline 54
0116 ; break;
0116 1BC0 xjmp L14
0118 L27:
0118 .dbline 56
0118 ; case 0x02:
0118 ; SPI_tx_buf[0]=0x56;
0118 86E5 ldi R24,86
011A 80930500 sts _SPI_tx_buf,R24
011E .dbline 57
011E ; SPI_tx_buf[1]=(*(unsigned char*)(qep_cnt+1));
011E E0E0 ldi R30,<_qep_cnt+2
0120 F0E0 ldi R31,>_qep_cnt+2
0122 2080 ldd R2,z+0
0124 20920600 sts _SPI_tx_buf+1,R2
0128 .dbline 58
0128 ; SPI_tx_buf[2]=(*((unsigned char*)(qep_cnt+1)+1));
0128 20900300 lds R2,_qep_cnt+2+1
012C 20920700 sts _SPI_tx_buf+2,R2
0130 .dbline 59
0130 ; SPI_tx_flag=1;
0130 81E0 ldi R24,1
0132 80930200 sts _SPI_tx_flag,R24
0136 .dbline 60
0136 ; break;
0136 .dbline 62
0136 ; default:
0136 ; break;
0136 .dbline 64
0136 ; }
0136 ; break;
0136 0BC0 xjmp L14
0138 L33:
0138 .dbline 66
0138 ; case 0x55:
0138 ; pwm_value[0]=SPI_rx_buf[1];
0138 20900900 lds R2,_SPI_rx_buf+1
013C 20920000 sts _pwm_value,R2
0140 .dbline 67
0140 ; pwm_value[1]=SPI_rx_buf[2];
0140 20900A00 lds R2,_SPI_rx_buf+2
0144 20920100 sts _pwm_value+1,R2
0148 .dbline 68
0148 ; pwm_flag=1;
0148 81E0 ldi R24,1
014A 80930000 sts _pwm_flag,R24
014E .dbline 69
014E ; break;
014E .dbline 71
014E ; default:
014E ; break;
014E L14:
014E .dbline 73
014E ; }
014E ; }
014E L12:
014E .dbline 74
014E L9:
014E .dbline -2
014E L1:
014E 2990 ld R2,y+
0150 2FBE out 0x3f,R2
0152 F991 ld R31,y+
0154 E991 ld R30,y+
0156 9991 ld R25,y+
0158 8991 ld R24,y+
015A 1991 ld R17,y+
015C 0991 ld R16,y+
015E 3990 ld R3,y+
0160 2990 ld R2,y+
0162 .dbline 0 ; func end
0162 1895 reti
0164 .dbend
0164 .dbfunc e spi_init _spi_init fV
0164 ; temp -> R16
.even
0164 _spi_init::
0164 .dbline -1
0164 .dbline 80
0164 ; }
0164 ; }
0164 ;
0164 ;
0164 ; //从机模式
0164 ; void spi_init(void)
0164 ; {
0164 .dbline 83
0164 ; unsigned char temp;
0164 ; //MISO=ouput and MOSI,SCK,SS = input
0164 ; DDRB |=BIT(MISO);
0164 BE9A sbi 0x17,6
0166 .dbline 84
0166 ; PORTB |=BIT(MISO); //MISO上拉电阻有效
0166 C69A sbi 0x18,6
0168 .dbline 85
0168 ; DDRB&=~BIT(SS);
0168 BC98 cbi 0x17,4
016A .dbline 86
016A ; SPCR = 0xC7; //SPI允许,从机模式,MSB,允许SPI中断 极性方式01,1/4系统时钟速率
016A 87EC ldi R24,199
016C 8DB9 out 0xd,R24
016E .dbline 87
016E ; SPSR = 0x00;
016E 2224 clr R2
0170 2EB8 out 0xe,R2
0172 .dbline 88
0172 ; temp = SPSR;
0172 0EB1 in R16,0xe
0174 .dbline 89
0174 ; temp = SPDR; //清空SPI,和中断标志,使SPI空闲
0174 0FB1 in R16,0xf
0176 .dbline 90
0176 ; SPI_tx_flag=0;
0176 20920200 sts _SPI_tx_flag,R2
017A .dbline 91
017A ; SPI_rx_flag=0;
017A 20920100 sts _SPI_rx_flag,R2
017E .dbline 92
017E ; rx_index=0;
017E 20920400 sts _rx_index,R2
0182 .dbline 93
0182 ; tx_index=0;
0182 20920300 sts _tx_index,R2
0186 .dbline -2
0186 L38:
0186 .dbline 0 ; func end
0186 0895 ret
0188 .dbsym r temp 16 c
0188 .dbend
.area bss(ram, con, rel)
0000 _temp::
0000 .blkb 1
0001 .dbsym e temp _temp c
0001 _SPI_rx_flag::
0001 .blkb 1
0002 .dbsym e SPI_rx_flag _SPI_rx_flag c
0002 _SPI_tx_flag::
0002 .blkb 1
0003 .dbsym e SPI_tx_flag _SPI_tx_flag c
0003 _tx_index::
0003 .blkb 1
0004 .dbsym e tx_index _tx_index c
0004 _rx_index::
0004 .blkb 1
0005 .dbsym e rx_index _rx_index c
0005 _SPI_tx_buf::
0005 .blkb 3
0008 .dbsym e SPI_tx_buf _SPI_tx_buf A[3:3]c
0008 _SPI_rx_buf::
0008 .blkb 3
000B .dbsym e SPI_rx_buf _SPI_rx_buf A[3:3]c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -