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

📄 initial.s

📁 avr 基于i2c接口的电源管理协议。包括主机发送主机接受从机发送接收。
💻 S
字号:
	.module initial.c
	.area text(rom, con, rel)
	.dbfile D:\myavrproject\icc\twi\initial.c
	.dbfunc e watchdog_init _watchdog_init fV
	.even
_watchdog_init::
	.dbline -1
	.dbline 12
; //ICC-AVR application builder : 2007-1-9 14:28:21
; // Target : M8
; // Crystal: 8.0000Mhz
; 
; #include <iom8v.h>
; #include <macros.h>
; 
; 
; //Watchdog initialize
; // prescale: 2048K
; void watchdog_init(void)
; {
	.dbline 13
;  WDR(); //this prevents a timout on enabling
	wdr
	.dbline 14
;  WDTCR = 0x0f; //WATCHDOG ENABLED - dont forget to issue WDRs
	ldi R24,15
	out 0x21,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e twi_init _twi_init fV
	.even
_twi_init::
	.dbline -1
	.dbline 28
;  /*
;  //关闭看门狗
;  //置位WDCE 和 WDE 
;  WDTCR |= (1<<WDCE) | (1<<WDE);
;  //关闭WDT
;  WDTCR = 0x00;
;  */
; }
; 
; //TWI initialize
; // bit rate:72
; //50KHZ
; void twi_init(void)
; {
	.dbline 29
;  TWCR= 0X00; //disable twi
	clr R2
	out 0x36,R2
	.dbline 30
;  TWBR= 0x48; //set bit rate
	ldi R24,72
	out 0x0,R24
	.dbline 31
;  TWSR= 0x00; //set prescale
	out 0x1,R2
	.dbline 32
;  TWAR= 0x01; //set slave address
	ldi R24,1
	out 0x2,R24
	.dbline 33
;  TWCR= 0x45; //enable twi
	ldi R24,69
	out 0x36,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 34
	rjmp _twi_isr
	.area text(rom, con, rel)
	.dbfile D:\myavrproject\icc\twi\initial.c
	.dbfunc e twi_isr _twi_isr fV
	.even
_twi_isr::
	.dbline -1
	.dbline 38
; }
; 
; #pragma interrupt_handler twi_isr:18
; void twi_isr(void)
; {
	.dbline -2
L3:
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 48
;  //twi event
; }
; 
; //UART0 initialize
; // desired baud rate: 9600
; // actual: baud rate:9615 (0.2%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)
; {
	.dbline 49
;  UCSRB = 0x00; //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 50
;  UCSRA = 0x02;
	ldi R24,2
	out 0xb,R24
	.dbline 51
;  UCSRC = BIT(URSEL) | 0x06;
	ldi R24,134
	out 0x20,R24
	.dbline 52
;  UBRRL = 0x67; //set baud rate lo
	ldi R24,103
	out 0x9,R24
	.dbline 53
;  UBRRH = 0x00; //set baud rate hi
	out 0x20,R2
	.dbline 54
;  UCSRB = 0x18;
	ldi R24,24
	out 0xa,R24
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 59
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 61
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 62
;  port_init();
	rcall _port_init
	.dbline 63
;  watchdog_init();
	rcall _watchdog_init
	.dbline 64
;  twi_init();
	rcall _twi_init
	.dbline 65
;  uart0_init();
	rcall _uart0_init
	.dbline 68
; 
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 69
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 70
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 71
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L5:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

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