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

📄 1602_main.s

📁 10K到5MHz的频率测量
💻 S
📖 第 1 页 / 共 2 页
字号:
	mov R10,R18
	mov R22,R16
	ldd R20,y+10
	ldd R21,y+11
	.dbline -1
	.dbline 211
; }
; //================================================================
; // 描述:在任意位置写任意多个字符
; // 入口:’row‘要写的字符所在的行,只能为1或2;
; //       ‘col’要写的字符所在的列,只能为0---15
; //       ‘num’要写字符的个数
; //       ‘pbuffer’要写字符的首地址
; //================================================================== 
; void	WriteChar(uchar row,uchar col,uchar num,uchar *pBuffer)
; {
	.dbline 213
; 	uchar i,t;
; 	if (row == 1)	row = 0x80 + col;
	cpi R22,1
	brne L38
X9:
	.dbline 213
	mov R22,R10
	subi R22,128    ; addi 128
	xjmp L39
L38:
	.dbline 214
; 	else	row = 0xC0 + col;
	mov R22,R10
	subi R22,64    ; addi 192
L39:
	.dbline 215
; 	writecom(row);
	mov R16,R22
	xcall _writecom
	.dbline 219
; 	//if (num<=0 | num>9)	num =0x30;
; 	//else	num = 0x30 + num;
; 
; 	PORTB|=(1<<RS);
	sbi 0x18,5
	.dbline 220
; 	s_ms(20);
	ldi R16,20
	ldi R17,0
	xcall _s_ms
	.dbline 221
; 	PORTB&=~(1<<RW);
	cbi 0x18,6
	.dbline 222
; 	s_ms(20);
	ldi R16,20
	ldi R17,0
	xcall _s_ms
	.dbline 223
; 	for(i=num;i!=0;i--)
	ldd R10,y+8
	xjmp L43
L40:
	.dbline 224
; 	{
	.dbline 225
; 		t = *pBuffer;
	movw R30,R20
	ldd R12,z+0
	.dbline 226
; 		s_ms(20);
	ldi R16,20
	ldi R17,0
	xcall _s_ms
	.dbline 227
; 		PORTA = t;
	out 0x1b,R12
	.dbline 228
; 		s_ms(20);
	ldi R16,20
	ldi R17,0
	xcall _s_ms
	.dbline 229
; 		PORTB|=(1<<EN);
	sbi 0x18,7
	.dbline 230
; 		s_ms(20);
	ldi R16,20
	ldi R17,0
	xcall _s_ms
	.dbline 231
; 		PORTB&=~(1<<EN);		
	cbi 0x18,7
	.dbline 232
; 		s_ms(20);		
	ldi R16,20
	ldi R17,0
	xcall _s_ms
	.dbline 233
; 		pBuffer++;
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 234
; 	}
L41:
	.dbline 223
	dec R10
L43:
	.dbline 223
	tst R10
	brne L40
X10:
	.dbline -2
L37:
	.dbline 0 ; func end
	xjmp pop_xgsetF03C
	.dbsym r t 12 c
	.dbsym r i 10 c
	.dbsym r pBuffer 20 pc
	.dbsym l num 8 c
	.dbsym r col 10 c
	.dbsym r row 22 c
	.dbend
	.area data(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602.h
_F::
	.blkb 3
	.area idata
	.byte 'F,61,0
	.area data(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602.h
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbsym e F _F A[3:3]c
_Hz::
	.blkb 3
	.area idata
	.byte 'H,'z,0
	.area data(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbsym e Hz _Hz A[3:3]c
_T::
	.blkb 3
	.area idata
	.byte 'T,61,0
	.area data(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbsym e T _T A[3:3]c
_S::
	.blkb 2
	.area idata
	.byte 'S,0
	.area data(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbsym e S _S A[2:2]c
_uS::
	.blkb 3
	.area idata
	.byte 'u,'S,0
	.area data(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbsym e uS _uS A[3:3]c
_dot::
	.blkb 2
	.area idata
	.byte 46,0
	.area data(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbsym e dot _dot A[2:2]c
	.area text(rom, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 14
; #include<iom16v.h>
; #include<macros.h>
; #include"1602.h"
; #define uint unsigned int
; #define uchar unsigned char  
; #define ulint unsigned long int
; uchar F[]={"F="},Hz[]={"Hz"},T[]={"T="};
; uchar S[]={"S"},uS[]={"uS"},dot[]={"."};
; float TT,FF;           
; ulint f,ff,T_int;
; uchar i,t,f_hign,f_low,hignf;
; 
; void port_init(void)
; {
	.dbline 15
;  DDRA  = 0xff;
	ldi R24,255
	out 0x1a,R24
	.dbline 16
;  PORTA = 0xff;
	out 0x1b,R24
	.dbline 17
;  PORTB = 0x00;
	clr R2
	out 0x18,R2
	.dbline 18
;  DDRB  = 0xF0;
	ldi R24,240
	out 0x17,R24
	.dbline 19
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 20
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 21
;  DDRD  = 0xff;
	ldi R24,255
	out 0x11,R24
	.dbline 22
;  PORTD = 0xff;
	out 0x12,R24
	.dbline -2
L44:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 30
; }
; 
; //TIMER0 initialize - prescale:1024
; // WGM: Normal
; // desired value: 8mSec
; // actual value:  8.000mSec (0.0%)
; void timer0_init(void)
; {
	.dbline 31
;  TCCR0 = 0x00; //stop
	clr R2
	out 0x33,R2
	.dbline 32
;  TCNT0 = 0x83; //set count  
	ldi R24,131
	out 0x32,R24
	.dbline 33
;  TCCR0 = 0x35; //start timer 
	ldi R24,53
	out 0x33,R24
	.dbline -2
L45:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 36
	jmp _timer0_ovf_isr
	.area text(rom, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
	.even
_timer0_ovf_isr::
	st -y,R24
	st -y,R25
	in R24,0x3f
	st -y,R24
	.dbline -1
	.dbline 38
; }
; 
; #pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
; void timer0_ovf_isr(void)
; {
	.dbline 39
;  TCNT0 = 0x83; //reload counter value
	ldi R24,131
	out 0x32,R24
	.dbline 40
;  t++;
	lds R24,_t
	subi R24,255    ; addi 1
	sts _t,R24
	.dbline -2
L46:
	.dbline 0 ; func end
	ld R24,y+
	out 0x3f,R24
	ld R25,y+
	ld R24,y+
	reti
	.dbend
	.dbfunc e timer1_init _timer1_init fV
	.even
_timer1_init::
	.dbline -1
	.dbline 46
; }
; 
; //TIMER1 initialize - prescale:Falling edge
; // WGM: 0) Normal, TOP=0xFFFF
; void timer1_init(void)
; {
	.dbline 47
;  TCCR1B = 0x00; //stop
	clr R2
	out 0x2e,R2
	.dbline 48
;  TCCR1A = 0x00;
	out 0x2f,R2
	.dbline 49
;  TCNT1H=0;
	out 0x2d,R2
	.dbline 50
;  TCNT1L=0;
	out 0x2c,R2
	.dbline 51
;  TCCR1B = 0x07; //start Timer
	ldi R24,7
	out 0x2e,R24
	.dbline -2
L47:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 32
	jmp _timer1_ovf_isr
	.area text(rom, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
	.dbfunc e timer1_ovf_isr _timer1_ovf_isr fV
	.even
_timer1_ovf_isr::
	st -y,R2
	st -y,R24
	st -y,R25
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 56
; }
; 
; #pragma interrupt_handler timer1_ovf_isr:iv_TIM1_OVF
; void timer1_ovf_isr(void)
; {
	.dbline 57
;  TCNT1H=0;
	clr R2
	out 0x2d,R2
	.dbline 58
;  TCNT1L=0;
	out 0x2c,R2
	.dbline 59
;  hignf++;
	lds R24,_hignf
	subi R24,255    ; addi 1
	sts _hignf,R24
	.dbline -2
L48:
	.dbline 0 ; func end
	ld R2,y+
	out 0x3f,R2
	ld R25,y+
	ld R24,y+
	ld R2,y+
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 64
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 65
;  port_init();
	xcall _port_init
	.dbline 66
;  timer0_init();
	xcall _timer0_init
	.dbline 67
;  timer1_init();
	xcall _timer1_init
	.dbline 68
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 69
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 70
;  TIMSK = 0x05; //timer interrupt sources
	ldi R24,5
	out 0x39,R24
	.dbline -2
L49:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	sbiw R28,4
	.dbline -1
	.dbline 75
; }
; 
; //主函数
; void main()
; {
	.dbline 76
;  CLI();
	cli
	.dbline 77
;  t=0;
	clr R2
	sts _t,R2
	.dbline 78
;  hignf=0;
	sts _hignf,R2
	.dbline 79
;  init_devices();
	xcall _init_devices
	.dbline 80
;  s_ms(5000);      //延时
	ldi R16,5000
	ldi R17,19
	xcall _s_ms
	.dbline 81
;  LcdInit();     //1602初始化
	xcall _LcdInit
	.dbline 82
;  WriteChar(1,0,2,T);
	ldi R24,<_T
	ldi R25,>_T
	std y+3,R25
	std y+2,R24
	ldi R24,2
	std y+0,R24
	clr R18
	ldi R16,1
	xcall _WriteChar
	.dbline 83
;  WriteChar(1,15,1,S);
	ldi R24,<_S
	ldi R25,>_S
	std y+3,R25
	std y+2,R24
	ldi R24,1
	std y+0,R24
	ldi R18,15
	ldi R16,1
	xcall _WriteChar
	.dbline 84
;  WriteNum(1,4,0);
	clr R2
	clr R3
	std y+1,R3
	std y+0,R2
	ldi R18,4
	ldi R19,0
	ldi R16,1
	ldi R17,0
	xcall _WriteNum
	.dbline 85
;  WriteChar(1,5,1,dot);    
	ldi R24,<_dot
	ldi R25,>_dot
	std y+3,R25
	std y+2,R24
	ldi R24,1
	std y+0,R24
	ldi R18,5
	ldi R16,1
	xcall _WriteChar
	.dbline 86
;  WriteChar(2,0,2,F);    
	ldi R24,<_F
	ldi R25,>_F
	std y+3,R25
	std y+2,R24
	ldi R24,2
	std y+0,R24
	clr R18
	ldi R16,2
	xcall _WriteChar
	.dbline 87
;  WriteChar(2,14,2,Hz);   
	ldi R24,<_Hz
	ldi R25,>_Hz
	std y+3,R25
	std y+2,R24
	ldi R24,2
	std y+0,R24
	ldi R18,14
	ldi R16,2
	xcall _WriteChar
	.dbline 88
;  SEI();
	sei
	xjmp L52
L51:
	.dbline 90
;  while(1)
;  { 
	.dbline 91
;   if(t==125)                     //100KHz~5MHz
	lds R24,_t
	cpi R24,125
	breq X16
	xjmp L54
X16:
X11:
	.dbline 92
;   {  
	.dbline 93
; 	f_low=TCNT1L;
	in R2,0x2c
	sts _f_low,R2
	.dbline 94
; 	f_hign=TCNT1H;
	in R2,0x2d
	sts _f_hign,R2
	.dbline 95
; 	f=(ulint)f_hign*256+f_low; //转换为unsigned long类型,否则所测频率最多32670HZ
	clr R3
	clr R4
	clr R5
	ldi R20,0
	ldi R21,1
	ldi R22,0
	ldi R23,0
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	movw R16,R20
	movw R18,R22
	xcall empy32u
	movw R2,R16
	movw R4,R18
	lds R6,_f_low
	clr R7
	clr R8
	clr R9
	add R2,R6
	adc R3,R7
	adc R4,R8
	adc R5,R9
	sts _f+1,R3
	sts _f,R2
	sts _f+2+1,R5
	sts _f+2,R4
	.dbline 96
; 	if(hignf)
	lds R2,_hignf
	tst R2
	breq L56
X12:
	.dbline 97
; 	{
	.dbline 98
; 		f+=hignf*65536;
	clr R3
	clr R4
	clr R5
	ldi R20,0
	ldi R21,0
	ldi R22,1
	ldi R23,0
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	movw R16,R20
	movw R18,R22
	xcall empy32s
	lds R4,_f+2
	lds R5,_f+2+1
	lds R2,_f
	lds R3,_f+1
	add R2,R16
	adc R3,R17
	adc R4,R18
	adc R5,R19
	sts _f+1,R3
	sts _f,R2
	sts _f+2+1,R5
	sts _f+2,R4
	.dbline 99
; 		hignf=0;
	clr R2
	sts _hignf,R2
	.dbline 100
; 	}
L56:
	.dbline 101
; 	FF=(float)f;
	lds R18,_f+2
	lds R19,_f+2+1
	lds R16,_f
	lds R17,_f+1
	xcall ulong2fp
	sts _FF+1,R17
	sts _FF,R16
	sts _FF+2+1,R19
	sts _FF+2,R18
	.dbline 102
; 	for(i=13;i>6;i--)
	ldi R24,13
	sts _i,R24
	xjmp L61
L58:
	.dbline 103
; 	{
	.dbline 104
; 		WriteNum(2,i,f%10);
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R18,_f+2
	lds R19,_f+2+1
	lds R16,_f
	lds R17,_f+1
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall mod32u
	std y+1,R17
	std y+0,R16
	lds R18,_i
	clr R19
	ldi R16,2
	ldi R17,0
	xcall _WriteNum
	.dbline 105
; 		f/=10;
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R18,_f+2
	lds R19,_f+2+1
	lds R16,_f
	lds R17,_f+1
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32u
	sts _f+1,R17
	sts _f,R16
	sts _f+2+1,R19
	sts _f+2,R18
	.dbline 106
; 	}
L59:
	.dbline 102
	lds R24,_i
	subi R24,1
	sts _i,R24
L61:
	.dbline 102
	ldi R24,6
	lds R2,_i
	cp R24,R2
	brlo L58
X13:
	.dbline 107
; 	 TT=1/FF;
	ldi R16,<L62
	ldi R17,>L62
	xcall lpm32
	ldi R24,<_FF
	ldi R25,>_FF
	st -y,R25
	st -y,R24
	xcall fpdiv1
	sts _TT+1,R17
	sts _TT,R16
	sts _TT+2+1,R19
	sts _TT+2,R18
	.dbline 108
; 	 T_int=(ulint)(TT*1000000000);
	ldi R16,<L63
	ldi R17,>L63
	xcall lpm32
	ldi R24,<_TT
	ldi R25,>_TT
	st -y,R25
	st -y,R24
	xcall fpmule1
	xcall fpint
	sts _T_int+1,R17
	sts _T_int,R16
	sts _T_int+2+1,R19
	sts _T_int+2,R18
	.dbline 109
; 	 for(i=14;i>5;i--)
	ldi R24,14
	sts _i,R24
	xjmp L67
L64:
	.dbline 110
; 	 {
	.dbline 111
; 		WriteNum(1,i,T_int%10);
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R18,_T_int+2
	lds R19,_T_int+2+1
	lds R16,_T_int
	lds R17,_T_int+1
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall mod32u
	std y+1,R17
	std y+0,R16
	lds R18,_i
	clr R19
	ldi R16,1
	ldi R17,0
	xcall _WriteNum
	.dbline 112
; 		T_int/=10;
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R18,_T_int+2
	lds R19,_T_int+2+1
	lds R16,_T_int
	lds R17,_T_int+1
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32u
	sts _T_int+1,R17
	sts _T_int,R16
	sts _T_int+2+1,R19
	sts _T_int+2,R18
	.dbline 113
; 	 }
L65:
	.dbline 109
	lds R24,_i
	subi R24,1
	sts _i,R24
L67:
	.dbline 109
	ldi R24,5
	lds R2,_i
	cp R24,R2
	brlo L64
X14:
	.dbline 114
; 	 t=0;
	clr R2
	sts _t,R2
	.dbline 115
; 	 init_devices();
	xcall _init_devices
	.dbline 116
;     }
L54:
	.dbline 117
;   }
L52:
	.dbline 89
	xjmp L51
X15:
	.dbline -2
L50:
	.dbline 0 ; func end
	adiw R28,4
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\我的资源\我的文件\电子技术\AVR\AVR学习\JASON'~2\M16频率计(10K-5MHz,误差0.1%以下)(已验证)\1602_main.c
_hignf::
	.blkb 1
	.dbsym e hignf _hignf c
_f_low::
	.blkb 1
	.dbsym e f_low _f_low c
_f_hign::
	.blkb 1
	.dbsym e f_hign _f_hign c
_t::
	.blkb 1
	.dbsym e t _t c
_i::
	.blkb 1
	.dbsym e i _i c
_T_int::
	.blkb 4
	.dbsym e T_int _T_int l
_ff::
	.blkb 4
	.dbsym e ff _ff l
_f::
	.blkb 4
	.dbsym e f _f l
_FF::
	.blkb 4
	.dbsym e FF _FF D
_TT::
	.blkb 4
	.dbsym e TT _TT D
	.area lit(rom, con, rel)
L63:
	.word 0x6b28,0x4e6e
L62:
	.word 0x0,0x3f80
; }

⌨️ 快捷键说明

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