📄 init.s
字号:
.module init.c
.area text(rom, con, rel)
.dbfile C:\RGauge\init.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 12
; //ICC-AVR application builder : 14/3/2007 23:29:10
; // Target : M16
; // Crystal: 7.3728Mhz
;
; #include "config.h"
; #include "predef.h"
;
; #define BAUD_RATE 9600
; #define BAUD_PRESCALE (((F_CPU / (BAUD_RATE * 16UL))) - 1)
;
; void port_init(void)
; {
.dbline 13
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 14
; DDRA = 0x00;
out 0x1a,R2
.dbline 15
; PORTB = 0xFD;
ldi R24,253
out 0x18,R24
.dbline 16
; DDRB = 0xB0;
ldi R24,176
out 0x17,R24
.dbline 17
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 18
; DDRC = 0x00;
out 0x14,R2
.dbline 19
; PORTD = 0x00;
out 0x12,R2
.dbline 20
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e uart0_init _uart0_init fV
.even
_uart0_init::
.dbline -1
.dbline 29
; }
;
; //UART0 initialize
; // desired baud rate:
; // actual: baud rate: (0.0%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)
; {
.dbline 30
; UCSRB = 0x00; //disable while setting baud rate
clr R2
out 0xa,R2
.dbline 31
; UCSRA = 0x00;
out 0xb,R2
.dbline 32
; UCSRC = BIT(URSEL) | 0x06; //Use 8-bit character sizes - URSEL bit set to select the UCRSC register
ldi R24,134
out 0x20,R24
.dbline 33
; UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
ldi R24,47
out 0x9,R24
.dbline 34
; UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
out 0x20,R2
.dbline 35
; UCSRB = 0xD8;
ldi R24,216
out 0xa,R24
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.area data(ram, con, rel)
.dbfile C:\RGauge\init.c
_sendready::
.blkb 2
.area idata
.word 1
.area data(ram, con, rel)
.dbfile C:\RGauge\init.c
.dbsym e sendready _sendready I
.area vector(rom, abs)
.org 44
jmp _uart0_rx_isr
.area data(ram, con, rel)
.dbfile C:\RGauge\init.c
.area text(rom, con, rel)
.dbfile C:\RGauge\init.c
.dbfunc e uart0_rx_isr _uart0_rx_isr fV
; status -> R22
; data -> R20
.even
_uart0_rx_isr::
xcall push_lset
xcall push_gset2
.dbline -1
.dbline 41
; }
;
; extern int sendready=1;
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
.dbline 44
; //uart has received a character in UDR
; unsigned char status,data;
; status=UCSRA; //get the usart status
in R22,0xb
.dbline 45
; data = UDR; //put the received character to data variable
in R20,0xc
.dbline 46
; if(data == 'R') {
cpi R20,82
brne L4
.dbline 46
.dbline 47
; sendready = 1;
ldi R24,1
ldi R25,0
sts _sendready+1,R25
sts _sendready,R24
.dbline 48
; }
L4:
.dbline 50
mov R24,R22
andi R24,24
brne L6
.dbline 51
.dbline 52
mov R16,R20
xcall _uart_putc
.dbline 53
L6:
.dbline -2
L3:
xcall pop_gset2
xcall pop_lset
.dbline 0 ; func end
reti
.dbsym r status 22 c
.dbsym r data 20 c
.dbend
.area vector(rom, abs)
.org 52
jmp _uart0_tx_isr
.area text(rom, con, rel)
.dbfile C:\RGauge\init.c
.dbfunc e uart0_tx_isr _uart0_tx_isr fV
.even
_uart0_tx_isr::
.dbline -1
.dbline 59
;
; if((status & (FRAMING_ERROR | DATA_OVERRUN))==0)
; {
; uart_putc(data);
; }
;
; }
;
; #pragma interrupt_handler uart0_tx_isr:14
; void uart0_tx_isr(void)
; {
.dbline -2
L8:
.dbline 0 ; func end
reti
.dbend
.dbfunc e spi_init _spi_init fV
.even
_spi_init::
.dbline -1
.dbline 67
; //character has been transmitted
; }
;
; //SPI initialize
; //Master mode
; // clock rate: 460799hz
; void spi_init(void)
; {
.dbline 68
; SPCR = 0x72; //setup SPI
ldi R24,114
out 0xd,R24
.dbline 69
; SPSR = 0x00; //setup SPI
clr R2
out 0xe,R2
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 40
jmp _spi_stc_isr
.area text(rom, con, rel)
.dbfile C:\RGauge\init.c
.dbfunc e spi_stc_isr _spi_stc_isr fV
.even
_spi_stc_isr::
.dbline -1
.dbline 74
; }
;
; #pragma interrupt_handler spi_stc_isr:11
; void spi_stc_isr(void)
; {
.dbline -2
L10:
.dbline 0 ; func end
reti
.dbend
.dbfunc e timer0_init _timer0_init fV
.even
_timer0_init::
.dbline -1
.dbline 84
; //byte in SPDR has been sent/received
; }
;
;
; //TIMER0 initialize - prescale:64
; // WGM: Normal
; // desired value: 1mSec
; // actual value: 0.998mSec (0.2%)
; void timer0_init(void)
; {
.dbline 85
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline 86
; TCNT0 = 0x8D; //set count
ldi R24,141
out 0x32,R24
.dbline 87
; OCR0 = 0x73; //set compare
ldi R24,115
out 0x3c,R24
.dbline 88
; TCCR0 = 0x03; //start timer
ldi R24,3
out 0x33,R24
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.area data(ram, con, rel)
.dbfile C:\RGauge\init.c
_count::
.blkb 2
.area idata
.word 0
.area data(ram, con, rel)
.dbfile C:\RGauge\init.c
.dbsym e count _count i
.area vector(rom, abs)
.org 36
jmp _timer0_ovf_isr
.area data(ram, con, rel)
.dbfile C:\RGauge\init.c
.area text(rom, con, rel)
.dbfile C:\RGauge\init.c
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
xcall push_lset
.dbline -1
.dbline 98
; }
;
;
; unsigned int count=0; //to count timer0
; extern char buffer [33];
; char uabuffer [33];
; extern int rcount;
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
.dbline 99
; TCNT0 = 0x8D; //reload counter value
ldi R24,141
out 0x32,R24
.dbline 100
; if (++count == 5000) //1000 ms = 1 Sec
lds R24,_count
lds R25,_count+1
adiw R24,1
sts _count+1,R25
sts _count,R24
cpi R24,136
ldi R30,19
cpc R25,R30
brne L13
.dbline 101
; {
.dbline 102
; count = 0;
clr R2
clr R3
sts _count+1,R3
sts _count,R2
.dbline 103
; if (sendready == 1) {
lds R24,_sendready
lds R25,_sendready+1
cpi R24,1
ldi R30,0
cpc R25,R30
brne L15
.dbline 103
.dbline 104
; uart_puts(buffer); //put the buffer to the serial
ldi R16,<_buffer
ldi R17,>_buffer
xcall _uart_puts
.dbline 105
; sendready = 0;
clr R2
clr R3
sts _sendready+1,R3
sts _sendready,R2
.dbline 106
; }
L15:
.dbline 107
; else {
.dbline 109
; //put to the queue buffer
; }
L16:
.dbline 111
clr R2
out 0x2d,R2
.dbline 112
out 0x2c,R2
.dbline 113
L13:
.dbline -2
L12:
xcall pop_lset
.dbline 0 ; func end
reti
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 119
; //reset the counter 1
; TCNT1H=0x00;
; TCNT1L=0x00;
; }
;
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 121
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 122
; port_init();
xcall _port_init
.dbline 123
; uart0_init();
xcall _uart0_init
.dbline 124
; spi_init();
xcall _spi_init
.dbline 125
; timer0_init();
xcall _timer0_init
.dbline 127
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 128
; GICR = 0x00;
out 0x3b,R2
.dbline 129
; TIMSK = 0x01; //timer interrupt sources
ldi R24,1
out 0x39,R24
.dbline 130
; SEI(); //re-enable interrupts
sei
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile C:\RGauge\init.c
_uabuffer::
.blkb 33
.dbsym e uabuffer _uabuffer A[33:33]c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -