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

📄 main.s

📁 AVR单片机系统开发经典实例部分源程序
💻 S
📖 第 1 页 / 共 4 页
字号:
; 	#ifdef CPU_eZ8
; 	SET_VECTOR(UART1_RX, isr_uart1_rx);		// setup an RX interrupt
; 											//
; 	IRQ2ENH |= (1<<U1REN);					// Set Interrupt Priority high
; 	IRQ2ENL |= (1<<U1REN);					//  "
;     #endif
; 
; 	// ****************************
; 	// Initialize the SPI - though we don't use it yet
; 
; 	SPI_Init();
	xcall _SPI_Init
	.dbline 693
; 
; 	// ****************************
; 	// setup the ADC
; 
; 	#ifdef CPU_eZ8
; 	#endif
; 
; 	#ifdef CPU_ATmega128
; 	SFIOR = 0;												//
	clr R2
	out 0x20,R2
	.dbline 695
; 															//
; 	ADCSRA = 0;												// disable adc
	out 0x6,R2
	.dbline 697
; 															//
; 	cbi(PORTF, 0);											// disable pull-up on ADC-0 input
	lds R24,98
	andi R24,254
	sts 98,R24
	.dbline 698
; 	cbi(PORTF, 1);											// disable pull-up on ADC-1 input
	lds R24,98
	andi R24,253
	sts 98,R24
	.dbline 706
; //	cbi(PORTF, 2);											// disable pull-up on ADC-2 input
; //	cbi(PORTF, 3);											// disable pull-up on ADC-3 input
; //	cbi(PORTF, 4);											// disable pull-up on ADC-4 input
; //	cbi(PORTF, 5);											// disable pull-up on ADC-5 input
; //	cbi(PORTF, 6);											// disable pull-up on ADC-6 input
; //	cbi(PORTF, 7);											// disable pull-up on ADC-7 input
; 															//
; 	ADMUX = 0;												// reference = AREF pin, Right adjusted, select adc input 0,
	out 0x7,R2
	.dbline 707
; 	ACSR = (1<<ACD);										// disable the Analogue comparator
	ldi R24,128
	out 0x8,R24
	.dbline 708
; 	ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);	// enable the ADC, Prescaler = 128 (Conversion time = 224uS)
	ldi R24,135
	out 0x6,R24
	.dbline 709
; 	sbi(ADCSRA, ADSC);										// start a conversion
	sbi 0x6,6
	.dbline 713
; 															//
; 	#endif
; 
; 	memset((void*)ADC_Input, 0, sizeof(ADC_Input));			// clear our ADC values - the timer interrupt saves the ADC values into this buffer
	ldi R24,16
	ldi R25,0
	std y+1,R25
	std y+0,R24
	clr R18
	clr R19
	ldi R16,<_ADC_Input
	ldi R17,>_ADC_Input
	xcall _memset
	.dbline 726
; 
; 	// ****************************
; 	// Initialize Test Button interrupt on port-C - we don't use it though as we just poll the pin in the timer interrupt
; 
; 	#ifdef CPU_eZ8
; //	SET_VECTOR(C0, isr_C0);							// set interrupt vector
; //	IRQ2ENH |= (1<<C0EN);							// Set Interrupt Priority High
; //	IRQ2ENL |= (1<<C0EN);							//  "
;     #endif
; 
;     // ****************************
; 
; 	WatchdogCounter = 0;							//
	clr R2
	sts _WatchdogCounter,R2
	.dbline 728
; 
; 	CommandBuffer[0] = 0;							//
	sts _CommandBuffer,R2
	.dbline 730
; 
; 	MainBufferWr_Rx = -1;							//
	ldi R24,-1
	ldi R25,-1
	sts _MainBufferWr_Rx+1,R25
	sts _MainBufferWr_Rx,R24
	.dbline 731
; 	MainBufferWr_Tx = 0;							//
	clr R3
	sts _MainBufferWr_Tx+1,R3
	sts _MainBufferWr_Tx,R2
	.dbline 733
; 
; 	AT_Stage(AT_Idle);								//
	clr R16
	xcall _AT_Stage
	.dbline 735
; 													//
; 	PPP.Stage = PPPS_None;							//
	clr R2
	sts _PPP+9,R2
	.dbline 739
; 													//
; 	#ifdef IncludeTCP
; 		#ifdef StaticTCPSocket
; 			TCP_Socket = (T_TCP_Socket*)&TCP_Static_Socket;	//
	ldi R24,<_TCP_Static_Socket
	ldi R25,>_TCP_Static_Socket
	sts _TCP_Socket+1,R25
	sts _TCP_Socket,R24
	.dbline 740
; 			TCP_SocketStage(TCP_Socket, TCP_CLOSED);		//
	clr R18
	movw R16,R24
	xcall _TCP_SocketStage
	.dbline 749
; 		#else
; 			TCP_Socket = NULL;								//
; 		#endif
; 	#endif
; 
; 	// ****************************
; 	// test to see if the button is pressed when booting up
; 
; 	if (!TestButton)
	sbic 0x10,0
	rjmp L127
	.dbline 750
; 	{	// the button is pressed
	.dbline 751
; 		RLed_On;										//
	cbi 0x18,5
	.dbline 752
; 		Flags1 |= (1<<Flags1_Button);					// set flag
	lds R24,_Flags1
	ori R24,32
	sts _Flags1,R24
	.dbline 755
; 														//
; 		// wait for the button to be released - short debounce detector
; 		for (i = 32767; i; i--)							//
	ldi R24,32767
	ldi R25,127
	movw R10,R24
L129:
	.dbline 756
; 		{												//
	.dbline 757
; 			Reset_WD();									//
	wdr
	.dbline 758
; 			if (!TestButton) i = 32767;					// button is still pressed
	sbic 0x10,0
	rjmp L133
	.dbline 758
	ldi R24,32767
	ldi R25,127
	movw R10,R24
L133:
	.dbline 759
L130:
	.dbline 755
	movw R24,R10
	sbiw R24,1
	movw R10,R24
	.dbline 755
	cpi R24,0
	cpc R24,R25
	brne L129
X9:
	.dbline 761
; 		}												//
; 														//
; 		RLed_Off;										//
	sbi 0x18,5
	.dbline 764
; 
; 		#ifdef CPU_ATmega128
; 		Set_UnitID("test 123456");						// reset our ID
	ldi R16,<L135
	ldi R17,>L135
	xcall _Set_UnitID
	.dbline 766
; 		#endif
; 	}
L127:
	.dbline 772
; 
; 	// ****************************
; 	// main loop
; 
; 	#ifdef Debug
; 	Flags1 |= (1<<Flags1_Debug);					// enable debug as default - for now
	lds R24,_Flags1
	ori R24,128
	sts _Flags1,R24
	.dbline 775
; 	#endif
; 
; 	Enable_Ints();									// enable global interrupts
	sei
	.dbline 778
; 
; 	#ifdef Debug
; 		SendDetails();								//
	xcall _SendDetails
	.dbline 779
; 		SendHelp();									//
	xcall _SendHelp
	.dbline 782
; 	#endif
; 
; 	PPP_Reset(0, 0);								//
	clr R18
	clr R19
	clr R16
	clr R17
	xcall _PPP_Reset
	.dbline 785
; 
; 	#ifdef CPU_ATmega128
; 	_StackCheck();									// check for stack overflow
	xcall __StackCheck
	.dbline 794
; 	#endif
; 
; //	_StackOverflowed(0);							// test our stack overflow routine
; //	StackOverflowTest(0);							// ditto
; 
; 	// **************
; 	// main executive loop
; 
; 	for (;;)
L136:
	.dbline 795
; 	{
	.dbline 799
; 		// *************
; 		// tell timer interrupt to keep the watchdog at bay
; 
; 		if (!WatchdogCounter) WatchdogCounter++;								//
	lds R2,_WatchdogCounter
	tst R2
	brne L140
	.dbline 799
	lds R24,_WatchdogCounter
	subi R24,255    ; addi 1
	sts _WatchdogCounter,R24
L140:
	.dbline 804
; 
; 		// *************
; 		// do stuff when the push button is pressed
; 
; 		if (Flags1 & (1<<Flags1_ButtonPress))									//
	lds R2,_Flags1
	sbrs R2,2
	rjmp L142
	.dbline 805
; 		{																		// Button has been pressed
	.dbline 806
; 			Flags1 &= ~(1<<Flags1_ButtonPress);									// clear the flag
	lds R24,_Flags1
	andi R24,251
	sts _Flags1,R24
	.dbline 809
; 																				//
; 			#ifdef Debug
; 				SendDebugRStr(Str4);											//
	ldi R16,<_Str4
	ldi R17,>_Str4
	xcall _SendDebugRStr
	.dbline 812
; 			#endif
; 																				//
; 			if (AT.Stage == AT_Idle)											//
	lds R2,_AT+3
	tst R2
	brne L144
	.dbline 813
; 				AT_Start();														// start a ppp link
	xcall _AT_Start
	xjmp L145
L144:
	.dbline 815
; 			else																//
; 				AT_End();														// terminate the ppp link
	xcall _AT_End
L145:
	.dbline 816
; 		}																		//
L142:
	.dbline 821
; 
; 		// *************
; 		// do stuff to keep things rolling - AT Modem, PPP, TCP etc
; 
; 		ProcessMainLoop();														//
	xcall _ProcessMainLoop
	.dbline 827
; 
; 		// *************
; 		// deal with rx'ing and tx'ing data from/to the tcp socket
; 
; 		#ifdef IncludeTCP
; 		if (TCP_Socket == NULL) continue;										// no tcp socket to process
	lds R2,_TCP_Socket
	lds R3,_TCP_Socket+1
	tst R2
	brne L147
	tst R3
	brne L147
X10:
	.dbline 827
	xjmp L136
L147:
	.dbline 828
; 		if (TCP_Socket->Stage != TCP_ESTABLISHED) continue;						// the tcp socket is not connected
	lds R30,_TCP_Socket
	lds R31,_TCP_Socket+1
	ldd R24,z+0
	cpi R24,4
	breq L149
	.dbline 828
	xjmp L136
L149:
	.dbline 830
; 																				//
; 		i = TCP_RxBytes(TCP_Socket);											// number of bytes the tcp socket has for us
	lds R16,_TCP_Socket
	lds R17,_TCP_Socket+1
	xcall _TCP_RxBytes
	movw R10,R16
	.dbline 831
; 		j = TCP_TxFree(TCP_Socket);												// number of bytes free in the tcp socket tx buffer
	lds R16,_TCP_Socket
	lds R17,_TCP_Socket+1
	xcall _TCP_TxFree
	movw R12,R16
	.dbline 832
	clr R2
	clr R3
	cp R2,R10
	cpc R3,R11
	brge L153
	cp R2,R16
	cpc R3,R17
	brlt L151
L153:
	.dbline 832
; 		if ((i <= 0) || (j <= 0)) continue;										// no data in rx buffer or no space left in tx buffer
	xjmp L136
L151:
	.dbline 834
; 																				//
; 		if (i > sizeof(ScratchPad)) i = sizeof(ScratchPad);						// limit to the temp buffer size
	ldi R24,256
	ldi R25,1
	cp R24,R10
	cpc R25,R11
	brsh L154
	.dbline 834
	movw R10,R24
L154:
	.dbline 836
; 																				//
; 		if (!TCP_Socket->OutGoing)												//
	lds R30,_TCP_Socket
	lds R31,_TCP_Socket+1
	ldd R2,z+12
	tst R2
	brne L156
	.dbline 837
; 		{																		// echo back - as we are in server mode
	.dbline 838
; 			if (i > j) i = j;													// limit the amount of data we move from tcp rx buffer back into the tcp tx buffer
	cp R12,R10
	cpc R13,R11
	brge L158
	.dbline 838
	movw R10,R12
L158:
	.dbline 839
; 			i = TCP_RxData(TCP_Socket, ScratchPad, i);							// move data from tcp rx buffer into temp buffer
	std y+1,R11
	std y+0,R10
	ldi R18,<_ScratchPad
	ldi R19,>_ScratchPad
	lds R16,_TCP_Socket
	lds R17,_TCP_Socket+1
	xcall _TCP_RxData
	movw R10,R16
	.dbline 840
; 			TCP_TxData(TCP_Socket, ScratchPad, i);								// move data from temp buffer into the tcp tx buffer
	std y+1,R11
	std y+0,R10
	ldi R18,<_ScratchPad
	ldi R19,>_ScratchPad
	lds R16,_TCP_Socket
	lds R17,_TCP_Socket+1
	xcall _TCP_TxData
	.dbline 841
; 		}																		//
	xjmp L157
L156:
	.dbline 843
; 		else																	//
; 		{																		// don't echo back - as we are in client mode
	.dbline 844
; 			i = TCP_RxData(TCP_Socket, ScratchPad, i);							// move data from tcp rx buffer into temp buffer
	std y+1,R11
	std y+0,R10
	ldi R18,<_ScratchPad
	ldi R19,>_ScratchPad
	lds R16,_TCP_Socket
	lds R17,_TCP_Socket+1
	xcall _TCP_RxData
	movw R10,R16
	.dbline 846
; 																				//
; 		}																		//
L157:
	.dbline 848
	movw R18,R10
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugAsciiDump
	.dbline 853
	.dbline 794
	.dbline 794
	xjmp L136
X11:
	.dbline -2
L117:
	adiw R28,2
	.dbline 0 ; func end
	ret
	.dbsym r i 10 I
	.dbsym r j 12 I
	.dbend
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L135:
	.blkb 12
	.area idata
	.byte 't,'e,'s,'t,32,49,50,51,52,53,54,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L52:
	.blkb 6
	.area idata
	.byte 37,48,52,'X,10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L51:
	.blkb 4
	.area idata
	.byte 'O,'K,10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L46:
	.blkb 8
	.area idata
	.byte 10,'S,'R,'A,'M,58,32,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L41:
	.blkb 5
	.area idata
	.byte 32,'P,'O,'R,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L38:
	.blkb 5
	.area idata
	.byte 32,'E,'X,'T,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L35:
	.blkb 9
	.area idata
	.byte 32,'B,'R,'N,45,'O,'U,'T,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L32:
	.blkb 4
	.area idata
	.byte 32,'W,'D,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L29:
	.blkb 6
	.area idata
	.byte 32,'J,'T,'A,'G,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L26:
	.blkb 25
	.area idata
	.byte 10,'L,'a,'s,'t,32,'r,'e,'s,'e,'t,32,'r,'e,'a,'s
	.byte 'o,'n,58,32,37,48,50,'X,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L25:
	.blkb 9
	.area idata
	.byte 'I,'n,'v,'a,'l,'i,'d,10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L22:
	.blkb 2
	.area idata
	.byte 10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L15:
	.blkb 11
	.area idata
	.byte 10,'U,'n,'i,'t,32,'I,'D,58,32,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c
L6:
	.blkb 9
	.area idata
	.byte 37,'u,46,37,48,50,'x,10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\main.c

⌨️ 快捷键说明

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