📄 server.s
字号:
.module server.c
.area data(ram, con, rel)
_flag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\单片机教学\调试程序\实验二舵机串口\server.c
.dbsym e flag _flag c
.area text(rom, con, rel)
.dbfile F:\单片机教学\调试程序\实验二舵机串口\server.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 10
; //ICC-AVR application builder : 2005-3-29 下午 10:34:28
; // Target : M8
; // Crystal: 11.059Mhz
;
; #include <iom8v.h>
; #include <macros.h>
; char flag = 0;
;
; void port_init(void)
; {
.dbline 11
; PORTB = 0xFF;
ldi R24,255
out 0x18,R24
.dbline 12
; DDRB = 0x02;//设置PB1为输出;
ldi R24,2
out 0x17,R24
.dbline 13
; PORTC = 0x7F; //m103 output only
ldi R24,127
out 0x15,R24
.dbline 14
; DDRC = 0x00;
clr R2
out 0x14,R2
.dbline 15
; PORTD = 0xFF;
ldi R24,255
out 0x12,R24
.dbline 16
; DDRD = 0x00;
out 0x11,R2
.dbline -2
.dbline 17
; }
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e timer1_init _timer1_init fV
.even
_timer1_init::
.dbline -1
.dbline 25
;
; //设置PWM输出方式;
; //TIMER1 initialisation - prescale:8
; // WGM: 14) PWM fast, TOP=ICRn
; // desired value: 50Hz
; // actual value: 50.001Hz (0.0%)
; void timer1_init(void)
; {
.dbline 26
; TCCR1B = 0x00; //stop
clr R2
out 0x2e,R2
.dbline 28
;
; TCNT1H = 0x00; //setup
out 0x2d,R2
.dbline 29
; TCNT1L = 0x00;
out 0x2c,R2
.dbline 31
;
; OCR1AH = 0x08;
ldi R24,8
out 0x2b,R24
.dbline 32
; OCR1AL = 0x19;
ldi R24,25
out 0x2a,R24
.dbline 33
; OCR1BH = 0x08;
ldi R24,8
out 0x29,R24
.dbline 34
; OCR1BL = 0x19;
ldi R24,25
out 0x28,R24
.dbline 36
;
; ICR1H = 0x6B;
ldi R24,107
out 0x27,R24
.dbline 37
; ICR1L = 0xFE;
ldi R24,254
out 0x26,R24
.dbline 39
;
; TCCR1A = 0xA2;
ldi R24,162
out 0x2f,R24
.dbline 40
; TCCR1B = 0x1A; //start Timer
ldi R24,26
out 0x2e,R24
.dbline -2
.dbline 41
; }
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e uart0_init _uart0_init fV
.even
_uart0_init::
.dbline -1
.dbline 50
;
; //串口初始化
; //UART0 initialisation
; // desired baud rate: 9600
; // actual: baud rate:9600 (0.0%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)
; {
.dbline 51
; UCSRB = 0x00; //disable while setting baud rate
clr R2
out 0xa,R2
.dbline 52
; UCSRA = 0x00;
out 0xb,R2
.dbline 53
; UCSRC = 0x86;
ldi R24,134
out 0x20,R24
.dbline 54
; UBRRL = 0x47; //set baud rate lo
ldi R24,71
out 0x9,R24
.dbline 55
; UBRRH = 0x00; //set baud rate hi
out 0x20,R2
.dbline 56
; UCSRB = 0x98;
ldi R24,152
out 0xa,R24
.dbline -2
.dbline 57
; }
L3:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 22
rjmp _uart0_rx_isr
.area text(rom, con, rel)
.dbfile F:\单片机教学\调试程序\实验二舵机串口\server.c
.dbfunc e uart0_rx_isr _uart0_rx_isr fV
; data -> R16
; time -> R16,R17
.even
_uart0_rx_isr::
st -y,R0
st -y,R1
st -y,R2
st -y,R3
st -y,R16
st -y,R17
st -y,R24
in R0,0x3f
st -y,R0
.dbline -1
.dbline 61
;
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
.dbline 66
; //uart has received a character in UDR
; char data;
; unsigned int time;
;
; data = UDR;//取出数据;
in R16,0xc
.dbline 67
; UDR = data;//返回接收的数据;
out 0xc,R16
.dbline 68
; time = data*31;//注意需要先乘,后移位防止溢出;
ldi R24,31
mul R24,R16
movw R16,R0
.dbline 69
; time = ( time>>1)+691;//注意运算符的优先级顺序;
lsr R17
ror R16
subi R16,77 ; offset = 691
sbci R17,253
.dbline 70
; OCR1AH = time >>8;//16位寄存器先写高位,后写低位;
movw R2,R16
mov R2,R3
clr R3
out 0x2b,R2
.dbline 71
; OCR1AL = time;
out 0x2a,R16
.dbline -2
.dbline 72
; }
L4:
ld R0,y+
out 0x3f,R0
ld R24,y+
ld R17,y+
ld R16,y+
ld R3,y+
ld R2,y+
ld R1,y+
ld R0,y+
.dbline 0 ; func end
reti
.dbsym r data 16 c
.dbsym r time 16 i
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 76
;
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
.dbline 78
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 79
; port_init();
rcall _port_init
.dbline 80
; timer1_init();
rcall _timer1_init
.dbline 81
; uart0_init();
rcall _uart0_init
.dbline 83
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 84
; GICR = 0x00;
out 0x3b,R2
.dbline 85
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 86
; SEI(); //re-enable interrupts
sei
.dbline -2
.dbline 88
; //all peripherals are now initialised
; }
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 92
;
; //
; void main(void)
; {
.dbline 93
; init_devices();
rcall _init_devices
L7:
.dbline 95
L8:
.dbline 95
rjmp L7
X0:
.dbline -2
.dbline 96
; //insert your functional code here...
; while(1);
; }
L6:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -