📄 slave.s
字号:
.module slave.C
.area data(ram, con, rel)
_X:
.blkb 1
.area idata
.byte 10
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905/config.h
.dbsym s X _X c
_Y:
.blkb 1
.area idata
.byte 2
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905/config.h
.dbsym s Y _Y c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905/config.h
.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905\slave.C
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 23
; //SLAVE
;
; //最关键的是SPI的初始化,MSB首位和极性方式00,极性方式错误,数据则不正确
;
;
; #include "config.h"
; #include "nrf905.h"
;
; #define MASTER //编译控制是主机还是从机
;
;
; #define T0N 25
; void DelayUs(uint);
; void DelayMs(uchar);
; //32字节数据包发送时间
; //=650us_StartUp+200us_Preamble+(4+32+2)Byts*8Bit/50000bps*1000000us=6.6ms
; #define RFTN 25 //发送测试间隔 10*20ms
;
; bit bTimer,bRfSend;
; uchar T0Cnt,RfCnt;
;
; void port_init(void)
; {
.dbline 24
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 25
; DDRA = 0xff;
ldi R24,255
out 0x1a,R24
.dbline 26
; PORTB = BIT(AM)|BIT(CD)|BIT(DR)|BIT(MISO);
ldi R24,78
out 0x18,R24
.dbline 27
; DDRB = BIT(CSN)|BIT(MOSI)|BIT(SCK);
ldi R24,176
out 0x17,R24
.dbline 28
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 29
; DDRC = 0x00;
out 0x14,R2
.dbline 30
; PORTD = BIT(uPCLK);
ldi R24,32
out 0x12,R24
.dbline 31
; DDRD = BIT(TRXCE)|BIT(TX_EN)|BIT(PWR)|BIT(LED)|0x07;
ldi R24,223
out 0x11,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e timer0_init _timer0_init fV
.even
_timer0_init::
.dbline -1
.dbline 39
; }
;
; //TIMER0 initialize - prescale:1024
; // WGM: Normal
; // desired value: 20mSec
; // actual value: 19.861mSec (0.7%)
; void timer0_init(void)
; {
.dbline 40
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline 41
; TCNT0 = 0x71; //set count
ldi R24,113
out 0x32,R24
.dbline 42
; OCR0 = 0x8F; //set compare
ldi R24,143
out 0x3c,R24
.dbline 43
; TCCR0 = 0x05; //start timer
ldi R24,5
out 0x33,R24
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 36
jmp _timer0_ovf_isr
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905\slave.C
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
st -y,R2
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 48
; }
;
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
.dbline 49
; TCNT0 = 0x29; //reload counter value
ldi R24,41
out 0x32,R24
.dbline 51
;
; if (--T0Cnt==0)
lds R24,_T0Cnt
subi R24,1
mov R2,R24
sts _T0Cnt,R2
tst R24
brne L4
.dbline 52
; {T0Cnt=T0N;
.dbline 52
ldi R24,25
sts _T0Cnt,R24
.dbline 53
; bTimer=1;
ldi R24,1
sts _bTimer,R24
.dbline 54
; }
L4:
.dbline 55
lds R24,_RfCnt
subi R24,1
mov R2,R24
sts _RfCnt,R2
tst R24
brne L6
.dbline 56
.dbline 56
ldi R24,25
sts _RfCnt,R24
.dbline 57
ldi R24,1
sts _bRfSend,R24
.dbline 58
L6:
.dbline -2
L3:
ld R2,y+
out 0x3f,R2
ld R24,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e spi_init _spi_init fV
; temp -> R16
.even
_spi_init::
.dbline -1
.dbline 65
; if (--RfCnt==0)
; {RfCnt=RFTN;
; bRfSend=1;
; }
; }
;
;
;
; //SPI initialize
; void spi_init(void)
; {uchar temp;
.dbline 67
;
; SPCR = 0x51; //不使用SPI中断,SPI允许,主机模式,MSB,极性方式00,1/16系统时钟速率
ldi R24,81
out 0xd,R24
.dbline 68
; SPSR = 0x00; //setup SPI
clr R2
out 0xe,R2
.dbline 70
;
; temp = SPSR; //!!!
in R16,0xe
.dbline 71
; temp = SPDR; //清空SPI,和中断标志,使SPI空闲
in R16,0xf
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbsym r temp 16 c
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 79
; }
;
;
;
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 81
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 82
; port_init();
xcall _port_init
.dbline 83
; timer0_init();
xcall _timer0_init
.dbline 84
; spi_init();
xcall _spi_init
.dbline 85
; init_lcd();
xcall _init_lcd
.dbline 86
; DISLCD();
sbi 0x12,1
.dbline 88
;
; MCUCR = 0x00; //下降沿触发
clr R2
out 0x35,R2
.dbline 89
; GICR = 0x00;
out 0x3b,R2
.dbline 90
; TIMSK = 0x05; //timer interrupt sources
ldi R24,5
out 0x39,R24
.dbline 91
; SEI(); //re-enable interrupts
sei
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.dbfunc e RfRecvProc _RfRecvProc fV
; i -> R20
.even
_RfRecvProc::
xcall push_gset1
.dbline -1
.dbline 100
; //all peripherals are now initialized
; }
;
;
;
;
; //接收处理
; void RfRecvProc()
; {uchar i;
.dbline 102
;
; if ((PINB&(1<<AM))==0) return;//一般先AM=1指示地址匹配对
sbic 0x16,1
rjmp L11
.dbline 102
xjmp L10
L11:
.dbline 104
;
; if ((PINB&(1<<DR))==0) return;//DR=1时表示数据接收对而且Crc正确
sbic 0x16,3
rjmp L13
.dbline 104
xjmp L10
L13:
.dbline 108
;
;
; //已经接收到数据
; nrf905_ReadData();//读出...
xcall _nrf905_ReadData
.dbline 112
;
;
; //数据接收正确...灯指示
; CPL(PORTD,LED);
ldi R24,128
ldi R25,0
in R2,0x12
clr R3
eor R2,R24
eor R3,R25
out 0x12,R2
.dbline 113
clr R20
xjmp L18
L15:
.dbline 113
.dbline 113
ldi R24,<_RxBuf
ldi R25,>_RxBuf
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
xcall _seg
.dbline 113
L16:
.dbline 113
inc R20
L18:
.dbline 113
; for (i=0;i<SIZE;i++){seg(RxBuf[i]);}
cpi R20,32
brlo L15
.dbline 114
; LCD(RxBuf[0]);
lds R16,_RxBuf
xcall _LCD
.dbline -2
L10:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.dbfunc e RfSendProc _RfSendProc fV
; i -> R20
.even
_RfSendProc::
xcall push_gset1
.dbline -1
.dbline 125
;
;
; //从机回送数据包,这样双方都能指示是否收到有效数据包
; #ifndef MASTER
; //RfSendProc();
; #endif
; }
;
; //发送测试
; void RfSendProc()
; {uchar i;
.dbline 126
clr R20
xjmp L23
L20:
.dbline 126
ldi R24,2
mul R24,R20
ldi R24,<_TxBuf
ldi R25,>_TxBuf
mov R30,R20
clr R31
add R30,R24
adc R31,R25
std z+0,R0
L21:
.dbline 126
inc R20
L23:
.dbline 126
; for (i=0;i<SIZE;i++) TxBuf[i]=2*i;
cpi R20,32
brlo L20
.dbline 127
; nrf905_SendData();//发送测试数据
xcall _nrf905_SendData
.dbline 128
; nrf905_RxOn();//重新回到接收状态
xcall _nrf905_RxOn
.dbline -2
L19:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.dbfunc e TimerFunc _TimerFunc fV
.even
_TimerFunc::
.dbline -1
.dbline 132
; }
;
; void TimerFunc()
; {
.dbline 133
; bTimer=0;
clr R2
sts _bTimer,R2
.dbline 136
; //WDR();//clear WDT
;
; CPL(PORTD,LED);
ldi R24,128
ldi R25,0
in R2,0x12
clr R3
eor R2,R24
eor R3,R25
out 0x12,R2
.dbline -2
L24:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SystemIni _SystemIni fV
.even
_SystemIni::
.dbline -1
.dbline 141
; //SPDR=66;
; }
;
; void SystemIni()
; {
.dbline 142
; T0Cnt=T0N;
ldi R24,25
sts _T0Cnt,R24
.dbline 143
; RfCnt=RFTN;
sts _RfCnt,R24
.dbline -2
L25:
.dbline 0 ; func end
ret
.dbend
.dbfunc e DelayMs _DelayMs fV
; i -> R20
; ms -> R22
.even
_DelayMs::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 147
; }
;
; void DelayMs(uchar ms)
; {char i;
.dbline 148
; for (i=0;i<ms;i++)
clr R20
xjmp L30
L27:
.dbline 149
.dbline 149
ldi R16,1000
ldi R17,3
xcall _DelayUs
.dbline 150
L28:
.dbline 148
inc R20
L30:
.dbline 148
cp R20,R22
brlo L27
.dbline 151
; {DelayUs(1000);
; }
; return;
.dbline -2
L26:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r ms 22 c
.dbend
.dbfunc e DelayUs _DelayUs fV
; i -> R20,R21
; us -> R16,R17
.even
_DelayUs::
xcall push_gset1
.dbline -1
.dbline 155
; }
;
; void DelayUs(uint us)
; {uint i;
.dbline 156
; for (i=0;i<us;i++)
clr R20
clr R21
xjmp L35
L32:
.dbline 157
.dbline 157
nop
.dbline 157
nop
.dbline 157
nop
.dbline 157
nop
.dbline 157
nop
.dbline 157
nop
.dbline 158
L33:
.dbline 156
subi R20,255 ; offset = 1
sbci R21,255
L35:
.dbline 156
cp R20,R16
cpc R21,R17
brlo L32
.dbline -2
L31:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r us 16 i
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 162
; {NOP();NOP();NOP();NOP();NOP();NOP();
; }
; }
;
; void main()
; {
.dbline 163
; init_devices();
xcall _init_devices
.dbline 164
; SystemIni();
xcall _SystemIni
.dbline 165
; nrf905_Init();
xcall _nrf905_Init
.dbline 166
; ENLCD();
cbi 0x12,1
.dbline 167
; PutChar('W');
ldi R16,87
xcall _PutChar
.dbline 168
; PutChar('e');
ldi R16,101
xcall _PutChar
.dbline 169
; PutChar('l');
ldi R16,108
xcall _PutChar
.dbline 170
; PutChar('c');
ldi R16,99
xcall _PutChar
.dbline 171
; PutChar('o');
ldi R16,111
xcall _PutChar
.dbline 172
; PutChar('m');
ldi R16,109
xcall _PutChar
.dbline 173
; PutChar('e');
ldi R16,101
xcall _PutChar
.dbline 174
; PutChar(' ');
ldi R16,32
xcall _PutChar
.dbline 175
; PutChar('t');
ldi R16,116
xcall _PutChar
.dbline 176
; PutChar('o');
ldi R16,111
xcall _PutChar
.dbline 177
; PutChar(' ');
ldi R16,32
xcall _PutChar
.dbline 178
; PutChar('X');
ldi R16,88
xcall _PutChar
.dbline 179
; PutChar('G');
ldi R16,71
xcall _PutChar
.dbline 180
; PutChar('C');
ldi R16,67
xcall _PutChar
.dbline 181
; DelayMs(1000);
ldi R16,232
xcall _DelayMs
.dbline 182
; DelayMs(1000);
ldi R16,232
xcall _DelayMs
.dbline 183
; DelayMs(1000);
ldi R16,232
xcall _DelayMs
.dbline 184
; DelayMs(1000);
ldi R16,232
xcall _DelayMs
.dbline 188
;
;
;
; clear_lcd();
xcall _clear_lcd
.dbline 191
;
;
; DISLCD();
sbi 0x12,1
xjmp L38
L37:
.dbline 194
;
; while (1)
; {
.dbline 197
; // if (bTimer) TimerFunc();
; #ifdef MASTER
; if (bRfSend)
lds R2,_bRfSend
tst R2
breq L40
.dbline 198
; { bRfSend=0;
.dbline 198
clr R2
sts _bRfSend,R2
.dbline 199
; RfSendProc();//发送测试
xcall _RfSendProc
.dbline 200
; }
L40:
.dbline 203
xcall _RfRecvProc
.dbline 204
L38:
.dbline 193
xjmp L37
X0:
.dbline -2
L36:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905\slave.C
_RfCnt::
.blkb 1
.dbsym e RfCnt _RfCnt c
_T0Cnt::
.blkb 1
.dbsym e T0Cnt _T0Cnt c
_bRfSend::
.blkb 1
.dbsym e bRfSend _bRfSend c
_bTimer::
.blkb 1
.dbsym e bTimer _bTimer c
_key:
.blkb 1
.dbfile C:\DOCUME~1\charon\MYDOCU~1\AVR\NRF905/config.h
.dbsym s key _key c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -