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

📄 init.s

📁 modbus RTU 的AVR单片机C语言程序。 单片机mega16,编译器ICCAVR。
💻 S
字号:
	.module init.c
	.area text(rom, con, rel)
	.dbfile E:\我的网页\mcuc\download\M16-23板程序模板\新建文件夹\init.c
	.dbfunc e varInit _varInit fV
	.even
_varInit::
	.dbline -1
	.dbline 9
; //ICC-AVR application builder : 2004-10-27 10:06:29
; // Target : M16
; // Crystal: 8.0000Mhz
; 
; #include "main.h"
; 
; //初始化变量
; void varInit(void)
; {
	.dbline -2
	.dbline 11
; 
; }//void valInit(void)
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 14
; 
; void port_init(void)
; {
	.dbline 16
;  	 				// 
;  PORTA = 0xF0;		//		
	ldi R24,240
	out 0x1b,R24
	.dbline 17
;  DDRA  = 0x00;		//
	clr R2
	out 0x1a,R2
	.dbline 18
;  PORTB = 0xFF;		//
	ldi R24,255
	out 0x18,R24
	.dbline 19
;  DDRB  = 0xFD;		//
	ldi R24,253
	out 0x17,R24
	.dbline 20
;  PORTC = 0xFF; 		//
	ldi R24,255
	out 0x15,R24
	.dbline 21
;  DDRC  = 0x00;		//
	out 0x14,R2
	.dbline 22
;  PORTD = 0xFF;		//
	out 0x12,R24
	.dbline 23
;  DDRD  = 0xFA;		//
	ldi R24,250
	out 0x11,R24
	.dbline -2
	.dbline 24
; }//void port_init(void)
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e watchdog_init _watchdog_init fV
	.even
_watchdog_init::
	.dbline -1
	.dbline 30
; 
; 
; //Watchdog initialisation
; // prescale: 2048K cycles
; void watchdog_init(void)
; {
	.dbline 31
;  WDR(); //this prevents a timout on enabling
	wdr
	.dbline 32
;  WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs
	ldi R24,15
	out 0x21,R24
	.dbline -2
	.dbline 33
; }//void watchdog_init(void)
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 36
; 
; void timer0_init(void)
; {
	.dbline 38
;  //初始化1ms 定时中断
;  TCCR0 = 0x00;
	clr R2
	out 0x33,R2
	.dbline 39
;  TIFR  = 0x00;  
	out 0x38,R2
	.dbline 40
;  TCNT0 = 0x83;
	ldi R24,131
	out 0x32,R24
	.dbline 41
;  TCCR0 = 0x03;
	ldi R24,3
	out 0x33,R24
	.dbline -2
	.dbline 42
; }//void timer0_init(void)
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e adc_init _adc_init fV
;         adcMux -> R16
	.even
_adc_init::
	.dbline -1
	.dbline 47
; 
; //ADC initialisation
; // Conversion time: 52uS
; void adc_init(void)
; {
	.dbline 48
;  uint8 adcMux = 0;
	clr R16
	.dbline 50
;  
;  ADCSR = 0x00; //disable adc
	clr R2
	out 0x6,R2
	.dbline 51
;  ADMUX = 0xc0 |(adcMux&0x0f); //select adc input 0   2.56V参考源
	mov R24,R16
	andi R24,15
	ori R24,192
	out 0x7,R24
	.dbline 52
;  ACSR  = 0x80;
	ldi R24,128
	out 0x8,R24
	.dbline 53
;  ADCSR = 0x85; //使能ADC 32分频
	ldi R24,133
	out 0x6,R24
	.dbline -2
	.dbline 54
; }//void adc_init(void)
L5:
	.dbline 0 ; func end
	ret
	.dbsym r adcMux 16 c
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 62
; 
; //UART0 initialisation
; // desired baud rate: 9600
; // actual: baud rate:9615 (0.2%)
; // char size: 8 bit
; // parity: Even
; void uart0_init(void)
; {
	.dbline 63
;  UCSRB = 0x00; //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 64
;  UCSRA = 0x00;
	out 0xb,R2
	.dbline 65
;  UCSRC = 0xA6;
	ldi R24,166
	out 0x20,R24
	.dbline 66
;  UBRRL = 51; //set baud rate lo
	ldi R24,51
	out 0x9,R24
	.dbline 67
;  UBRRH = 0x00; //set baud rate hi
	out 0x20,R2
	.dbline 68
;  UCSRB = 0xD8;
	ldi R24,216
	out 0xa,R24
	.dbline 70
;  
;  receEnable();
	cbi 0x18,7
	.dbline -2
	.dbline 71
; }
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 44
	jmp _uart0_rx_isr
	.area text(rom, con, rel)
	.dbfile E:\我的网页\mcuc\download\M16-23板程序模板\新建文件夹\init.c
	.dbfunc e uart0_rx_isr _uart0_rx_isr fV
