⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soc_test.s

📁 atmega128串口通信
💻 S
📖 第 1 页 / 共 4 页
字号:
L47:
	.dbline 220
; 			else if(CHANGE_WORDL2==buffer[buf_index])
	ldi R24,<_buffer
	ldi R25,>_buffer
	lds R30,_buf_index
	clr R31
	add R30,R24
	adc R31,R25
	ldd R24,z+0
	cpi R24,93
	brne L50
	.dbline 221
; 			{
	.dbline 222
; 				buffer[buf_index-1]=0x7D;	//若是7D 5D -> 7D
	ldi R24,<_buffer-1
	ldi R25,>_buffer-1
	lds R30,_buf_index
	clr R31
	add R30,R24
	adc R31,R25
	ldi R24,125
	std z+0,R24
	.dbline 223
; 				buf_index-=1;			//buf_index减一
	lds R24,_buf_index
	subi R24,1
	sts _buf_index,R24
	.dbline 224
; 			}
	xjmp L29
L50:
	.dbline 226
; 			else
; 			{
	.dbline 227
; 				haveError=0x04;		//haveError索引(4),转义字符出错
	ldi R24,4
	sts _haveError,R24
	.dbline 228
; 			}
	.dbline 229
; 		}
	xjmp L29
L45:
	.dbline 230
; 		else if(0x7D==buffer[buf_index])
	ldi R24,<_buffer
	ldi R25,>_buffer
	lds R30,_buf_index
	clr R31
	add R30,R24
	adc R31,R25
	ldd R24,z+0
	cpi R24,125
	brne L29
	.dbline 231
; 		{
	.dbline 232
; 			haveSpeWord=0x01;			//接收到转义字符
	ldi R24,1
	sts _haveSpeWord,R24
	.dbline 233
; 		} 
	.dbline 234
; 	}
	xjmp L29
L28:
	.dbline 236
; 	else
; 	{
	.dbline 237
; 		haveError=0x01;		//haveError索引(1),超出了接收长度
	ldi R24,1
	sts _haveError,R24
	.dbline 238
; 	}
L29:
	.dbline 240
; 	//跳出时做错误判断
; 	if(haveError!=0)				//如果发现有错误
	lds R2,_haveError
	tst R2
	breq L55
	.dbline 241
; 	{	//如果有错误,重新接收
	.dbline 242
; 		buffer[0]=0x00;			//第一个字符清零
	clr R2
	sts _buffer,R2
	.dbline 243
; 		buf_index=0;				//buffer索引清零,继续接收
	sts _buf_index,R2
	.dbline 244
; 		beginWord=0x00;			//为开始做准备
	sts _beginWord,R2
	.dbline 245
; 		endWord=0x00;				//结束字还没收到
	sts _endWord,R2
	.dbline 246
; 		haveSpeWord=0;				//清接收转义字符标志
	sts _haveSpeWord,R2
	.dbline 247
; 		haveError=0;				//清错误标志
	sts _haveError,R2
	.dbline 248
; 	}
	xjmp L56
L55:
	.dbline 250
	.dbline 251
	lds R24,_buf_index
	subi R24,255    ; addi 1
	sts _buf_index,R24
	.dbline 252
L56:
	.dbline -2
	.dbline 253
; 	else
; 	{										//若没有错误
; 		buf_index+=1;					//buffer索引加1
; 	}
; }//end usart0_receive
L27:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R16,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbsym r revChar 16 c
	.dbend
	.dbfunc e Write_bus_data _Write_bus_data fV
;     bus_data_H -> R20
;     bus_data_L -> R22
;       bus_data -> R22,R23
	.even
_Write_bus_data::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 259
; 
; /*********************************************************
; 向命令总线写命令数据
; *********************************************************/
; void  Write_bus_data(short bus_data)
; {unsigned char bus_data_L;
	.dbline 261
;  unsigned char bus_data_H;
;  bus_data_H = bus_data/256;
	ldi R18,256
	ldi R19,1
	movw R16,R22
	xcall div16s
	mov R20,R16
	.dbline 262
;  bus_data_L = bus_data%256;
	ldi R18,256
	ldi R19,1
	movw R16,R22
	xcall mod16s
	mov R22,R16
	.dbline 263
;  INSTRUCT_BYTE_LOW = bus_data_L;
	sts 4607,R22
	.dbline 264
;  INSTRUCT_BYTE_HIG = bus_data_H;
	sts 4863,R20
	.dbline -2
	.dbline 265
; }//end Write_bus_data
L57:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r bus_data_H 20 c
	.dbsym r bus_data_L 22 c
	.dbsym r bus_data 22 S
	.dbend
	.dbfunc e Write_bus_add _Write_bus_add fV
;        bus_add -> R16
	.even
_Write_bus_add::
	.dbline -1
	.dbline 271
; /*********************************************************
; 向命令总线写命令地址
; *********************************************************/
;     
; void  Write_bus_add(unsigned char bus_add)
; {INSTRUCT_ADD = bus_add;
	.dbline 271
	sts 5119,R16
	.dbline -2
	.dbline 272
; }//end Write_bus_add
L58:
	.dbline 0 ; func end
	ret
	.dbsym r bus_add 16 c
	.dbend
	.dbfunc e send_instruct _send_instruct fV
;        address -> R20
;        command -> R22,R23
	.even
_send_instruct::
	xcall push_gset2
	mov R20,R18
	movw R22,R16
	.dbline -1
	.dbline 277
; /*********************************************************
; 写控制命令
; *********************************************************/
; void  send_instruct(short command ,unsigned char address)
; {Write_bus_data(command);
	.dbline 277
	movw R16,R22
	xcall _Write_bus_data
	.dbline 278
;  Write_bus_add(address);
	mov R16,R20
	xcall _Write_bus_add
	.dbline 279
;  PORTE&=~BIT(BUSWEN);  //BUSWEN置低
	cbi 0x3,3
	.dbline 280
;  NOP5();
	xcall _NOP5
	.dbline 281
;  PORTE|=BIT(BUSWEN);  //BUSWEN置高
	sbi 0x3,3
	.dbline 282
;  NOP5();
	xcall _NOP5
	.dbline 283
;  PORTE&=~BIT(NBUS_CLK);  //NBUS_CLK置低
	cbi 0x3,2
	.dbline 284
;  NOP5();
	xcall _NOP5
	.dbline 285
;  PORTE|=BIT(NBUS_CLK);  //NBUS_CLK置高
	sbi 0x3,2
	.dbline 286
;  NOP5();
	xcall _NOP5
	.dbline 287
;  PORTE&=~BIT(NBUS_CLK);  //NBUS_CLK置低
	cbi 0x3,2
	.dbline 288
;  NOP5();
	xcall _NOP5
	.dbline 289
;  PORTE&=~BIT(BUSWEN);  //BUSWEN置低
	cbi 0x3,3
	.dbline 290
;  NOP5();
	xcall _NOP5
	.dbline -2
	.dbline 292
;  
; }//end send_instruct
L59:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r address 20 c
	.dbsym r command 22 S
	.dbend
	.dbfunc e start_sample _start_sample fV
	.even
_start_sample::
	.dbline -1
	.dbline 297
; /*********************************************************
; 启动DDC数据采样
; *********************************************************/
; void start_sample(void)
; {PORTE&=~BIT(SAMPLE_START);  //SAMPLE_START置低
	.dbline 297
	cbi 0x3,4
	.dbline 298
;  NOP5();
	xcall _NOP5
	.dbline 299
;  PORTE|=BIT(SAMPLE_START);  //SAMPLE_START置高
	sbi 0x3,4
	.dbline 300
;  NOP5();
	xcall _NOP5
	.dbline 301
;  NOP5();
	xcall _NOP5
	.dbline 302
;  NOP5();
	xcall _NOP5
	.dbline 303
;  NOP5();
	xcall _NOP5
	.dbline 304
;  NOP5();
	xcall _NOP5
	.dbline 305
;  NOP5();
	xcall _NOP5
	.dbline 306
;  PORTE&=~BIT(SAMPLE_START);  //SAMPLE_START置低
	cbi 0x3,4
	.dbline -2
	.dbline 307
; }//end start_sample
L60:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e start_mcuread_sample _start_mcuread_sample fV
;           temp -> R20
	.even
_start_mcuread_sample::
	xcall push_gset1
	.dbline -1
	.dbline 313
; 
; /*********************************************************
; 启动单片机读DDC采样数据
; *********************************************************/
; void start_mcuread_sample(void)
; {unsigned char temp;
	.dbline 314
;  PORTE&=~BIT(MCUREAD_START);  //MCUREAD_START置低
	cbi 0x3,5
	.dbline 315
;  NOP5();
	xcall _NOP5
	.dbline 316
;  PORTE|=BIT(MCUREAD_START);  //MCUREAD_START置高
	sbi 0x3,5
	.dbline 317
;  NOP5();
	xcall _NOP5
	.dbline 318
;  temp=DDCDATA_ADD;
	lds R20,5887
	.dbline 319
;  NOP5();
	xcall _NOP5
	.dbline 320
;  PORTE&=~BIT(MCUREAD_START); //MCUREAD_START置低
	cbi 0x3,5
	.dbline -2
	.dbline 321
; }//end start_sample
L61:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbend
	.dbfunc e aquire_data _aquire_data fV
;            cnt -> R20,R21
;       ddc_data -> R22
	.even
_aquire_data::
	xcall push_gset2
	.dbline -1
	.dbline 328
; 
; 
; /*********************************************************
; 通过串口获取DDC数据
; *********************************************************/
; void aquire_data(void)
; {unsigned char ddc_data;
	.dbline 330
; int cnt;
; start_sample();                //启动DDC数据采集
	xcall _start_sample
	.dbline 331
; asm("ldi R16,$20");
	ldi R16,$20
	.dbline 332
; delay1();                      //延时足够时间保证采样结束
	xcall _delay1
	.dbline 333
; start_mcuread_sample();        //启动MCU读
	xcall _start_mcuread_sample
	.dbline 334
; usart0_sendbyte(0x7E);         //发送起始字
	ldi R16,126
	xcall _usart0_sendbyte
	.dbline 335
; usart0_sendbyte(0x6F);        //发送地址字
	ldi R16,111
	xcall _usart0_sendbyte
	.dbline 336
; ddc_data=DDCDATA_ADD;         //假读一次
	lds R22,5887
	.dbline 337
; for(cnt=0;cnt<8192;cnt++)     //发送数据
	clr R20
	clr R21
L63:
	.dbline 338
	.dbline 339
	lds R22,5887
	.dbline 340
	mov R16,R22
	xcall _usart0_sendbyte
	.dbline 341
L64:
	.dbline 337
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 337
	cpi R20,0
	ldi R30,32
	cpc R21,R30
	brlt L63
	.dbline 342
; {
;  ddc_data=DDCDATA_ADD;
;  usart0_sendbyte(ddc_data);
; }
; usart0_sendbyte(0x7E);       //发送结束字
	ldi R16,126
	xcall _usart0_sendbyte
	.dbline -2
	.dbline 343
; }//end aquire_data
L62:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r cnt 20 I
	.dbsym r ddc_data 22 c
	.dbend
	.dbfunc e set_dds_freq _set_dds_freq fV
;           temp -> R10,R11
;       dds_freq -> y+6
	.even
_set_dds_freq::
	xcall push_arg4
	xcall push_gset3
	.dbline -1
	.dbline 349
; 
; /*********************************************************
; 设置DDS频率
; *********************************************************/
; void set_dds_freq(long dds_freq)
; {short temp;
	.dbline 350
;     temp=(short)(dds_freq>>16);
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	movw R10,R4
	.dbline 351
; 	send_instruct(temp,0x83);
	ldi R18,131
	movw R16,R10
	xcall _send_instruct
	.dbline 352
; 	temp=dds_freq%65536;
	ldi R20,0
	ldi R21,0
	ldi R22,1
	ldi R23,0
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall mod32s
	movw R10,R16
	.dbline 353
;   	send_instruct(temp,0x82); 
	ldi R18,130
	xcall _send_instruct
	.dbline -2
	.dbline 354
; }//set_dds_freq
L67:
	xcall pop_gset3
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r temp 10 S
	.dbsym l dds_freq 6 L
	.dbend
	.dbfunc e set_dds_scale _set_dds_scale fV
;           temp -> R20,R21
;        dds_amp -> R22,R23
	.even
_set_dds_scale::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 360
; 
; /*********************************************************
; 设置DDS幅度
; *********************************************************/
; void set_dds_scale(short dds_amp)
; {short temp=0x0;
	.dbline 360
	clr R20
	clr R21
	.dbline 361
;     temp=dds_amp&0x0FFF;
	movw R20,R22
	andi R21,15
	.dbline 362
; 	temp=temp|0x0000;
	.dbline 363
; 	send_instruct(temp,0x80);
	ldi R18,128
	movw R16,R20
	xcall _send_instruct
	.dbline -2
	.dbline 364
; }//set_dds_scale
L68:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 S
	.dbsym r dds_amp 22 S
	.dbend
	.dbfunc e set_dds_phase _set_dds_phase fV
;      dds_phase -> R20,R21
	.even
_set_dds_phase::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 370
; 
; /*********************************************************
; 设置DDS相位
; *********************************************************/
; void set_dds_phase(short dds_phase)
; {	send_instruct(dds_phase,0x81);
	.dbline 370
	ldi R18,129
	movw R16,R20
	xcall _send_instruct
	.dbline -2
	.dbline 371
; }//set_dds_phase
L69:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r dds_phase 20 S
	.dbend
	.dbfunc e set_dds_increment _set_dds_increment fV
;           temp -> R10,R11
;  dds_freqdelta -> y+6
	.even
_set_dds_increment::
	xcall push_arg4
	xcall push_gset3
	.dbline -1
	.dbline 377
; 
; /*********************************************************
; 设置DDS频率步进
; *********************************************************/
; void set_dds_increment(long dds_freqdelta)
; { short temp;
	.dbline 378
;   temp = (short)(dds_freqdelta>>16);
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	movw R10,R4
	.dbline 379
;   send_instruct(temp,0x85);
	ldi R18,133
	movw R16,R10
	xcall _send_instruct
	.dbline 380
;   temp = dds_freqdelta%65536;
	ldi R20,0
	ldi R21,0
	ldi R22,1
	ldi R23,0
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall mod32s
	movw R10,R16
	.dbline 381
;   send_instruct(temp,0x84);
	ldi R18,132
	xcall _send_instruct
	.dbline -2
	.dbline 382
; }//set_dds_increment
L70:
	xcall pop_gset3
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r temp 10 S
	.dbsym l dds_freqdelta 6 L
	.dbend
	.dbfunc e DDC_param_set _DDC_param_set fV
	.even
_DDC_param_set::
	xcall push_gset1
	.dbline -1
	.dbline 388
; 
; /*********************************************************
; DDC旁路设置
; *********************************************************/
; void DDC_param_set(void)
; { 
	.dbline 389
; switch(buffer[4])
	lds R20,_buffer+4
	clr R21
	cpi R20,0
	cpc R20,R21
	breq L76
X3:
	cpi R20,1
	ldi R30,0
	cpc R21,R30
	breq L77
	cpi R20,2
	ldi R30,0
	cpc R21,R30
	brne X5
	xjmp L78
X5:
	cpi R20,3
	ldi R30,0
	cpc R21,R30
	brne X6
	xjmp L79
X6:
	cpi R20,4
	ldi R30,0
	cpc R21,R30
	brne X7
	xjmp L80
X7:
	cpi R20,5
	ldi R30,0
	cpc R21,R30
	brne X8
	xjmp L81
X8:
	cpi R20,6
	ldi R30,0
	cpc R21,R30
	brne X9
	xjmp L82
X9:
	cpi R20,7
	ldi R30,0
	cpc R21,R30
	brne X10
	xjmp L83
X10:
	cpi R20,8
	ldi R30,0
	cpc R21,R30
	brne X11
	xjmp L84
X11:
	xjmp L73
X4:
	.dbline 390
; {case 0x00://接入NCO
L76:
	.dbline 391
;     ddc_param= ddc_param&0b1111111111111110;
	lds R24,_ddc_param
	lds R25,_ddc_param+1
	andi R24,254
	sts _ddc_param+1,R25
	sts _ddc_param,R24
	.dbline 392
;    break;
	xjmp L73
L77:
	.dbline 394
;  case 0x01://旁路NCO
;     ddc_param= ddc_param|0b0000000000000001;
	lds R24,_ddc_param
	lds R25,_ddc_param+1
	ori R24,1
	sts _ddc_param+1,R25
	sts _ddc_param,R24
	.dbline 395
;    break;
	xjmp L73
L78:
	.dbline 397
;  case 0x02://接入CIC
;     ddc_param= ddc_param&0b1111111111111101;
	lds R24,_ddc_param
	lds R25,_ddc_param+1
	andi R24,253
	sts _ddc_param+1,R25
	sts _ddc_param,R24
	.dbline 398
;    break;
	xjmp L73

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -