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

📄 m16pwm-led.s

📁 电动车控制器
💻 S
📖 第 1 页 / 共 2 页
字号:
	ldi R25,0
	cp R24,R20
	cpc R25,R21
	brsh L32
	.dbline 184
	ldi R20,208
L32:
	.dbline 185
;    if(ad_tmp<0x30)ad_tmp=0x30;
	cpi R20,48
	ldi R30,0
	cpc R21,R30
	brsh L34
	.dbline 185
	ldi R20,48
	ldi R21,0
L34:
	.dbline 186
;    ad_tmp-=0x30;
	subi R20,48
	sbci R21,0
	.dbline 187
;    AdResult=(ad_tmp*0xff/0xa0)&0x00ff-1;   
	ldi R16,255
	ldi R17,0
	movw R18,R20
	xcall empy16s
	ldi R18,160
	ldi R19,0
	xcall div16u
	movw R24,R16
	andi R24,254
	andi R25,0
	sts _AdResult,R24
	.dbline -2
L31:
	xcall pop_gset1
	ld R16,y+
	out 0x3f,R16
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R19,y+
	ld R18,y+
	ld R17,y+
	ld R16,y+
	.dbline 0 ; func end
	reti
	.dbsym r ad_tmp 20 i
	.dbend
	.area vector(rom, abs)
	.org 32
	jmp _timer1_comp_isr
	.area text(rom, con, rel)
	.dbfile D:\EBIKE\eb_pro\M16PWM_led\m16pwm-led.c
	.dbfunc e timer1_comp_isr _timer1_comp_isr fV
;             tt -> <dead>
	.even
_timer1_comp_isr::
	st -y,R2
	st -y,R24
	st -y,R25
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 192
;    //LedBuf[0]=AdResult;
; } 
; #pragma interrupt_handler timer1_comp_isr:9
; void timer1_comp_isr(void)
; {
	.dbline 195
;  //compare occured TCNT1=OCR1
;  uchar tt;
;     TCNT1 = 0xC2F7; //setup 
	ldi R24,49911
	ldi R25,194
	out 0x2d,R25
	out 0x2c,R24
	.dbline 199
;     //PORTD ^=0x60;		
;     //LedDp[second_data%4]=1;
; 	//LedBuf[0]=second_data;
;     if(++second_data>=60)
	lds R24,_second_data
	subi R24,255    ; addi 1
	mov R2,R24
	sts _second_data,R2
	cpi R24,60
	brlo L37
	.dbline 200
;     {
	.dbline 201
; 	    second_data=0;
	clr R2
	sts _second_data,R2
	.dbline 202
;         if(++minut_data>=60)
	lds R24,_minut_data
	subi R24,255    ; addi 1
	mov R2,R24
	sts _minut_data,R2
	cpi R24,60
	brlo L39
	.dbline 203
; 	    {
	.dbline 204
; 	        minut_data=0;
	clr R2
	sts _minut_data,R2
	.dbline 205
; 		    if(++hour_data>=24)	 
	lds R24,_hour_data
	subi R24,255    ; addi 1
	mov R2,R24
	sts _hour_data,R2
	cpi R24,24
	brlo L41
	.dbline 206
; 	        {
	.dbline 207
; 	            hour_data=0;
	clr R2
	sts _hour_data,R2
	.dbline 208
; 	        }
L41:
	.dbline 209
;     	}
L39:
	.dbline 210
L37:
	.dbline -2
L36:
	ld R2,y+
	out 0x3f,R2
	ld R25,y+
	ld R24,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbsym l tt 1 c
	.dbend
	.dbfunc e led_display _led_display fV
;           tmp1 -> R22
;           tmp0 -> R10
;          delay -> R20
	.even
_led_display::
	xcall push_gset3
	mov R20,R16
	.dbline -1
	.dbline 216
;      }		
;  
; }
; 
; //led display
; void led_display(uchar delay)
; {
	.dbline 218
;   uchar tmp0,tmp1;
;   tmp0=LedBuf[0];
	lds R10,_LedBuf
	.dbline 219
;   tmp1=LedBuf[1];
	lds R22,_LedBuf+1
	.dbline 220
;   if(tmp0>99)tmp0=99;
	ldi R24,99
	cp R24,R10
	brsh L45
	.dbline 220
	mov R10,R24
L45:
	.dbline 221
;   if(tmp1>99)tmp1=99;  
	ldi R24,99
	cp R24,R22
	brsh L47
	.dbline 221
	ldi R22,99
L47:
	.dbline 222
;   PORTB = ~0x08;  
	ldi R24,247
	out 0x18,R24
	.dbline 223
;   PORTA = LedTab[(tmp0%10)]; 
	ldi R18,10
	ldi R19,0
	mov R16,R10
	clr R17
	xcall mod16s
	movw R30,R16
	ldi R24,<_LedTab
	ldi R25,>_LedTab
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 224
;   if(LedDp&0x01)PORTB|=0x10;
	lds R2,_LedDp
	sbrs R2,0
	rjmp L49
	.dbline 224
	sbi 0x18,4
	xjmp L50
L49:
	.dbline 225
;   else PORTB&=0xEF;
	in R24,0x18
	andi R24,239
	out 0x18,R24
L50:
	.dbline 226
;   ms_delay(delay);
	mov R16,R20
	clr R17
	xcall _ms_delay
	.dbline 228
;      
;   PORTB = ~0x04;  
	ldi R24,251
	out 0x18,R24
	.dbline 229
;   PORTA = LedTab[((tmp0/10)&0x0f)];
	ldi R18,10
	ldi R19,0
	mov R16,R10
	clr R17
	xcall div16s
	movw R30,R16
	andi R30,15
	andi R31,0
	ldi R24,<_LedTab
	ldi R25,>_LedTab
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 230
;   if(LedDp&0x02)PORTB|=0x10;
	lds R2,_LedDp
	sbrs R2,1
	rjmp L51
	.dbline 230
	sbi 0x18,4
	xjmp L52
L51:
	.dbline 231
;   else PORTB&=0xEF;
	in R24,0x18
	andi R24,239
	out 0x18,R24
L52:
	.dbline 232
;   ms_delay(delay);
	mov R16,R20
	clr R17
	xcall _ms_delay
	.dbline 234
;     
;   PORTB = ~0x02;  
	ldi R24,253
	out 0x18,R24
	.dbline 235
;   PORTA = LedTab[(tmp1%10)];
	ldi R18,10
	ldi R19,0
	mov R16,R22
	clr R17
	xcall mod16s
	movw R30,R16
	ldi R24,<_LedTab
	ldi R25,>_LedTab
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 236
;   if(LedDp&0x04)PORTB|=0x10;
	lds R2,_LedDp
	sbrs R2,2
	rjmp L53
	.dbline 236
	sbi 0x18,4
	xjmp L54
L53:
	.dbline 237
;   else PORTB&=0xEF;
	in R24,0x18
	andi R24,239
	out 0x18,R24
L54:
	.dbline 238
;   ms_delay(delay); 
	mov R16,R20
	clr R17
	xcall _ms_delay
	.dbline 240
;    
;   PORTB = ~0x01;  
	ldi R24,254
	out 0x18,R24
	.dbline 241
;   PORTA = LedTab[((tmp1/10)&0x0f)];
	ldi R18,10
	ldi R19,0
	mov R16,R22
	clr R17
	xcall div16s
	movw R30,R16
	andi R30,15
	andi R31,0
	ldi R24,<_LedTab
	ldi R25,>_LedTab
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 242
;   if(LedDp&0x08)PORTB|=0x10;
	lds R2,_LedDp
	sbrs R2,3
	rjmp L55
	.dbline 242
	sbi 0x18,4
	xjmp L56
L55:
	.dbline 243
;   else PORTB&=0xEF;
	in R24,0x18
	andi R24,239
	out 0x18,R24
L56:
	.dbline 244
;   ms_delay(delay); 
	mov R16,R20
	clr R17
	xcall _ms_delay
	.dbline -2
L43:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r tmp1 22 c
	.dbsym r tmp0 10 c
	.dbsym r delay 20 c
	.dbend
	.dbfunc e ms_delay _ms_delay fV
;             d1 -> R20,R21
;             d2 -> R22,R23
;          delay -> R16,R17
	.even
_ms_delay::
	xcall push_gset2
	.dbline -1
	.dbline 249
;     
;   
; }
; void ms_delay(uint delay)
; {
	.dbline 251
;     int d1,d2;
; 	for(d1=0;d1<delay;d1++)
	clr R20
	clr R21
	xjmp L61
L58:
	.dbline 252
; 	{
	.dbline 253
	clr R22
	clr R23
L62:
	.dbline 253
L63:
	.dbline 253
	subi R22,255  ; offset = 1
	sbci R23,255
	.dbline 253
	cpi R22,232
	ldi R30,3
	cpc R23,R30
	brlt L62
	.dbline 254
L59:
	.dbline 251
	subi R20,255  ; offset = 1
	sbci R21,255
L61:
	.dbline 251
	cp R20,R16
	cpc R21,R17
	brlo L58
	.dbline -2
L57:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r d1 20 I
	.dbsym r d2 22 I
	.dbsym r delay 16 i
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 258
; 	   for(d2=0;d2<1000;d2++);
; 	}
; }
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
	.dbline 260
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 261
;  port_init();
	xcall _port_init
	.dbline 262
;  uart0_init();
	xcall _uart0_init
	.dbline 263
;  timer1_init();
	xcall _timer1_init
	.dbline 264
;  adc_init();
	xcall _adc_init
	.dbline 265
;  MCUCR = 0x02;
	ldi R24,2
	out 0x35,R24
	.dbline 266
;  GICR  = 0x40;
	ldi R24,64
	out 0x3b,R24
	.dbline 267
;  TIMSK = 0x04; //timer interrupt sources
	ldi R24,4
	out 0x39,R24
	.dbline 269
