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

📄 twimain.s

📁 PTR8000无线通信模块的单片机控制程序
💻 S
字号:
	.module twimain.c
	.area vector(rom, abs)
	.org 34
	rjmp _twi_isr
	.area data(ram, con, rel)
_receive_data::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbsym e receive_data _receive_data c
_error_state::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbsym e error_state _error_state c
_slave_address::
	.blkb 1
	.area idata
	.byte 192
	.area data(ram, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbsym e slave_address _slave_address c
_bit_race::
	.blkb 1
	.area idata
	.byte 32
	.area data(ram, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbsym e bit_race _bit_race c
_send_data::
	.blkb 1
	.area idata
	.byte 2
	.area data(ram, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbsym e send_data _send_data c
_trandata::
	.blkb 2
	.area idata
	.byte 0,1
	.area data(ram, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.blkb 2
	.area idata
	.byte 2,3
	.area data(ram, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbsym e trandata _trandata A[4:4]c
	.area text(rom, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbfunc e Delay_1ms _Delay_1ms fV
;              i -> R16,R17
	.even
_Delay_1ms::
	.dbline -1
	.dbline 39
; 
; /*函数的使用说明:
; 1.该twi模块包含四种工作模式,主发,主收,从收,从发,其中主发由
;   twiWriteByte(从机地址,要发送的数据)实现,主收由twiReadByte(从机地址)实现,从机
;   的发送与接收均通过中断实现
; 2.在从机模式下,需调用twi_init()来使能并初始化twi总线
; 3.在主机模式下,调用twiWriteByte(从机地址,要发送的数据)向指定的从机写入数据,
;   调用twiReadByte(从机地址)从指定的从机读取数据,然后可通过查询错误状态error_state
;   的值决定下一步如何操作。
; */
; 
; #include "twi.h"
; 
; //TWI同程序的接口参数
; //receive_data,error_state不用设置
; char receive_data=0;  		  // 接收到的数据
; char error_state=0;   		  // twi错误状态
; //以下三个参数根据需求进行设置
; char slave_address=0xC0;      // 设置从机地址,Bits 7..1:存放从机地址,Bit 0:最低位为广播识别使能位
; char bit_race=0x20;           // 设置主机模式的比特率,SCL=CPU频率/(16+2*(TWBR)*4TWPS),TWPS在4的指数位置
; char send_data=0x02;     	  // 从机发送模式下从机向主机发送的数据
; //要发送的数据
; char trandata[num] = {0x00,0x01,0x02,0x03};
; //*************************** twi错误状态说明*********************************
; // 0:twi传送无错误
; // 1:在主发模式下,SLA+W已发送,返回NOT ACK
; // 2:在主发模式下,DATA已发送,返回NOT ACK
; // 3:在主发模式下,SLA+W或者数据的仲裁失败
; // 4:在主收模式下,SLA+R或者数据的仲裁失败
; // 5:在主收模式下,SLA+R已发送,返回NOT ACK
; // 6:在主发模式下,START信号发送不成功
; // 7:在主收模式下,START信号发送不成功
; // 8:在主收模式下,数据接受完成
; // 9:在主收模式下,数据接受不成功
; //*****************************************************************************
; //*************************** 延时1ms 程序 *************************************
; //******************************************************************************
; void Delay_1ms(void)
; {
	.dbline 41
	clr R16
	clr R17
	rjmp L5
L2:
	.dbline 41
L3:
	.dbline 41
	subi R16,255  ; offset = 1
	sbci R17,255
L5:
	.dbline 41
; 	unsigned int i;
; 	for(i = 0;i < (unsigned int)11 * 143 - 2;i ++);
	cpi R16,35
	ldi R30,6
	cpc R17,R30
	brlo L2
	.dbline -2
	.dbline 42
; }
L1:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e Delay_Nms _Delay_Nms fV
;              j -> R20,R21
;              i -> R22,R23
	.even
_Delay_Nms::
	rcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 46
; //*************************** 延时1s 程序 **************************************
; //******************************************************************************
; void Delay_Nms(unsigned int i)
; {
	.dbline 48
; 	unsigned int j;
; 	for(j = 0;j < i;j ++)
	clr R20
	clr R21
	rjmp L10
L7:
	.dbline 49
	rcall _Delay_1ms
L8:
	.dbline 48
	subi R20,255  ; offset = 1
	sbci R21,255
L10:
	.dbline 48
	cp R20,R22
	cpc R21,R23
	brlo L7
	.dbline -2
	.dbline 50
; 		Delay_1ms();
; }
L6:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r j 20 i
	.dbsym r i 22 i
	.dbend
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 54
; //*************************** I/O 初始化****************************************
; //******************************************************************************
; void port_init(void)
; {
	.dbline 55
; 	PORTB = 0x2f;	//置PB0,PB1,PB2,PB3,PB5为1,PB4,PB6,PB7为0
	ldi R24,47
	out 0x18,R24
	.dbline 56
; 	DDRB = 0x2f;	//置PB0,PB1,PB2--SS,PB3--MOSI,PB5--SCK为输出,PB4--MISO为输入
	out 0x17,R24
	.dbline 57
; 	PORTC = 0x0f;   
	ldi R24,15
	out 0x15,R24
	.dbline 58
; 	DDRC  = 0x0f;	//PC4--SDA,PC5--SCL为输入,PC0--PC3全为输出以便测试
	out 0x14,R24
	.dbline 59
; 	PORTD = 0x05;	//置PWR,TXEN为1,  TRXCE为0
	ldi R24,5
	out 0x12,R24
	.dbline 60
; 	DDRD  = 0x07;	//置PD3,PD4,PD5输入;PD2--PWR,PD0--TXEN,PD1--TRXCE输出
	ldi R24,7
	out 0x11,R24
	.dbline -2
	.dbline 61
; }
L11:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 70
; //******************************串口程序****************************************
; //******************************************************************************
; //UART0 initialize
; // desired baud rate: 9600
; // actual: baud rate:9600 (0.0%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)
; {
	.dbline 71
;  UCSRB = 0x00; //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 72
;  UCSRA = 0x00;
	out 0xb,R2
	.dbline 73
;  UCSRC = BIT(URSEL) | 0x0E;
	ldi R24,142
	out 0x20,R24
	.dbline 74
;  UBRRL = 0x47; //set baud rate lo
	ldi R24,71
	out 0x9,R24
	.dbline 75
;  UBRRH = 0x00; //set baud rate hi
	out 0x20,R2
	.dbline 76
;  UCSRB = 0x98;
	ldi R24,152
	out 0xa,R24
	.dbline -2
	.dbline 77
; }
L12:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e USART_Transmit _USART_Transmit fV
;           data -> R16
	.even
_USART_Transmit::
	.dbline -1
	.dbline 81
; //********************串口程序函数实现部分**************************************
; //******************************************************************************
; void USART_Transmit( unsigned char data )
; {
L14:
	.dbline 82
L15:
	.dbline 82
; 	while ( !( UCSRA & (1<<UDRE)));   // 等待发送缓冲器为空
	sbis 0xb,5
	rjmp L14
	.dbline 83
; 	UDR = data; 	  // 将数据放入缓冲器,发送数据
	out 0xc,R16
	.dbline -2
	.dbline 84
; }
L13:
	.dbline 0 ; func end
	ret
	.dbsym r data 16 c
	.dbend
	.area vector(rom, abs)
	.org 22
	rjmp _uart0_rx_isr
	.area text(rom, con, rel)
	.dbfile E:\iccavr\无线+I2C\test1--sr\twimain.c
	.dbfunc e uart0_rx_isr _uart0_rx_isr fV
	.even
_uart0_rx_isr::
	.dbline -1
	.dbline 88
; 
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
	.dbline -2
	.dbline 90
; 	//uart has received a character in UDR
; }
L17:
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 94
; //****************************** 初始化外围 ************************************
; //******************************************************************************
; void init_devices(void)
; {
	.dbline 96
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 97
;  port_init();
	rcall _port_init
	.dbline 98
;  uart0_init();
	rcall _uart0_init
	.dbline 99
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 100
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 101
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 102
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
	.dbline 104
;  //all peripherals are now initialized
; }
L18:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
;              i -> <dead>
	.even
_main::
	.dbline -1
	.dbline 111
; //****************************** 主函数  ***************************************
; /*该程序工作于从收模式下,在基于中断的该模式下,cpu顺序接收来自主机的字符,并根
; 据字符的值去置位PC0--PC3为低,PC0--PC3可以外接LED以显示操作的结果
; */
; //******************************************************************************
; void main(void)
; {
	.dbline 113
;  	int i;
; 	init_devices();
	rcall _init_devices
	.dbline 114
; 	Delay_Nms(2000);
	ldi R16,2000
	ldi R17,7
	rcall _Delay_Nms
	rjmp L21
L20:
	.dbline 116
; 	while(1)
; 	{
	.dbline 117
; 	 	if(receive_data == 0x00)
	lds R2,_receive_data
	tst R2
	brne L23
	.dbline 118
; 		{
	.dbline 119
; 		 	PORTC &= ~BIT(PC0);
	cbi 0x15,0
	.dbline 120
; 		}
	rjmp L24
L23:
	.dbline 121
; 		else if(receive_data == 0x01)
	lds R24,_receive_data
	cpi R24,1
	brne L25
	.dbline 122
; 		{
	.dbline 123
; 		 	PORTC &= ~BIT(PC1);
	cbi 0x15,1
	.dbline 124
; 		}
	rjmp L26
L25:
	.dbline 126
; 		else
; 		PORTC |= 0X0f;
	in R24,0x15
	ori R24,15
	out 0x15,R24
L26:
L24:
	.dbline 134
L21:
	.dbline 115
	rjmp L20
X0:
	.dbline -2
	.dbline 135
; 		
; 		
; 		/* for(i = 0 ; i < num ; i ++)
; 		 {
; 			USART_Transmit( receive_data )	//给下位机发送接收到的数据,
; 			Delay_1ms();
; 		 }*/
; 	}
; }
L19:
	.dbline 0 ; func end
	ret
	.dbsym l i 1 I
	.dbend

⌨️ 快捷键说明

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