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

📄 251.s

📁 卡车仪表的单片机程序
💻 S
📖 第 1 页 / 共 5 页
字号:
; 
;  //2. NextChannel
;  ++ADCCurrentChannel;
	lds R24,_ADCCurrentChannel
	subi R24,255    ; addi 1
	sts _ADCCurrentChannel,R24
	.dbline 271
;  if(ADCCurrentChannel>5)
	ldi R24,5
	lds R2,_ADCCurrentChannel
	cp R24,R2
	brsh L45
	.dbline 272
;    ADCCurrentChannel = 0; 
	clr R2
	sts _ADCCurrentChannel,R2
L45:
	.dbline 275
;  
;  //3.Set MUX
;  adc_setmux(ADCCurrentChannel+1);
	lds R16,_ADCCurrentChannel
	subi R16,255    ; addi 1
	rcall _adc_setmux
	.dbline 277
;  //4.CLEAR INTERUPT FLAG ADIF
;  ADCSR |= BIT(ADIF);
	sbi 0x6,4
	.dbline -2
L44:
	rcall pop_lset
	.dbline 0 ; func end
	reti
	.dbend
	.area vector(rom, abs)
	.org 2
	rjmp _int0_isr
	.area text(rom, con, rel)
	.dbfile D:\prog251\251.c
	.dbfunc e int0_isr _int0_isr fV
	.even
_int0_isr::
	st -y,R2
	st -y,R3
	st -y,R4
	st -y,R5
	st -y,R16
	st -y,R17
	st -y,R18
	st -y,R19
	st -y,R24
	st -y,R25
	st -y,R26
	st -y,R27
	st -y,R30
	in R2,0x3f
	st -y,R2
	rcall push_gset2
	.dbline -1
	.dbline 282
; }
; 
; #pragma interrupt_handler int0_isr:2
; void int0_isr(void)//speed
; {
	.dbline 285
;  //external interupt on INT0
;  //1.Read Interval
;  CLI();
	cli
	.dbline 286
;  if(SpeedUltraLow)
	lds R2,_SpeedUltraLow
	tst R2
	breq L48
	.dbline 287
;    SpeedUltraLow = 0;
	clr R2
	sts _SpeedUltraLow,R2
	rjmp L49
L48:
	.dbline 288
;  else if (!(TIFR&BIT(TOV1)))
	in R2,0x38
	sbrc R2,2
	rjmp L50
	.dbline 289
;  {
	.dbline 290
;    TimeInterval = TCNT1;
	in R2,0x2c
	in R3,0x2d
	clr R4
	clr R5
	sts _TimeInterval+1,R3
	sts _TimeInterval,R2
	sts _TimeInterval+2+1,R5
	sts _TimeInterval+2,R4
	.dbline 291
;    TimeIntervalRefreshed = 1;
	ldi R24,1
	sts _TimeIntervalRefreshed,R24
	.dbline 292
;  }
L50:
L49:
	.dbline 295
;  
;  //Mileage Counting
;  MileagePulseCnt++;
	lds R24,_MileagePulseCnt
	lds R25,_MileagePulseCnt+1
	adiw R24,1
	sts _MileagePulseCnt+1,R25
	sts _MileagePulseCnt,R24
	.dbline 296
;  if (MileagePulseCnt>=998)
	cpi R24,230
	ldi R30,3
	cpc R25,R30
	brlo L52
	.dbline 297
;  {
	.dbline 298
;    mileage++;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R4,_mileage+2
	lds R5,_mileage+2+1
	lds R2,_mileage
	lds R3,_mileage+1
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	sts _mileage+1,R3
	sts _mileage,R2
	sts _mileage+2+1,R5
	sts _mileage+2,R4
	.dbline 299
;    MileageCurrent++;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	lds R4,_MileageCurrent+2
	lds R5,_MileageCurrent+2+1
	lds R2,_MileageCurrent
	lds R3,_MileageCurrent+1
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	sts _MileageCurrent+1,R3
	sts _MileageCurrent,R2
	sts _MileageCurrent+2+1,R5
	sts _MileageCurrent+2,R4
	.dbline 300
;    MileageSaved = 0;
	clr R2
	sts _MileageSaved,R2
	.dbline 301
;    MileagePulseCnt = 0;
	clr R3
	sts _MileagePulseCnt+1,R3
	sts _MileagePulseCnt,R2
	.dbline 302
;  }
L52:
	.dbline 305
; 
;  //clear Timer
;  TCNT1H = 0;
	clr R2
	out 0x2d,R2
	.dbline 306
;  TCNT1L = 0;
	out 0x2c,R2
	.dbline -2
L47:
	rcall pop_gset2
	ld R2,y+
	out 0x3f,R2
	ld R30,y+
	ld R27,y+
	ld R26,y+
	ld R25,y+
	ld R24,y+
	ld R19,y+
	ld R18,y+
	ld R17,y+
	ld R16,y+
	ld R5,y+
	ld R4,y+
	ld R3,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.area vector(rom, abs)
	.org 4
	rjmp _int1_isr
	.area text(rom, con, rel)
	.dbfile D:\prog251\251.c
	.dbfunc e int1_isr _int1_isr fV
	.even
_int1_isr::
	st -y,R2
	st -y,R3
	st -y,R24
	st -y,R25
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 311
	.dbline 313
	lds R24,_NPulseCnt
	lds R25,_NPulseCnt+1
	adiw R24,1
	sts _NPulseCnt+1,R25
	sts _NPulseCnt,R24
	.dbline 314
	ldi R24,120
	ldi R25,0
	lds R2,_NPulseCnt
	lds R3,_NPulseCnt+1
	cp R24,R2
	cpc R25,R3
	brsh L55
	.dbline 315
	sts _NPulseCnt+1,R25
	sts _NPulseCnt,R24
L55:
	.dbline -2
L54:
	ld R2,y+
	out 0x3f,R2
	ld R25,y+
	ld R24,y+
	ld R3,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 320
; }
; 
; #pragma interrupt_handler int1_isr:3
; void int1_isr(void)
; {
;  //external interupt on INT1
;  NPulseCnt++;
;  if(NPulseCnt>MaxNPulse)
;    NPulseCnt = MaxNPulse; //Limit
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 322
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 323
;  port_init();
	rcall _port_init
	.dbline 325
;  //timer1_init();
;  timer2_init();
	rcall _timer2_init
	.dbline 326
;  spi_init();
	rcall _spi_init
	.dbline 329
;  //adc_init();
; 
;  MCUCR = 0x0F;
	ldi R24,15
	out 0x35,R24
	.dbline 330
;  GICR  = 0x00;
	clr R2
	out 0x3b,R2
	.dbline 331
;  TIMSK = 0x45; //timer interrupt sources
	ldi R24,69
	out 0x39,R24
	.dbline 332
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L57:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	sbiw R28,1
	.dbline -1
	.dbline 337
;  //all peripherals are now initialized
; }
; 
; void main(void)
; {
	.dbline 339
;  //Initiate port,timer2,spi& others
;  init_devices();//port&timer2 for motor control
	rcall _init_devices
	.dbline 340
;  ParallelOutputCmd = 0x00;
	clr R2
	clr R3
	sts _ParallelOutputCmd+1,R3
	sts _ParallelOutputCmd,R2
	.dbline 341
;  ParallelOutput();
	rcall _ParallelOutput
	.dbline 342
;  MileageLoding();
	rcall _MileageLoding
	.dbline 343
;  init_lcd();
	rcall _init_lcd
	.dbline 344
;  LCDDecoding();
	rcall _LCDDecoding
	.dbline 345
;  lcd_display(lcdshow,LCDContent,13);
	ldi R24,13
	std y+0,R24
	ldi R18,<_LCDContent
	ldi R19,>_LCDContent
	ldi R16,<_lcdshow
	ldi R17,>_lcdshow
	rcall _lcd_display
	rjmp L60
L59:
	.dbline 348
;  //motor turn to zero
;  while(SpeedMotorSetting!=SpeedMotorCurrent)
;  {
	.dbline 349
;     if(MotorBlocked==0)
	lds R2,_MotorBlocked
	tst R2
	brne L62
	.dbline 350
; 	  motor();
	rcall _motor
L62:
	.dbline 351
L60:
	.dbline 347
	lds R2,_SpeedMotorCurrent
	lds R3,_SpeedMotorCurrent+1
	lds R4,_SpeedMotorSetting
	lds R5,_SpeedMotorSetting+1
	cp R4,R2
	cpc R5,R3
	brne L59
	.dbline 354
;  }
; 										
;  //Initiate timer1,adc,OPEN int0,1
;  timer0_init();
	rcall _timer0_init
	.dbline 355
;  timer1_init();
	rcall _timer1_init
	.dbline 356
;  adc_init();
	rcall _adc_init
	.dbline 357
;  GICR  = 0xC0;
	ldi R24,192
	out 0x3b,R24
	.dbline 358
;  watchdog_init();
	rcall _watchdog_init
	rjmp L65
L64:
	.dbline 361
;  //Initialization Finished!!! Insert your functional code here...
;  while(1)
;  {
	.dbline 362
;     if(MotorBlocked==0)//unblocked by timer2
	lds R2,_MotorBlocked
	tst R2
	brne L67
	.dbline 363
; 	  motor();
	rcall _motor
L67:
	.dbline 364
; 	if(ParallelBlocked==0)//unblocked by timer0
	lds R2,_ParallelBlocked
	tst R2
	brne L69
	.dbline 365
; 	  Parallel();
	rcall _Parallel
L69:
	.dbline 366
; 	if(CalculateBlocked==0)//unblocked by timer0
	lds R2,_CalculateBlocked
	tst R2
	brne L71
	.dbline 367
; 	  Calculate();
	rcall _Calculate
L71:
	.dbline 368
; 	if(MileageSaveBlocked==0)//unblocked by timer1_overflow
	lds R2,_MileageSaveBlocked
	tst R2
	brne L73
	.dbline 369
; 	  MileageSaving();
	rcall _MileageSaving
L73:
	.dbline 370
L65:
	.dbline 360
	rjmp L64
X0:
	.dbline -2
L58:
	adiw R28,1
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e motor _motor fV
;  anticlockwise -> R20
;      clockwise -> R22
; AnticlockwiseCmd -> R10
;   ClockwiseCmd -> R12
;              i -> R14
	.even
_motor::
	rcall push_gset5
	.dbline -1
	.dbline 377
;  }
; }
; 
; //===============================================
; //=============MOTOR SUBROUTINE=================
; //================================================
; void motor(void)
; {
	.dbline 379
;  	 uchar i;
;  	 uchar clockwise = 0x00;//test
	clr R22
	.dbline 380
; 	 uchar anticlockwise = 0x00;
	clr R20
	.dbline 381
; 	 uchar ClockwiseCmd=0x00;//Original, reversed motor not inverted
	clr R12
	.dbline 382
; 	 uchar AnticlockwiseCmd=0x00;//Original, reversed motor not inverted
	clr R10
	.dbline 385
; 
;  //TEST
;  PORTB ^= BIT(2);	 
	ldi R24,4
	in R2,0x18
	eor R2,R24
	out 0x18,R2
	.dbline 387
; 	 //LIMITING
; 	 if(SpeedMotorSetting>MaxAngle)
	ldi R24,2880
	ldi R25,11
	lds R2,_SpeedMotorSetting
	lds R3,_SpeedMotorSetting+1
	cp R24,R2
	cpc R25,R3
	brge L76
	.dbline 388
; 	    SpeedMotorSetting = MaxAngle;
	sts _SpeedMotorSetting+1,R25
	sts _SpeedMotorSetting,R24
L76:
	.dbline 389
; 	 if(NMotorSetting>MaxAngle)
	ldi R24,2880
	ldi R25,11
	lds R2,_NMotorSetting
	lds R3,_NMotorSetting+1
	cp R24,R2
	cpc R25,R3
	brge L78
	.dbline 390
; 	    NMotorSetting = MaxAngle;		
	sts _NMotorSetting+1,R25
	sts _NMotorSetting,R24
L78:
	.dbline 393
; 	 
;  	 //CALCULATE THE DIRECTION OF ALL MOTOR
; 	 if(SpeedMotorCurrent<SpeedMotorSetting)
	lds R2,_SpeedMotorSetting
	lds R3,_SpeedMotorSetting+1
	lds R4,_SpeedMotorCurrent
	lds R5,_SpeedMotorCurrent+1
	cp R4,R2
	cpc R5,R3
	brge L80
	.dbline 394
; 	 {	 	 
	.dbline 395
; 	   SpeedMotorCurrent++;
	movw R24,R4
	adiw R24,1
	sts _SpeedMotorCurrent+1,R25
	sts _SpeedMotorCurrent,R24
	.dbline 396
; 	   ClockwiseCmd |=BIT(0);
	mov R24,R12
	ori R24,1
	mov R12,R24
	.dbline 397
; 	 }
	rjmp L81
L80:
	.dbline 398
; 	 else if (SpeedMotorCurrent>SpeedMotorSetting)
	lds R2,_SpeedMotorSetting
	lds R3,_SpeedMotorSetting+1
	lds R4,_SpeedMotorCurrent
	lds R5,_SpeedMotorCurrent+1
	cp R2,R4
	cpc R3,R5
	brge L82
	.dbline 399
; 	 {
	.dbline 400
; 	   SpeedMotorCurrent--;
	movw R24,R4
	sbiw R24,1
	sts _SpeedMotorCurrent+1,R25
	sts _SpeedMotorCurrent,R24
	.dbline 401
; 	   AnticlockwiseCmd |=BIT(0);
	mov R24,R10
	ori R24,1
	mov R10,R24
	.dbline 402
; 	 }
L82:
L81:
	.dbline 403
; 	 if(NMotorCurrent<NMotorSetting)
	lds R2,_NMotorSetting
	lds R3,_NMotorSetting+1
	lds R4,_NMotorCurrent
	lds R5,_NMotorCurrent+1
	cp R4,R2
	cpc R5,R3
	brge L84
	.dbline 404
; 	 {
	.dbline 405
; 	   NMotorCurrent++;
	movw R24,R4
	adiw R24,1
	sts _NMotorCurrent+1,R25
	sts _NMotorCurrent,R24
	.dbline 406
; 	   ClockwiseCmd |=BIT(1); //SPEED invert
	mov R24,R12
	ori R24,2
	mov R12,R24
	.dbline 407
; 	 }
	rjmp L85
L84:
	.dbline 408
; 	 else if (NMotorCurrent>NMotorSetting)
	lds R2,_NMotorSetting
	lds R3,_NMotorSetting+1
	lds R4,_NMotorCurrent
	lds R5,_NMotorCurrent+1
	cp R2,R4
	cpc R3,R5
	brge L86
	.dbline 409
; 	 {
	.dbline 410
; 	   NMotorCurrent--;
	movw R24,R4
	sbiw R24,1
	sts _NMotorCurrent+1,R25
	sts _NMotorCurrent,R24
	.dbline 411
; 	   AnticlockwiseCmd |= BIT(1); //SPEED invert
	mov R24,R10
	ori R24,2
	mov R10,R24
	.dbline 412
; 	 }
L86:
L85:
	.dbline 413
; 	 for(i=0;i<=5;i++)
	clr R14
	rjmp L91
L88:
	.dbline 414
; 	 {
	.dbline 415
; 	   if(VoltageMotorCurrent[i]<VoltageMotorSetting[i])
	ldi R24,2
	mul R24,R14
	ldi R24,<_VoltageMotorSetting
	ldi R25,>_VoltageMotorSetting
	movw R30,R0
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	ldi R24,<_VoltageMotorCurrent
	ldi R25,>_VoltageMotorCurrent
	movw R30,R0
	add R30,R24
	adc R31,R25
	ldd R4,z+0
	ldd R5,z+1
	cp R4,R2
	cpc R5,R3
	brsh L92
	.dbline 416
; 	   {
	.dbline 417
; 	     VoltageMotorCurrent[i]++;
	ldi R24,2
	mul R24,R14
	movw R2,R0
	ldi R24,<_VoltageMotorCurrent
	ldi R25,>_VoltageMotorCurrent
	add R2,R24
	adc R3,R25
	movw R30,R2
	ldd R24,z+0
	ldd R25,z+1
	adiw R24,1
	std z+1,R25
	std z+0,R24
	.dbline 418
; 		 ClockwiseCmd |=BIT((i+VoltageMotorBias));
	mov R17,R14
	subi R17,254    ; addi 2
	ldi R16,1
	rcall lsl8
	or R12,R16
	.dbline 419
; 	   }
	rjmp L93
L92:
	.dbline 420
; 	   else if(VoltageMotorCurrent[i]>VoltageMotorSetting[i])
	ldi R24,2
	mul R24,R14
	ldi R24,<_VoltageMotorSetting
	ldi R25,>_VoltageMotorSetting
	movw R30,R0
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	ldi R24,<_VoltageMotorCurrent
	ldi R25,>_VoltageMotorCurrent
	movw R30,R0
	add R30,R24
	adc R31,R25
	ldd R4,z+0
	ldd R5,z+1
	cp R2,R4
	cpc R3,R5
	brsh L94
	.dbline 421
; 	   {
	.dbline 422
; 	     VoltageMotorCurrent[i]--;
	ldi R24,2
	mul R24,R14
	movw R2,R0
	ldi R24,<_VoltageMotorCurrent
	ldi R25,>_VoltageMotorCurrent
	add R2,R24
	adc R3,R25
	movw R30,R2
	ldd R24,z+0
	ldd R25,z+1
	sbiw R24,1
	std z+1,R25
	std z+0,R24
	.dbline 423
; 		 AnticlockwiseCmd |=BIT((i+VoltageMotorBias));
	mov R17,R14
	subi R17,254    ; addi 2
	ldi R16,1
	rcall lsl8
	or R10,R16
	.dbline 424
; 	   }
L94:
L93:
	.dbline 425
L89:
	.dbline 413
	inc R14
L91:
	.dbline 413
	ldi R24,5
	cp R24,R14
	brlo X1
	rjmp L88
X1:

⌨️ 快捷键说明

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