;         status -> R16
	.even
_uart0_rx_isr::
	st -y,R2
	st -y,R16
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 75
; 
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
	.dbline 79
;  	uint8 status;
; 	
;  //uart has received a character in UDR
; 	status = UCSRA;
	in R16,0xb
	.dbline 80
;     receBuf[receCount] = UDR;
	ldi R24,<_receBuf
	ldi R25,>_receBuf
	lds R30,_receCount
	clr R31
	add R30,R24
	adc R31,R25
	in R2,0xc
	std z+0,R2
	.dbline 82
; 	
;     if(status & 0x1c)  //通信出错
	mov R24,R16
	andi R24,28
	breq L8
	.dbline 83
;     	 checkoutError = 2;	//偶校验出错
	ldi R24,2
	sts _checkoutError,R24
L8:
	.dbline 86
; 
;   	//testRegister = status;		 
;     receCount++;          //接收地址偏移寄存器加1
	lds R24,_receCount
	subi R24,255    ; addi 1
	sts _receCount,R24
	.dbline 87
;     receCount &= 0x1f;    //最多一次只能接收32个字节 
	andi R24,31
	sts _receCount,R24
	.dbline 88
;     receTimeOut = 10;    //通讯超时值	
	ldi R24,10
	sts _receTimeOut,R24
	.dbline -2
	.dbline 89
; }
L7:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R16,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbsym r status 16 c
	.dbend
	.area vector(rom, abs)
	.org 52
	jmp _uart0_tx_isr
	.area text(rom, con, rel)
	.dbfile E:\我的网页\mcuc\download\M16-23板程序模板\新建文件夹\init.c
	.dbfunc e uart0_tx_isr _uart0_tx_isr fV
	.even
_uart0_tx_isr::
	st -y,R2
	st -y,R3
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 93
; 
; #pragma interrupt_handler uart0_tx_isr:14
; void uart0_tx_isr(void)
; {
	.dbline 95
;  //character has been transmitted
;     if(sendPosi < sendCount) 
	lds R2,_sendCount
	lds R3,_sendPosi
	cp R3,R2
	brsh L11
	.dbline 96
;     {
	.dbline 97
;         sendPosi++;
	mov R24,R3
	subi R24,255    ; addi 1
	sts _sendPosi,R24
	.dbline 98
;         UDR = sendBuf[sendPosi];
	ldi R24,<_sendBuf
	ldi R25,>_sendBuf
	lds R30,_sendPosi
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0xc,R2
	.dbline 99
;     }
	xjmp L12
L11:
	.dbline 101
	.dbline 102
	cbi 0x18,7
	.dbline 103
	clr R2
	sts _receCount,R2
	.dbline 104
	sts _checkoutError,R2
	.dbline 105
L12:
	.dbline -2
	.dbline 106
;     else
;     {
;         receEnable();    //发送完后将485置于接收状态
;         receCount = 0;   //清接收地址偏移寄存器
;         checkoutError = 0;
;     } 
; }
L10:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R3,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 110
; 
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
	.dbline 112
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 113
;  port_init();
	xcall _port_init
	.dbline 114
;  watchdog_init(); 
	xcall _watchdog_init
	.dbline 115
;  timer0_init();
	xcall _timer0_init
	.dbline 116
;  adc_init();
	xcall _adc_init
	.dbline 117
;  uart0_init(); 
	xcall _uart0_init
	.dbline 119
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 120
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 121
;  TIMSK = 0x01; //timer interrupt sources
	ldi R24,1
	out 0x39,R24
	.dbline 122
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
	.dbline 124
;  //all peripherals are now initialised
; }//void init_devices(void)
L13:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

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