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

📄 main.s

📁 ATMega16驱动Cy2198TR无线串口程序
💻 S
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile D:\Test\Movetion\Cy2198TR\main.c
	.dbfunc e main _main fI
	.even
_main::
	.dbline -1
	.dbline 42
; /*
; Cy2198TR-B Program
; by Chenxi
; */
; #include <iom16v.h>
; 
; /*====================MACRO DEFINE============================================*/
; /*define system as transmitter or receiver*/
; /*
; transmitter -- 1
; receiver -- 0
; */
; #define WIRELESS_TRANSIMIT_SEL 1
; 
; /*----------ports---------*/
; #define W_EN	3
; #define W_BUSY	2
; #define W_RT	1
; #define W_FS	0
; #define W_RXD	0  
; #define W_TXD	1
; 
; #define WIRELESS_EN()			PORTC &= (~(1 << W_EN))
; #define WIRELESS_REC_EN()		PORTC |= (1 << W_RT)
; #define WIRELESS_SEND_EN()		PORTC &= (~(1 << W_RT))
; #define WIRELESS_IS_BUSY		PINC & (1 << W_BUSY)
; #define WIRELESS_FREQUENCY_SEL() PORTC |= (1 << W_FS)
; 
; /*============================================================================*/
; /*=================FUNCTIONS DECLARATION======================================*/
; void Port_Init(void);
; void USART_Init(void);
; void Wireless_Init(void);
; void USART_Transmit(unsigned char ucbyte);
; void Wireless_TransmitByte(unsigned char ucbyte);
; void Delay_nms(unsigned int n);
; unsigned char USART_Receive(void);
; /*============================================================================*/
; 
; /*================== MAIN ====================================================*/
; int main(void)
; {
	.dbline 43
; 	Wireless_Init();
	xcall _Wireless_Init
	xjmp L3
L2:
	.dbline 45
	.dbline 46
	ldi R16,1
	xcall _Wireless_TransmitByte
	.dbline 47
	ldi R16,1000
	ldi R17,3
	xcall _Delay_nms
	.dbline 48
	ldi R16,2
	xcall _Wireless_TransmitByte
	.dbline 49
	ldi R16,1000
	ldi R17,3
	xcall _Delay_nms
	.dbline 50
L3:
	.dbline 44
; 	while(1)
	xjmp L2
X0:
	.dbline 51
; 	{	
;     	Wireless_TransmitByte(0x01);
;     	Delay_nms(1000);
;     	Wireless_TransmitByte(0x02);
;     	Delay_nms(1000);
; 	}
; 	return 0;
	clr R16
	clr R17
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Port_Init _Port_Init fV
	.even
_Port_Init::
	.dbline -1
	.dbline 58
; }
; /*============================================================================*/
; 
; /*===============FUNCTIONS HERE===============================================*/
; /*--------------Initialize Ports--------------------*/
; void Port_Init(void)
; {
	.dbline 59
;  	PORTB = 0x01;
	ldi R24,1
	out 0x18,R24
	.dbline 60
;  	DDRB = 0xFF;
	ldi R24,255
	out 0x17,R24
	.dbline 61
; 	DDRC |= (1 << W_EN) | (1 << W_RT) | (1 << W_FS);
	in R24,0x14
	ori R24,11
	out 0x14,R24
	.dbline 62
; 	DDRC |= ~(1 << W_BUSY);
	in R24,0x14
	ori R24,251
	out 0x14,R24
	.dbline 63
; 	PORTC = (1 << W_EN) | (1 << W_RT) | (1 << W_BUSY) | (1 << W_FS);
	ldi R24,15
	out 0x15,R24
	.dbline 64
; 	DDRD |= (1 << W_TXD);
	sbi 0x11,1
	.dbline 65
; 	DDRD &= ~(1 << W_RXD);
	cbi 0x11,0
	.dbline 66
; 	PORTD |= (1 << W_TXD) | (1 << W_RXD);	
	in R24,0x12
	ori R24,3
	out 0x12,R24
	.dbline -2
	.dbline 67
; }
L5:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e USART_Init _USART_Init fV
	.even
_USART_Init::
	.dbline -1
	.dbline 72
; 
; /*--------------UART0 initialize----------------*/
; /*baudrate: 19200*/
; void USART_Init(void)
; {
	.dbline 73
; 	UCSRB = 0x00; 
	clr R2
	out 0xa,R2
	.dbline 74
; 	UCSRA = 0x00;
	out 0xb,R2
	.dbline 75
; 	UCSRC = (1 <<URSEL) | 0x06;
	ldi R24,134
	out 0x20,R24
	.dbline 76
; 	UBRRL= 25;
	ldi R24,25
	out 0x9,R24
	.dbline 77
; 	UBRRH= 0x00;
	out 0x20,R2
	.dbline 78
; 	UCSRB = 0x98;
	ldi R24,152
	out 0xa,R24
	.dbline -2
	.dbline 79
; }
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Wireless_Init _Wireless_Init fV
	.even
_Wireless_Init::
	.dbline -1
	.dbline 83
; 
; /*----------------initialize system-----------------*/
; void Wireless_Init(void)
; {
	.dbline 84
;  	asm("cli");
	cli
	.dbline 85
; 	Port_Init();
	xcall _Port_Init
	.dbline 86
; 	USART_Init();
	xcall _USART_Init
	.dbline 89
; 	
; 	#if WIRELESS_TRANSIMIT_SEL
; 		WIRELESS_SEND_EN();
	cbi 0x15,1
	.dbline 94
; 	#else
; 		WIRELESS_RECEIVE_EN();
; 	#endif
; 	
; 	WIRELESS_EN();
	cbi 0x15,3
	.dbline 95
; 	asm("sei");
	sei
	.dbline -2
	.dbline 96
; }
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e USART_Transmit _USART_Transmit fV
;         ucbyte -> R16
	.even
_USART_Transmit::
	.dbline -1
	.dbline 100
; 
; /*--------------UART0 transmit a byte----------------*/
; void USART_Transmit( unsigned char ucbyte )
; {
L9:
	.dbline 101
L10:
	.dbline 101
; 	while ( !( UCSRA & (1<<UDRE)));
	sbis 0xb,5
	rjmp L9
	.dbline 102
; 	UDR = ucbyte;
	out 0xc,R16
	.dbline -2
	.dbline 103
; }
L8:
	.dbline 0 ; func end
	ret
	.dbsym r ucbyte 16 c
	.dbend
	.dbfunc e Wireless_TransmitByte _Wireless_TransmitByte fV
;         ucbyte -> R20
	.even
_Wireless_TransmitByte::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 107
; 
; /*------------wireless transmit a byte-------------*/
; void Wireless_TransmitByte(unsigned char ucbyte)
; {
L13:
	.dbline 108
L14:
	.dbline 108
; 	while(!(WIRELESS_IS_BUSY));
	sbis 0x13,2
	rjmp L13
	.dbline 109
; 	USART_Transmit(ucbyte);
	mov R16,R20
	xcall _USART_Transmit
	.dbline 110
; 	USART_Transmit(0x0D);
	ldi R16,13
	xcall _USART_Transmit
	.dbline 111
; 	USART_Transmit(0x0A);
	ldi R16,10
	xcall _USART_Transmit
	.dbline -2
	.dbline 112
; }
L12:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r ucbyte 20 c
	.dbend
	.dbfunc e Delay_nms _Delay_nms fV
;              i -> R20,R21
;              j -> R22,R23
;              n -> R16,R17
	.even
_Delay_nms::
	xcall push_gset2
	.dbline -1
	.dbline 116
; 
; /*--------------delaly function---------------------*/
; void Delay_nms(unsigned int n)       //N ms
; {
	.dbline 117
;    unsigned int i = 0;
	clr R20
	clr R21
	.dbline 118
;    unsigned int j = 0;
	clr R22
	clr R23
	.dbline 119
;    for (i = 0 ; i < n ; i ++)
	xjmp L20
L17:
	.dbline 120
;    {
	.dbline 121
	clr R22
	clr R23
	xjmp L24
L21:
	.dbline 121
L22:
	.dbline 121
	subi R22,255  ; offset = 1
	sbci R23,255
L24:
	.dbline 121
	cpi R22,116
	ldi R30,4
	cpc R23,R30
	brlo L21
	.dbline 122
L18:
	.dbline 119
	subi R20,255  ; offset = 1
	sbci R21,255
L20:
	.dbline 119
	cp R20,R16
	cpc R21,R17
	brlo L17
	.dbline -2
	.dbline 123
;    	   for (j = 0 ; j < 1140 ;j ++);
;    }
; }
L16:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r j 22 i
	.dbsym r n 16 i
	.dbend
	.dbfunc e USART_Receive _USART_Receive fc
	.even
_USART_Receive::
	.dbline -1
	.dbline 127
; 
; /*--------------USART receive a byte---------------------*/
; unsigned char USART_Receive(void)
; {
L26:
	.dbline 128
L27:
	.dbline 128
; 	while(!(UCSRA&(1<<RXC)));
	sbis 0xb,7
	rjmp L26
	.dbline 129
; 	return UDR;
	in R16,0xc
	.dbline -2
L25:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 44
	jmp _uart0_rx_isr
	.area text(rom, con, rel)
	.dbfile D:\Test\Movetion\Cy2198TR\main.c
	.dbfunc e uart0_rx_isr _uart0_rx_isr fV
	.even
_uart0_rx_isr::
	st -y,R2
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 135
; }
; 
; /*--------------wireless receive -------------------------*/
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
	.dbline 137
;  	//add receiver code here......
;  	PORTB = UDR;
	in R2,0xc
	out 0x18,R2
	.dbline -2
	.dbline 138
; }
L29:
	ld R2,y+
	out 0x3f,R2
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend

⌨️ 快捷键说明

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