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

📄 uart.s

📁 AVR单片机C语言程序设计实例精粹
💻 S
📖 第 1 页 / 共 4 页
字号:
	.module UART.c
	.area data(ram, con, rel)
_bSCI_Event::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\市电电压频率测量系统\UART.c
	.dbsym e bSCI_Event _bSCI_Event c
_bBuzzer_Count::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\市电电压频率测量系统\UART.c
	.dbsym e bBuzzer_Count _bBuzzer_Count c
	.area text(rom, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\市电电压频率测量系统\UART.c
	.dbfunc e sSet_SCI_Event _sSet_SCI_Event fV
;          event -> R16
	.even
_sSet_SCI_Event::
	.dbline -1
	.dbline 23
; //********************************************************************
; // File Name : UART.c
; // Author    : Steaven
; // Created   : 2008-10-05
; // Modified  : 
; // Revision  : V0.0
; //********************************************************************
; 
; #include "includes.h" 
; 
; struct SCI_Buffer stSciBuffer;
; 
; INT8U bSCI_Event = 0;    //SCI Event
; INT8U bBuzzer_Count = 0; //Buzzer ON Time
; 
; //********************************************************************
; // Function    : sSet_SCI_Event
; // Input       : event - SCI Event
; // Output      : none
; // Description : Interface Function
; //********************************************************************
; void sSet_SCI_Event(INT8U event)
; {
	.dbline 24
; 	bSCI_Event = event;
	sts _bSCI_Event,R16
	.dbline -2
	.dbline 25
; }
L1:
	.dbline 0 ; func end
	ret
	.dbsym r event 16 c
	.dbend
	.dbfunc e sbGet_SCI_Event _sbGet_SCI_Event fc
;          event -> R16
	.even
_sbGet_SCI_Event::
	.dbline -1
	.dbline 34
; 
; //********************************************************************
; // Function    : sbGet_SCI_Event
; // Input       : none
; // Output      : SCI Event
; // Description : Interface Function
; //********************************************************************
; INT8U sbGet_SCI_Event(void)
; {
	.dbline 36
; 	INT8U event;
; 	event = bSCI_Event;
	lds R16,_bSCI_Event
	.dbline 37
; 	bSCI_Event = 0;
	clr R2
	sts _bSCI_Event,R2
	.dbline 38
; 	return(event);
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbsym r event 16 c
	.dbend
	.dbfunc e sSet_Buzzer_Count _sSet_Buzzer_Count fV
;         bCount -> R16
	.even
_sSet_Buzzer_Count::
	.dbline -1
	.dbline 48
; }
; 
; //********************************************************************
; // Function    : sSet_Buzzer_Count
; // Input       : bCount - Buzzer ON Time
; // Output      : none
; // Description : Interface Function
; //********************************************************************
; void sSet_Buzzer_Count(INT8U bCount)
; {
	.dbline 49
; 	bBuzzer_Count = bCount;
	sts _bBuzzer_Count,R16
	.dbline -2
	.dbline 50
; }
L3:
	.dbline 0 ; func end
	ret
	.dbsym r bCount 16 c
	.dbend
	.dbfunc e sbGet_Buzzer_Count _sbGet_Buzzer_Count fc
	.even
_sbGet_Buzzer_Count::
	.dbline -1
	.dbline 59
; 
; //********************************************************************
; // Function    : sbGet_Buzzer_Count
; // Input       : none
; // Output      : Buzzer ON Time
; // Description : Interface Function
; //********************************************************************
; INT8U sbGet_Buzzer_Count(void)
; {
	.dbline 60
; 	return(bBuzzer_Count);
	lds R16,_bBuzzer_Count
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Init_UART _Init_UART fV
	.even
_Init_UART::
	.dbline -1
	.dbline 70
; }
; 		
; //********************************************************************
; // Function    : Init_UART
; // Input       : none
; // Output      : none
; // Description : ATmega16 UART Initialization,9600/N/8/1
; //********************************************************************
; void Init_UART(void)
; {
	.dbline 71
; 	UCSRA = 0x00;
	clr R2
	out 0xb,R2
	.dbline 72
; 	UCSRB = 0xD8;
	ldi R24,216
	out 0xa,R24
	.dbline 73
; 	UCSRC = 0x86;
	ldi R24,134
	out 0x20,R24
	.dbline 74
; 	UBRRL = 0x33;
	ldi R24,51
	out 0x9,R24
	.dbline 75
; 	SCI_Task_Init();
	.dbline -2
	.dbline 76
; }
L5:
	.dbline 0 ; func end
	xjmp _SCI_Task_Init
	.dbend
	.dbfunc e SCI_Task_Init _SCI_Task_Init fV
	.even
_SCI_Task_Init::
	.dbline -1
	.dbline 85
; 
; //********************************************************************
; // Function    : SCI_Task_Init
; // Input       : none
; // Output      : none
; // Description : Enable UART RX Interrupt and Initialize Buffer
; //********************************************************************
; void SCI_Task_Init(void)
; {
	.dbline 86
; 	Enable_UART_RX_INT();
	xcall _Enable_UART_RX_INT
	.dbline 87
; 	SciBuffer_Init(&stSciBuffer);
	ldi R16,<_stSciBuffer
	ldi R17,>_stSciBuffer
	.dbline -2
	.dbline 88
; }
L6:
	.dbline 0 ; func end
	xjmp _SciBuffer_Init
	.dbend
	.dbfunc e Enable_UART_RX_INT _Enable_UART_RX_INT fV
	.even
_Enable_UART_RX_INT::
	.dbline -1
	.dbline 97
; 
; //********************************************************************
; // Function    : Enable_UART_RX_INT
; // Input       : none
; // Output      : none
; // Description : Enable UART RX Interrupt
; //********************************************************************
; void Enable_UART_RX_INT(void)
; {
	.dbline 98
; 	UCSRB |= 0x80;
	sbi 0xa,7
	.dbline -2
	.dbline 99
; }
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Enable_UART_TX_INT _Enable_UART_TX_INT fV
	.even
_Enable_UART_TX_INT::
	.dbline -1
	.dbline 108
; 
; //********************************************************************
; // Function    : Enable_UART_TX_INT
; // Input       : none
; // Output      : none
; // Description : Enable UART TX Interrupt
; //********************************************************************
; void Enable_UART_TX_INT(void)
; {
	.dbline 109
; 	UCSRB |= 0x40;
	sbi 0xa,6
	.dbline -2
	.dbline 110
; }
L8:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Disable_UART_RX_INT _Disable_UART_RX_INT fV
	.even
_Disable_UART_RX_INT::
	.dbline -1
	.dbline 119
; 
; //********************************************************************
; // Function    : Disable_UART_RX_INT
; // Input       : none
; // Output      : none
; // Description : Disable UART RX Interrupt
; //********************************************************************
; void Disable_UART_RX_INT(void)
; {
	.dbline 120
; 	UCSRB &= ~0x80;
	cbi 0xa,7
	.dbline -2
	.dbline 121
; }
L9:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Disable_UART_TX_INT _Disable_UART_TX_INT fV
	.even
_Disable_UART_TX_INT::
	.dbline -1
	.dbline 130
; 
; //********************************************************************
; // Function    : Disable_UART_TX_INT
; // Input       : none
; // Output      : none
; // Description : Disable UART TX Interrupt
; //********************************************************************
; void Disable_UART_TX_INT(void)
; {
	.dbline 131
; 	UCSRB &= ~0x40;
	cbi 0xa,6
	.dbline -2
	.dbline 132
; }
L10:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e UART_TX_DATA _UART_TX_DATA fV
;          bData -> R16
	.even
_UART_TX_DATA::
	.dbline -1
	.dbline 141
; 
; //********************************************************************
; // Function    : UART_TX_DATA
; // Input       : bData-data to be send
; // Output      : none
; // Description : Write Data to UART TX Reigster
; //********************************************************************
; void UART_TX_DATA(INT8U bData)
; {
	.dbline 142
; 	UDR = bData;
	out 0xc,R16
	.dbline -2
	.dbline 143
; }
L11:
	.dbline 0 ; func end
	ret
	.dbsym r bData 16 c
	.dbend
	.dbfunc e UART_RX_DATA _UART_RX_DATA fc
	.even
_UART_RX_DATA::
	.dbline -1
	.dbline 152
; 
; //********************************************************************
; // Function    : UART_RX_DATA
; // Input       : none
; // Output      : data received
; // Description : Get Received Data from Register
; //********************************************************************
; INT8U UART_RX_DATA(void)
; {
	.dbline 153
; 	return(UDR);
	in R16,0xc
	.dbline -2
L12:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 44
	jmp _sUART_RX_ISR
	.area text(rom, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\市电电压频率测量系统\UART.c
	.dbfunc e sUART_RX_ISR _sUART_RX_ISR fV
;           data -> R20
	.even
_sUART_RX_ISR::
	xcall push_lset
	xcall push_gset1
	.dbline -1
	.dbline 164
; }
; 
; //********************************************************************
; // Function    : sUART_RX_ISR
; // Input       : none
; // Output      : none
; // Description : UART RX Interrupt Service Routine
; //********************************************************************
; #pragma interrupt_handler sUART_RX_ISR:12  
; void sUART_RX_ISR(void)
; {
	.dbline 167
; 	INT8U data;
; 	//step1:read receive register to clear interrupt flag
; 	data = UART_RX_DATA();
	xcall _UART_RX_DATA
	mov R20,R16
	.dbline 169
; 	//step2:report event or store received char to buffer
; 	if((data == 0x0A) || (data == 0x0D))
	cpi R16,10
	breq L16
	cpi R16,13
	brne L14
L16:
	.dbline 170
; 	{
	.dbline 171
; 		if(sbGetRxBufferEmptyStatus(&stSciBuffer) == false)
	ldi R16,<_stSciBuffer
	ldi R17,>_stSciBuffer
	xcall _sbGetRxBufferEmptyStatus
	tst R16
	brne L15
	.dbline 172
; 		{
	.dbline 173
; 			SciBuffer_Rx_Reset(&stSciBuffer);
	ldi R16,<_stSciBuffer
	ldi R17,>_stSciBuffer
	xcall _SciBuffer_Rx_Reset
	.dbline 174
; 			sSet_SCI_Event(1);
	ldi R16,1
	xcall _sSet_SCI_Event
	.dbline 175
; 		}
	.dbline 176
; 	}
	xjmp L15
L14:
	.dbline 178
	.dbline 179
	mov R18,R20
	ldi R16,<_stSciBuffer
	ldi R17,>_stSciBuffer
	xcall _SciBuffer_Rx_In
	.dbline 180
L15:
	.dbline -2
	.dbline 181
; 	else
; 	{
; 		SciBuffer_Rx_In(&stSciBuffer,data);
; 	}
; }
L13:
	xcall pop_gset1
	xcall pop_lset
	.dbline 0 ; func end
	reti
	.dbsym r data 20 c
	.dbend
	.area vector(rom, abs)
	.org 52
	jmp _sUART_TX_ISR
	.area text(rom, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\市电电压频率测量系统\UART.c
	.dbfunc e sUART_TX_ISR _sUART_TX_ISR fV
;          bData -> R20
	.even
_sUART_TX_ISR::
	xcall push_lset
	xcall push_gset1
	.dbline -1
	.dbline 191
; 
; //********************************************************************
; // Function    : sUART_TX_ISR
; // Input       : none
; // Output      : none
; // Description : UART TX Interrupt Service Routine
; //********************************************************************
; #pragma interrupt_handler sUART_TX_ISR:14  
; void sUART_TX_ISR(void)
; {
	.dbline 193
; 	INT8U bData;
; 	if(sbGetTxBufferNoEmptyStatus(&stSciBuffer) == true)
	ldi R16,<_stSciBuffer
	ldi R17,>_stSciBuffer
	xcall _sbGetTxBufferNoEmptyStatus
	cpi R16,1
	brne L20
	.dbline 194
; 	{
	.dbline 195
; 		bData = SciBuffer_Tx_Out(&stSciBuffer);
	ldi R16,<_stSciBuffer
	ldi R17,>_stSciBuffer
	xcall _SciBuffer_Tx_Out
	mov R20,R16
	.dbline 196
; 		UART_TX_DATA(bData);
	xcall _UART_TX_DATA
	.dbline 197
; 	}
	xjmp L21
L20:
	.dbline 199
	.dbline 200
	xcall _Disable_UART_TX_INT
	.dbline 201
	ldi R16,<_stSciBuffer
	ldi R17,>_stSciBuffer
	xcall _SciBuffer_Tx_Reset
	.dbline 202
L21:
	.dbline -2
	.dbline 203
; 	else
; 	{
; 		Disable_UART_TX_INT();
; 		SciBuffer_Tx_Reset(&stSciBuffer);
; 	}
; }
L19:
	xcall pop_gset1
	xcall pop_lset
	.dbline 0 ; func end
	reti
	.dbsym r bData 20 c
	.dbend
	.dbfunc e SciBuffer_Init _SciBuffer_Init fV
;            ptr -> R16,R17
	.even
_SciBuffer_Init::
	.dbline -1
	.dbline 212
; 
; //********************************************************************
; // Function    : SciBuffer_Init
; // Input       : ptr-pointer to SCI Buffer
; // Output      : none
; // Description : Initialization of SCI Buffer
; //********************************************************************
; void SciBuffer_Init(struct SCI_Buffer *ptr)
; {
	.dbline 213
; 	ptr->bRxLength = 0;
	clr R2
	movw R30,R16
	std z+0,R2
	.dbline 214
; 	ptr->bTxLength = 0;
	std z+1,R2
	.dbline 215
; 	ptr->bTxBufferLength = 0;
	movw R30,R16
	std z+2,R2
	.dbline -2
	.dbline 216
; }
L22:
	.dbline 0 ; func end
	ret
	.dbsym r ptr 16 pX
	.dbend
	.dbfunc e SciBuffer_Rx_In _SciBuffer_Rx_In fV
;          bData -> R18
;            ptr -> R16,R17
	.even
_SciBuffer_Rx_In::
	.dbline -1
	.dbline 225
; 
; //********************************************************************
; // Function    : SciBuffer_Rx_In
; // Input       : ptr-pointer to SCI Buffer
; // Output      : none
; // Description : Add data into the SCI RX Buffer
; //********************************************************************
; void SciBuffer_Rx_In(struct SCI_Buffer *ptr,INT8U bData)
; {
	.dbline 226
; 	if(ptr->bRxLength < cMaxRxLength)
	movw R30,R16
	ldd R24,z+0
	cpi R24,50
	brsh L24
	.dbline 227
; 	{
	.dbline 228
; 		ptr->bRxBuffer[ptr->bRxLength] = bData;
	movw R24,R30
	adiw R24,3
	ldd R30,z+0
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R18
	.dbline 229
; 		ptr->bRxLength++;
	movw R30,R16
	ldd R24,z+0
	subi R24,255    ; addi 1
	std z+0,R24
	.dbline 230
; 	}
	xjmp L25
L24:
	.dbline 232
	.dbline 233
	movw R30,R16
	std z+3,R18
	.dbline 234
	ldi R24,1
	movw R30,R16
	std z+0,R24
	.dbline 235
L25:
	.dbline -2
	.dbline 236
; 	else
; 	{
; 		ptr->bRxBuffer[0] = bData;
; 		ptr->bRxLength = 1;
; 	}
; }
L23:
	.dbline 0 ; func end
	ret
	.dbsym r bData 18 c
	.dbsym r ptr 16 pX
	.dbend
	.dbfunc e SciBuffer_Tx_Out _SciBuffer_Tx_Out fc
;          bData -> R20
;            ptr -> R16,R17
	.even
_SciBuffer_Tx_Out::
	xcall push_gset1
	.dbline -1
	.dbline 245
; 
; //********************************************************************
; // Function    : SciBuffer_Tx_Out
; // Input       : ptr-pointer to SCI Buffer
; // Output      : data from SCI TX Buffer
; // Description : Get data from the SCI TX Buffer
; //********************************************************************
; INT8U SciBuffer_Tx_Out(struct SCI_Buffer *ptr)
; {
	.dbline 247
; 	INT8U bData;
; 	bData = ptr->bTxBuffer[ptr->bTxLength];
	movw R24,R16
	adiw R24,53
	movw R30,R16
	ldd R30,z+1
	clr R31
	add R30,R24
	adc R31,R25
	ldd R20,z+0
	.dbline 248
; 	ptr->bTxLength++;
	movw R24,R16
	adiw R24,1
	movw R30,R24
	ldd R24,z+0
	subi R24,255    ; addi 1
	std z+0,R24
	.dbline 249
; 	return(bData);	
	mov R16,R20
	.dbline -2
L26:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r bData 20 c
	.dbsym r ptr 16 pX
	.dbend
	.dbfunc e SciBuffer_Tx_In _SciBuffer_Tx_In fV
;          bData -> R18
;            ptr -> R16,R17
	.even
_SciBuffer_Tx_In::
	.dbline -1
	.dbline 259
	.dbline 260
	movw R30,R16
	ldd R24,z+2
	cpi R24,100
	brsh L28
	.dbline 261
	.dbline 262
	movw R24,R16
	adiw R24,53
	movw R30,R16
	ldd R30,z+2
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R18
	.dbline 263
	movw R24,R16
	adiw R24,2
	movw R30,R24
	ldd R24,z+0
	subi R24,255    ; addi 1
	std z+0,R24
	.dbline 264
L28:
	.dbline -2
	.dbline 265
; }
; 
; //********************************************************************
; // Function    : SciBuffer_Tx_In
; // Input       : ptr-pointer to SCI Buffer
; // Output      : none
; // Description : Add data into the SCI TX Buffer
; //********************************************************************
; void SciBuffer_Tx_In(struct SCI_Buffer *ptr,INT8U bData)
; {
; 	if(ptr->bTxBufferLength < cMaxTxLength)
; 	{
; 		ptr->bTxBuffer[ptr->bTxBufferLength] = bData;
; 		ptr->bTxBufferLength++;
; 	}
; }
L27:
	.dbline 0 ; func end
	ret
	.dbsym r bData 18 c
	.dbsym r ptr 16 pX
	.dbend
	.dbfunc e sbGetTxBufferNoEmptyStatus _sbGetTxBufferNoEmptyStatus fc
;            ptr -> R16,R17
	.even
_sbGetTxBufferNoEmptyStatus::
	.dbline -1
	.dbline 274
; 		
; //********************************************************************
; // Function    : sbGetTxBufferNoEmptyStatus
; // Input       : ptr-pointer to SCI Buffer
; // Output      : Status of SCI TX Buffer
; // Description : Check whether the SCI TX Buffer is empty or not
; //********************************************************************
; INT8U sbGetTxBufferNoEmptyStatus(struct SCI_Buffer *ptr)
; {
	.dbline 275
; 	if(ptr->bTxLength < ptr->bTxBufferLength)
	movw R30,R16
	ldd R2,z+2
	movw R30,R16
	ldd R3,z+1
	cp R3,R2
	brsh L31
	.dbline 276
; 	{
	.dbline 277
; 		return(true);
	ldi R16,1
	xjmp L30
L31:
	.dbline 279
; 	}
; 	return(false);
	clr R16
	.dbline -2
L30:
	.dbline 0 ; func end
	ret

⌨️ 快捷键说明

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