;  
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L66:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
;              i -> <dead>
;        leddptt -> R12
;           ttmp -> R12
;            key -> R22,R23
;            led -> R10,R11
;            adc -> R20,R21
	.even
_main::
	.dbline -1
	.dbline 275
;  //all peripherals are now initialised
; }
; 
; ////////////////////////////////////////////////////////////////////////////////
; void main()
; {
	.dbline 276
;   int i,adc=0,led=0,key=0;
	clr R20
	clr R21
	.dbline 276
	clr R10
	clr R11
	.dbline 276
	clr R22
	clr R23
	.dbline 277
;   uchar ttmp,leddptt=0;
	clr R12
	.dbline 278
;   init_devices();
	xcall _init_devices
	.dbline 279
;   temp_data=0x13;
	ldi R24,19
	sts _temp_data,R24
	xjmp L69
L68:
	.dbline 281
;   while(1)
;   {
	.dbline 287
;      
;    //display second flag
;    
;    
;     
;      if(++led>240)
	movw R24,R10
	adiw R24,1
	movw R10,R24
	ldi R24,240
	ldi R25,0
	cp R24,R10
	cpc R25,R11
	brge L71
	.dbline 288
;      {     		
	.dbline 289
; 		PORTD ^= (LRledReg<<3);//LR-LED		
	lds R2,_LRledReg
	lsl R2
	lsl R2
	lsl R2
	in R3,0x12
	eor R3,R2
	out 0x12,R3
	.dbline 290
;         led=0;
	clr R10
	clr R11
	.dbline 291
; 		M8Mode ^= (LRledReg&0x03);
	lds R24,_LRledReg
	andi R24,3
	lds R2,_M8Mode
	eor R2,R24
	sts _M8Mode,R2
	.dbline 292
;      }
L71:
	.dbline 293
;      if(++adc>100)
	subi R20,255  ; offset = 1
	sbci R21,255
	ldi R24,100
	ldi R25,0
	cp R24,R20
	cpc R25,R21
	brge L73
	.dbline 294
;      {
	.dbline 295
;          tx_pack();	
	xcall _tx_pack
	.dbline 296
; 		 ADCSRA |=(1<<ADSC);  //启动AD转换 
	sbi 0x6,6
	.dbline 297
;          adc=0;		 
	clr R20
	clr R21
	.dbline 298
;      }
L73:
	.dbline 299
; 	 if(++key>200)
	movw R24,R22
	adiw R24,1
	movw R22,R24
	ldi R24,200
	ldi R25,0
	cp R24,R22
	cpc R25,R23
	brge L75
	.dbline 300
; 	 {	     
	.dbline 301
; 		 key=0;
	clr R22
	clr R23
	.dbline 302
; 		 ttmp = PINC&0x03; 
	in R24,0x13
	andi R24,3
	mov R12,R24
	.dbline 303
; 		 if(ttmp==0x03)
	cpi R24,3
	brne L77
	.dbline 304
; 		 {
	.dbline 305
; 		     PORTD |=0x18;//关LR-LED
	in R24,0x12
	ori R24,24
	out 0x12,R24
	.dbline 306
; 			 M8Mode=0;
	clr R2
	sts _M8Mode,R2
	.dbline 307
; 		     LRledReg=0;
	sts _LRledReg,R2
	.dbline 308
; 		 } 
	xjmp L78
L77:
	.dbline 309
;          else LRledReg = (~(ttmp))&0x03;
	mov R24,R12
	com R24
	andi R24,3
	sts _LRledReg,R24
L78:
	.dbline 310
; 		 LedDp=LedDp<<1;
	lds R2,_LedDp
	lsl R2
	sts _LedDp,R2
	.dbline 311
; 		 if(LedDp>0x08)LedDp=0x01;
	ldi R24,8
	cp R24,R2
	brsh L79
	.dbline 311
	ldi R24,1
	sts _LedDp,R24
L79:
	.dbline 313
; 	 
; 	 }
L75:
	.dbline 314
	ldi R16,1
	xcall _led_display
	.dbline 316
L69:
	.dbline 280
	xjmp L68
X0:
	.dbline -2
L67:
	.dbline 0 ; func end
	ret
	.dbsym l i 1 I
	.dbsym r leddptt 12 c
	.dbsym r ttmp 12 c
	.dbsym r key 22 I
	.dbsym r led 10 I
	.dbsym r adc 20 I
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\EBIKE\eb_pro\M16PWM_led\m16pwm-led.c
_UartBuf::
	.blkb 10
	.dbsym e UartBuf _UartBuf A[10:10]c
_second_flag::
	.blkb 1
	.dbsym e second_flag _second_flag c
_second_data::
	.blkb 1
	.dbsym e second_data _second_data c
_minut_data::
	.blkb 1
	.dbsym e minut_data _minut_data c
_hour_data::
	.blkb 1
	.dbsym e hour_data _hour_data c
_temp_data::
	.blkb 1
	.dbsym e temp_data _temp_data c
_k::
	.blkb 2
	.dbsym e k _k I
_kk::
	.blkb 1
	.dbsym e kk _kk c

⌨️ 快捷键说明

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