📄 洗衣机.s
字号:
sbis 0xb,7
rjmp L99
X35:
.dbline 98
; return UDR;
in R16,0xc
.dbline -2
L98:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Putchar _Putchar fV
; c -> R16
.even
_Putchar::
.dbline -1
.dbline 105
; }
;
; //-----------------------------------------------------------
; //串口发送字节子程序
; //-----------------------------------------------------------
; void Putchar(char c)
; {
L103:
.dbline 106
; while (!(UCSRA&(1<<UDRE)));
L104:
.dbline 106
sbis 0xb,5
rjmp L103
X36:
.dbline 107
; UDR=c;
out 0xc,R16
.dbline -2
L102:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.dbfunc e Putstr _Putstr fV
; s -> R20,R21
.even
_Putstr::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 114
; }
;
; //-----------------------------------------------------------
; //串口发送字符串子程序
; //-----------------------------------------------------------
; void Putstr(char *s)
; {
xjmp L108
L107:
.dbline 116
; while (*s)
; {
.dbline 117
; Putchar(*s);
movw R30,R20
ldd R16,z+0
xcall _Putchar
.dbline 118
; s++;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 119
; }
L108:
.dbline 115
movw R30,R20
ldd R2,z+0
tst R2
brne L107
X37:
.dbline -2
L106:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r s 20 pc
.dbend
.dbfunc e Puts _Puts fV
; s -> R20,R21
.even
_Puts::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 126
; }
;
; //-----------------------------------------------------------
; //串口发送字符串子程序(带有换行符)
; //-----------------------------------------------------------
; void Puts(char *s)
; {
xjmp L112
L111:
.dbline 128
; while (*s)
; {
.dbline 129
; Putchar(*s);
movw R30,R20
ldd R16,z+0
xcall _Putchar
.dbline 130
; s++;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 131
; }
L112:
.dbline 127
movw R30,R20
ldd R2,z+0
tst R2
brne L111
X38:
.dbline 132
; Putchar(0x0a); //回车换行
ldi R16,10
xcall _Putchar
.dbline 133
; Putchar(0x0d);
ldi R16,13
xcall _Putchar
.dbline -2
L110:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r s 20 pc
.dbend
.dbfunc e close_rx _close_rx fV
.even
_close_rx::
.dbline -1
.dbline 137
; }
;
; void close_rx()
; {
.dbline 138
; UCSRB&=~BIT(RXCIE);
cbi 0xa,7
.dbline -2
L114:
.dbline 0 ; func end
ret
.dbend
.dbfunc e open_rx _open_rx fV
.even
_open_rx::
.dbline -1
.dbline 142
; }
;
; void open_rx()
; {
.dbline 143
; UCSRB|=BIT(RXCIE);
sbi 0xa,7
.dbline -2
L115:
.dbline 0 ; func end
ret
.dbend
.dbfunc e PORT_Init _PORT_Init fV
.even
_PORT_Init::
.dbline -1
.dbline 147
; }
;
; void PORT_Init()
; {
.dbline 148
; DDRA=0XFF;
ldi R24,255
out 0x1a,R24
.dbline -2
L116:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay _delay fV
; i -> R20,R21
; j -> R22,R23
; ms -> R16,R17
.even
_delay::
xcall push_xgsetF000
.dbline -1
.dbline 152
; }
;
; void delay(uint ms)
; {
.dbline 154
; uint i,j;
; for(i=0;i<ms;i++)
clr R20
clr R21
xjmp L121
L118:
.dbline 155
; {
.dbline 156
; for(j=0;j<1000;j++);
clr R22
clr R23
xjmp L125
L122:
.dbline 156
L123:
.dbline 156
subi R22,255 ; offset = 1
sbci R23,255
L125:
.dbline 156
cpi R22,232
ldi R30,3
cpc R23,R30
brlo L122
X39:
.dbline 157
; }
L119:
.dbline 154
subi R20,255 ; offset = 1
sbci R21,255
L121:
.dbline 154
cp R20,R16
cpc R21,R17
brlo L118
X40:
.dbline -2
L117:
.dbline 0 ; func end
xjmp pop_xgsetF000
.dbsym r i 20 i
.dbsym r j 22 i
.dbsym r ms 16 i
.dbend
.dbfunc e spi_init _spi_init fV
.even
_spi_init::
.dbline -1
.dbline 161
; }
;
; void spi_init()
; {
.dbline 162
; DDRB|=0XB0;//SCK、SS和MOSI设置为输出,其他为输入
in R24,0x17
ori R24,176
out 0x17,R24
.dbline 163
; SPCR = (1 << SPE)|(1 << MSTR)|(1 << SPR0);
ldi R24,81
out 0xd,R24
.dbline 165
; // SPCR = (1 << SPE)|(1 << MSTR);//2Mbps
; SPSR = 0;
clr R2
out 0xe,R2
.dbline -2
L126:
.dbline 0 ; func end
ret
.dbend
.dbfunc e send_spi _send_spi fc
; date -> R16
.even
_send_spi::
.dbline -1
.dbline 169
; }
;
; uchar send_spi(uchar date)
; {
.dbline 170
; SPSR &= ~(1 << SPIF);
cbi 0xe,7
.dbline 171
; SPDR=date;
out 0xf,R16
L128:
.dbline 172
; while(!(SPSR&(1 << SPIF)));
L129:
.dbline 172
sbis 0xe,7
rjmp L128
X41:
.dbline 173
; return SPDR;
in R16,0xf
.dbline -2
L127:
.dbline 0 ; func end
ret
.dbsym r date 16 c
.dbend
.dbfunc e interr_0 _interr_0 fV
.even
_interr_0::
.dbline -1
.dbline 179
;
; }
;
;
; void interr_0()
; {
.dbline 180
; MCUCR=0X02;
ldi R24,2
out 0x35,R24
.dbline 181
; SREG|=0X80;
bset 7
.dbline 182
; GICR=0X40;
ldi R24,64
out 0x3b,R24
.dbline -2
L131:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_sys _init_sys fV
.even
_init_sys::
.dbline -1
.dbline 186
; }
;
; void init_sys()
; {
.dbline 187
; DDRD|=0X02;//串口发送TX为输出
sbi 0x11,1
L133:
.dbline 188
; CE_0; // 清零CE,处于待机状态
.dbline 188
in R24,0x1b
andi R24,253
out 0x1b,R24
.dbline 188
L134:
.dbline 188
L136:
.dbline 189
; CSN_0; //清零CSN,
.dbline 189
in R24,0x18
andi R24,239
out 0x18,R24
.dbline 189
L137:
.dbline 189
.dbline -2
L132:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SPI_RW_Reg _SPI_RW_Reg fc
; a -> R10
; value -> R12
; reg -> R10
.even
_SPI_RW_Reg::
st -y,R10
st -y,R12
mov R12,R18
mov R10,R16
.dbline -1
.dbline 202
; }
;
;
;
; /**************************************************
; Function: SPI_RW_Reg();
;
; Description:
; Writes value 'value' to register 'reg'
; /**************************************************/
;
; uchar SPI_RW_Reg(BYTE reg, BYTE value)
; {
L140:
.dbline 204
; uchar a;
; CSN_0;
.dbline 204
in R24,0x18
andi R24,239
out 0x18,R24
.dbline 204
L141:
.dbline 204
.dbline 205
; a=send_spi(reg);
mov R16,R10
xcall _send_spi
mov R10,R16
.dbline 206
; send_spi(value); // ..and write value to it..
mov R16,R12
xcall _send_spi
L143:
.dbline 207
; CSN_1;
.dbline 207
sbi 0x18,4
.dbline 207
L144:
.dbline 207
.dbline 208
; return(a); // return nRF24L01 status byte
mov R16,R10
.dbline -2
L139:
.dbline 0 ; func end
ld R12,y+
ld R10,y+
ret
.dbsym r a 10 c
.dbsym r value 12 c
.dbsym r reg 10 c
.dbend
.dbfunc e SPI_Read _SPI_Read fc
; reg_val -> R10
; reg -> R10
.even
_SPI_Read::
st -y,R10
mov R10,R16
.dbline -1
.dbline 214
; }
; /**************************************************/
;
; /**************************************************/
; BYTE SPI_Read(BYTE reg)
; {
L147:
.dbline 217
;
; BYTE reg_val;
; CSN_0;//CSN IS LOW
.dbline 217
in R24,0x18
andi R24,239
out 0x18,R24
.dbline 217
L148:
.dbline 217
.dbline 218
; send_spi(reg); // Select register to read from..
mov R16,R10
xcall _send_spi
.dbline 219
; reg_val=send_spi(0); // ..then read registervalue
clr R16
xcall _send_spi
mov R10,R16
L150:
.dbline 220
; CSN_1;
.dbline 220
sbi 0x18,4
.dbline 220
L151:
.dbline 220
.dbline 221
; return(reg_val); // return register value
mov R16,R10
.dbline -2
L146:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym r reg_val 10 c
.dbsym r reg 10 c
.dbend
.dbfunc e SPI_Read_Buf _SPI_Read_Buf fc
; status -> R10
; byte_ctr -> R12
; bytes -> y+6
; pBuf -> R14,R15
; reg -> R10
.even
_SPI_Read_Buf::
xcall push_xgset00FC
movw R14,R18
mov R10,R16
.dbline -1
.dbline 233
; }
; /*
;
; /**************************************************
; Function: SPI_Read_Buf();
;
; Description:
; Reads 'bytes' #of bytes from register 'reg'
; Typically used to read RX payload, Rx/Tx address
; /**************************************************/
; uchar SPI_Read_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
; {
L154:
.dbline 235
; uchar status,byte_ctr;
; CSN_0;//CSN IS LOW
.dbline 235
in R24,0x18
andi R24,239
out 0x18,R24
.dbline 235
L155:
.dbline 235
.dbline 236
; status=send_spi(reg); // Select register to write to and read status byte
mov R16,R10
xcall _send_spi
mov R10,R16
.dbline 237
; for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
clr R12
xjmp L160
L157:
.dbline 238
; pBuf[byte_ctr] = send_spi(0); // Perform SPI_RW to read byte from nRF24L01
clr R16
xcall _send_spi
mov R30,R12
clr R31
add R30,R14
adc R31,R15
std z+0,R16
L158:
.dbline 237
inc R12
L160:
.dbline 237
ldd R0,y+6
cp R12,R0
brlo L157
X42:
L161:
.dbline 239
; CSN_1;
.dbline 239
sbi 0x18,4
.dbline 239
L162:
.dbline 239
.dbline 240
; return(status);
mov R16,R10
.dbline -2
L153:
.dbline 0 ; func end
xjmp pop_xgset00FC
.dbsym r status 10 c
.dbsym r byte_ctr 12 c
.dbsym l bytes 6 c
.dbsym r pBuf 14 pc
.dbsym r reg 10 c
.dbend
.dbfunc e SPI_Write_Buf _SPI_Write_Buf fc
; status -> R10
; byte_ctr -> R12
; bytes -> y+6
; pBuf -> R14,R15
; reg -> R10
.even
_SPI_Write_Buf::
xcall push_xgset00FC
movw R14,R18
mov R10,R16
.dbline -1
.dbline 253
; }
; /**************************************************/
;
; /**************************************************
; Function: SPI_Write_Buf();
;
; Description:
; Writes contents of buffer '*pBuf' to nRF24L01
; Typically used to write TX payload, Rx/Tx address
; /**************************************************/
;
; uchar SPI_Write_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
; {
L165:
.dbline 255
; uchar status,byte_ctr;
; CSN_0;//CSN IS LOW
.dbline 255
in R24,0x18
andi R24,239
out 0x18,R24
.dbline 255
L166:
.dbline 255
.dbline 256
; status=send_spi(reg); // Select register to write to and read status byte写的过程顺便读读寄存器状态
mov R16,R10
xcall _send_spi
mov R10,R16
.dbline 257
; for(byte_ctr=0; byte_ctr<bytes; byte_ctr++) // then write all byte in buffer(*pBuf)
clr R12
xjmp L171
L168:
.dbline 258
; send_spi(*pBuf++);
movw R30,R14
ld R16,Z+
movw R14,R30
xcall _send_spi
L169:
.dbline 257
inc R12
L171:
.dbline 257
ldd R0,y+6
cp R12,R0
brlo L168
X43:
L172:
.dbline 259
; CSN_1;
.dbline 259
sbi 0x18,4
.dbline 259
L173:
.dbline 259
.dbline 260
; return(status);
mov R16,R10
.dbline -2
L164:
.dbline 0 ; func end
xjmp pop_xgset00FC
.dbsym r status 10 c
.dbsym r byte_ctr 12 c
.dbsym l bytes 6 c
.dbsym r pBuf 14 pc
.dbsym r reg 10 c
.dbend
.dbfunc e init_24l01 _init_24l01 fV
.even
_init_24l01::
.dbline -1
.dbline 265
; }
; /**************************************************/
;
; void init_24l01()
; {
.dbline 266
; SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); // Enable Auto.Ack:Pipe0(数据通道0自动应答允许)
ldi R18,1
ldi R16,33
xcall _SPI_RW_Reg
.dbline 267
; SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); // Enable Pipe0(接收数据通道0允许)
ldi R18,1
ldi R16,34
xcall _SPI_RW_Reg
.dbline 268
; SPI_RW_Reg(WRITE_REG + RF_CH, 40); // Select RF channel 40(设置工作通道频率为40)
ldi R18,40
ldi R16,37
xcall _SPI_RW_Reg
.dbline 269
; SPI_RW_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH); // Select same RX payload width as TX Payload width RX0通道有效数据宽度与TX设置相同
ldi R18,2
ldi R16,49
xcall _SPI_RW_Reg
.dbline 270
; SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x0f); // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR数据传输率2Mbps发射功率0dbm低噪声放大增益
ldi R18,15
ldi R16,38
xcall _SPI_RW_Reg
.dbline -2
L175:
.dbline 0 ; func end
ret
.dbend
.dbfunc e RX_Mode _RX_Mode fV
.even
_RX_Mode::
sbiw R28,1
.dbline -1
.dbline 288
; }
; //CRC使能、8位CRC校验、模式为掉电、不屏蔽任何中断reserved
; //接收发射地址宽度:5字节SET-UP_AW
; //自动重发延时:250+86US,自动重发次数:3次SET-UP_RETR
; //发送地址与数据通道0接收地址初始值均相同
; /**************************************************
; Function: RX_Mode();
;
; Description:
; This function initializes one nRF24L01 device to
; RX Mode, set RX address, writes RX payload width,
; select RF channel, datarate & LNA HCURR.
; After init, CE is toggled high, which means that
; this device is now ready to receive a datapacket.
; /**************************************************/
;
; void RX_Mode(void)
; {
L177:
.dbline 289
; CE_0;
.dbline 289
in R24,0x1b
andi R24,253
out 0x1b,R24
.dbline 289
L178:
.dbline 289
.dbline 290
; SPI_Write_Buf((WRITE_REG + RX_ADDR_P0), TX_ADDRESS, TX_ADR_WIDTH); //Use the same address on the RX device as the TX device
ldi R24,5
std y+0,R24
ldi R18,<_TX_ADDRESS
ldi R19,>_TX_ADDRESS
ldi R16,42
xcall _SPI_Write_Buf
.dbline 291
; SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f); // Set PWR_UP bit, enable CRC(2 bytes) & Prim:RX. RX_DR enabled..
ldi R18,15
ldi R16,32
xcall _SPI_RW_Reg
L180:
.dbline 292
; CE_1; // Set CE
.dbline 292
sbi 0x1b,1
.dbline 292
L181:
.dbline 292
.dbline -2
L176:
.dbline 0 ; func end
adiw R28,1
ret
.dbend
.dbfunc e TX_Mode _TX_Mode fV
.even
_TX_Mode::
sbiw R28,1
.dbline -1
.dbline 310
; }
; /**************************************************/
;
; /**************************************************
; Function: TX_Mode();
;
; Description:
; This function initializes one nRF24L01 device to
; TX mode, set TX address, set RX address for auto.ack,
; fill TX payload, select RF channel, datarate & TX pwr.
; PWR_UP is set, CRC(2 bytes) is enabled, & PRIM:TX.
;
; ToDo: One high pulse(>10us) on CE will now send this
; packet and expext an acknowledgment from the RX device.
; /**************************************************/
;
; void TX_Mode(void)
; {
L184:
.dbline 311
; CE_0;
.dbline 311
in R24,0x1b
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -