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

📄 main.s

📁 avr bootloader 上位机源码
💻 S
📖 第 1 页 / 共 2 页
字号:
L33:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r TempInt 20 i
	.dbsym r i 22 i
	.dbend
	.dbfunc e CheckFlash _CheckFlash fc
;       TempInt2 -> R20,R21
;        TempInt -> R22,R23
;              i -> R10
	.even
_CheckFlash::
	xcall push_gset3
	.dbline -1
	.dbline 212
; 
; /*****************************************************************************/
; 
; char CheckFlash(void)
;   {
	.dbline 217
;     unsigned char i;							
;     unsigned int TempInt;
;     unsigned int TempInt2;
; 
;     for (i=0;i<PageByte;i+=2)
	clr R10
	xjmp L42
L39:
	.dbline 218
;       {
	.dbline 219
; 	   TempInt = read_program_memory(PageAddress + i,0x00);
	clr R18
	mov R2,R10
	clr R3
	lds R16,_PageAddress
	lds R17,_PageAddress+1
	add R16,R2
	adc R17,R3
	xcall _read_program_memory
	movw R22,R16
	.dbline 220
; 	   TempInt2 = PageBuffer[i] +(PageBuffer[i+1]<<8);
	ldi R24,<_PageBuffer+1
	ldi R25,>_PageBuffer+1
	mov R30,R10
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	clr R3
	mov R3,R2
	clr R2
	ldi R24,<_PageBuffer
	ldi R25,>_PageBuffer
	mov R30,R10
	clr R31
	add R30,R24
	adc R31,R25
	ldd R20,z+0
	clr R21
	add R20,R2
	adc R21,R3
	.dbline 221
; 	   if (TempInt != TempInt2)
	cp R16,R20
	cpc R17,R21
	breq L44
	.dbline 222
; 	     return 0;
	clr R16
	xjmp L38
L44:
	.dbline 223
L40:
	.dbline 217
	mov R24,R10
	subi R24,254    ; addi 2
	mov R10,R24
L42:
	.dbline 217
	mov R24,R10
	cpi R24,0
	brlt L39
	.dbline 224
;       } 
;     return 1;
	ldi R16,1
	.dbline -2
L38:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r TempInt2 20 i
	.dbsym r TempInt 22 i
	.dbsym r i 10 c
	.dbend
	.dbfunc e IsChar _IsChar fc
	.even
_IsChar::
	.dbline -1
	.dbline 230
;   }
; /*****************************************************************************/
; /* Serial Port Code										                     */
; /*****************************************************************************/
; unsigned char IsChar(void)
; {
	.dbline 235
; #if (ChipType == Atmega8)||(ChipType == Atmega16)||(ChipType == Atmega32)
;    if(UCSRA & 0x80)
; #endif
; #if (ChipType == Atmega64)||(ChipType == Atmega128)
;    if(UCSR1A & 0x80)
	lds R2,155
	sbrs R2,7
	rjmp L47
	.dbline 237
; #endif    
;      return 1;
	ldi R16,1
	xjmp L46
L47:
	.dbline 239
;    else 
;      return 0;	 
	clr R16
	.dbline -2
L46:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e RecChar _RecChar fc
	.even
_RecChar::
	.dbline -1
	.dbline 244
; }
; /*****************************************************************************/
; /*  		字符输入函数 		 */	
; unsigned char RecChar(void)
;   {
L50:
	.dbline 250
L51:
	.dbline 250
; #if (ChipType == Atmega8)||(ChipType == Atmega16)||(ChipType == Atmega32)  
;      while(!(UCSRA & 0x80));
;      return UDR;
; #endif
; #if (ChipType == Atmega64)||(ChipType == Atmega128)	
;      while(!(UCSR1A & 0x80));
	lds R2,155
	sbrs R2,7
	rjmp L50
	.dbline 251
;      return UDR1;
	lds R16,156
	.dbline -2
L49:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SendChar _SendChar fV
;              c -> R16
	.even
_SendChar::
	.dbline -1
	.dbline 256
; #endif 
;   }		
; /*****************************************************************************/
; void SendChar(unsigned char c)
;   {
L54:
	.dbline 262
L55:
	.dbline 262
; #if (ChipType == Atmega8)||(ChipType == Atmega16)||(ChipType == Atmega32)  	 
;     while (!(UCSRA&(1<<UDRE)));
;     UDR=c;
; #endif
; #if (ChipType == Atmega64)||(ChipType == Atmega128)
;     while (!(UCSR1A&(1<<UDRE1)));
	lds R2,155
	sbrs R2,5
	rjmp L54
	.dbline 263
;     UDR1=c;
	sts 156,R16
	.dbline -2
	.dbline 265
; #endif	
;   }
L53:
	.dbline 0 ; func end
	ret
	.dbsym r c 16 c
	.dbend
	.dbfunc e delay _delay fV
;              i -> R16,R17
	.even
_delay::
	.dbline -1
	.dbline 267
; void delay(void)  
;   {
	.dbline 269
	clr R16
	clr R17
	xjmp L61
L58:
	.dbline 269
L59:
	.dbline 269
	subi R16,255  ; offset = 1
	sbci R17,255
L61:
	.dbline 269
;     unsigned int i;
;     for (i=0;i<65530;i++);
	cpi R16,250
	ldi R30,255
	cpc R17,R30
	brlo L58
	.dbline -2
	.dbline 270
;   }
L57:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e ExecCode _ExecCode fV
	.even
_ExecCode::
	.dbline -1
	.dbline 274
; 
; /*****************************************************************************/
; void ExecCode(void)
;   {
	.dbline 276
; #ifdef RAMPZ_FLAG 
;     RAMPZ = 0;
	clr R2
	out 0x3b,R2
	.dbline 278
; #endif
;     INTVECREG=0x01;           //中断向量表移位允许
	ldi R24,1
	out 0x35,R24
	.dbline 279
;     INTVECREG=0x00;           //中断向量指向应用程序区
	out 0x35,R2
	.dbline 280
;     asm("jmp 0x0000");              
	jmp 0x0000
	.dbline -2
	.dbline 281
;   }
L62:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
;       BootFlag -> R20
	.even
_main::
	.dbline -1
	.dbline 284
; 		
; void main(void)
;   {
	.dbline 288
;     unsigned char BootFlag;
;     
; #ifdef InteClk                //如果使用内部时钟,读取时钟校准值
;        OSCCAL=read_flash(OscAddress);
	ldi R16,8191
	ldi R17,31
	xcall _read_flash
	sts 111,R16
	.dbline 300
; #endif
; 
; #if (ChipType == Atmega8)||(ChipType == Atmega16)||(ChipType == Atmega32)    
;     UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); //8位数据+1位停止
;     UCSRB = (1<<RXEN)|(1<<TXEN);       //允许串口发送和接收
;     UBRR = BAU;
; #endif	
; 
; #if (ChipType == Atmega64)||(ChipType == Atmega128)
; //------------------使用串口1为Boot口-----------------    
;     //UCSR1C=(1<<URSEL1)|(1<<UCSZ11)|(1<<UCSZ10); //8位数据+1位停止
; 	UCSR1C=(1<<UCSZ11)|(1<<UCSZ10);//|(1<<USBS1);
	ldi R24,6
	sts 157,R24
	.dbline 301
;     UCSR1B = (1<<RXEN1)|(1<<TXEN1);       //允许串口发送和接收
	ldi R24,24
	sts 154,R24
	.dbline 302
; 	UBRR1L=((fosc/16/baud1)-1)%256;
	ldi R24,12
	sts 153,R24
	.dbline 303
;     UBRR1H=((fosc/16/baud1)-1)/256;
	clr R2
	sts 152,R2
	.dbline 305
; #endif   
;     SendChar('>');              //通知PC机,BOOT下载准备就绪
	ldi R16,62
	xcall _SendChar
	.dbline 306
;     delay();                    //延时等待PC机响应
	xcall _delay
	.dbline 307
; 	delay();
	xcall _delay
	.dbline 308
; 	delay();
	xcall _delay
	.dbline 309
; 	delay();
	xcall _delay
	.dbline 310
; 	delay();
	xcall _delay
	.dbline 311
; 	delay();
	xcall _delay
	.dbline 312
; 	delay();
	xcall _delay
	.dbline 313
; 	delay();
	xcall _delay
	.dbline 314
;     BootFlag=UDR1;
	lds R20,156
	.dbline 315
;     if (BootFlag == '<') 
	cpi R20,60
	brne L64
	.dbline 316
;       {
	.dbline 317
; 	   SendChar(ChipType);
	ldi R16,52
	xcall _SendChar
L66:
	.dbline 318
L67:
	.dbline 318
; 	   while (RecChar()!='N');
	xcall _RecChar
	cpi R16,78
	brne L66
	.dbline 319
;          SendChar(BootSize);
	ldi R16,100
	xcall _SendChar
L69:
	.dbline 320
L70:
	.dbline 320
; 	   while (RecChar()!='N');	 
	xcall _RecChar
	cpi R16,78
	brne L69
	.dbline 321
;          SendChar(BootVer);
	ldi R16,102
	xcall _SendChar
	xjmp L73
L72:
	.dbline 323
;        while (1)
; 	   {
	.dbline 324
; 	     switch (RecChar())
	xcall _RecChar
	mov R20,R16
	clr R21
	cpi R20,69
	ldi R30,0
	cpc R21,R30
	breq L79
	cpi R20,69
	ldi R30,0
	cpc R21,R30
	brlt L76
L83:
	cpi R20,87
	ldi R30,0
	cpc R21,R30
	breq L78
	xjmp L76
X3:
	.dbline 325
; 	       {
L78:
	.dbline 326
; 	         case 'W': FlashLoad(); break;
	xcall _FlashLoad
	.dbline 326
	xjmp L76
L79:
	.dbline 327
; 	         case 'E': { 
	.dbline 328
; 	         	     SendChar('E');  //通知PC机,进入运用程序区
	ldi R16,69
	xcall _SendChar
L80:
	.dbline 329
L81:
	.dbline 329
; 					 while (RecChar()!='N');
	xcall _RecChar
	cpi R16,78
	brne L80
	.dbline 330
; 	         	     ExecCode();  
	xcall _ExecCode
	.dbline 331
; 	         	   } break;
	.dbline 331
	.dbline 332
; 	         default : break;
L76:
	.dbline 334
L73:
	.dbline 322
	xjmp L72
X4:
	.dbline 335
; 	       }
; 	   }
;       }
L64:
	.dbline 336
;     SendChar('E');  //通知PC机,进入运用程序区
	ldi R16,69
	xcall _SendChar
	.dbline 338
; 	//while (RecChar()!='N');
;     delay();
	xcall _delay
	.dbline 339
; 	delay();
	xcall _delay
	.dbline 340
; 	delay();
	xcall _delay
	.dbline 341
; 	delay();
	xcall _delay
	.dbline 342
;     ExecCode();
	.dbline -2
	.dbline 343
;   }
L63:
	.dbline 0 ; func end
	xjmp _ExecCode
	.dbsym r BootFlag 20 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\icc\peterf\BootLoad\main.c
_PageAddress::
	.blkb 2
	.dbsym e PageAddress _PageAddress i
_RealPageAddress::
	.blkb 2
	.dbsym e RealPageAddress _RealPageAddress i
_PageBuffer::
	.blkb 256
	.dbsym e PageBuffer _PageBuffer A[256:256]c

⌨️ 快捷键说明

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