?? 串口發送接收.s
字號:
.module _串口發送接收.c
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\設計資料\項目設計\ICCAVR_mega8_C\ICCAVR_mega8_串口發送接收\串口發送接收.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 9
; //ICC-AVR application builder : 2009-3-11 14:28:07
; // Target : M8
; // Crystal: 8.0000Mhz
;
; #include <iom8v.h>
; #include <macros.h>
;
; void port_init(void)
; {
.dbline 10
; PORTB = 0x00;
clr R2
out 0x18,R2
.dbline 11
; DDRB = 0x00;
out 0x17,R2
.dbline 12
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 13
; DDRC = 0x00;
out 0x14,R2
.dbline 14
; PORTD = 0x00;
out 0x12,R2
.dbline 15
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 20
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 22
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 23
; port_init();
rcall _port_init
.dbline 25
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 26
; GICR = 0x00;
out 0x3b,R2
.dbline 27
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 28
; SEI(); //re-enable interrupts
sei
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay _delay fV
; i -> R16,R17
.even
_delay::
.dbline -1
.dbline 38
; //all peripherals are now initialized
; }
;
; /************************************
; Name :小延時程序
; Target :atmega8
; Crystal(晶振):8M
; ************************************/
; void delay()
; {
.dbline 40
; unsigned int i;//最大值65536
; for (i=0;i<40000;i++)
clr R16
clr R17
rjmp L7
L4:
.dbline 41
; {;}
.dbline 41
.dbline 41
L5:
.dbline 40
subi R16,255 ; offset = 1
sbci R17,255
L7:
.dbline 40
ldi R24,64
ldi R25,156
ldi R26,0
ldi R27,0
movw R2,R16
clr R4
clr R5
cp R2,R24
cpc R3,R25
cpc R4,R26
cpc R5,R27
brlt L4
X0:
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e init_uart _init_uart fV
.even
_init_uart::
.dbline -1
.dbline 55
; }
;
; /***********************************************************
; 用 途:串口發送接收程序
; Taget :mega8
; crystal :8M
; 介 紹:
; **********************************************************/
; //晶振和波特率
; #define fosc 8000000
; #define baud 9600
; //UART初始化函數
; void init_uart()
; {
.dbline 56
; UCSRB=(1<<RXEN)|(1<<TXEN)|(1<<RXCIE);//允許收發,打開接收中斷
ldi R24,152
out 0xa,R24
.dbline 57
; UBRRL=(fosc/16/(baud+1))%256;//設置波特率寄存器
ldi R24,52
out 0x9,R24
.dbline 58
; UBRRH=(fosc/16/(baud+1))/256;
clr R2
out 0x20,R2
.dbline 59
; UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);//8位數據+1位STOP
ldi R24,134
out 0x20,R24
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbend
.dbfunc e uart_putchar _uart_putchar fV
; c -> R16
.even
_uart_putchar::
.dbline -1
.dbline 63
; }
; //字符輸出
; void uart_putchar(unsigned char c)
; {
L10:
.dbline 64
; while(!(UCSRA&(1<<UDRE)));//上次發送有沒有完成
L11:
.dbline 64
sbis 0xb,5
rjmp L10
X1:
.dbline 65
; UDR=c;
out 0xc,R16
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.dbfunc e uart_getchar _uart_getchar fc
.even
_uart_getchar::
.dbline -1
.dbline 69
; }
; //字符輸入
; unsigned char uart_getchar()
; {
L14:
.dbline 70
; while(!(UCSRA&(1<<RXC))){;}//有沒有接收到數據
.dbline 70
.dbline 70
L15:
.dbline 70
sbis 0xb,7
rjmp L14
X2:
.dbline 71
; return UDR;
in R16,0xc
.dbline -2
L13:
.dbline 0 ; func end
ret
.dbend
.dbfunc e uart_print _uart_print fI
; s -> R20,R21
.even
_uart_print::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 75
; }
; //帶回車的字符串輸出
; int uart_print(char *s)
; {
rjmp L19
L18:
.dbline 77
; while(*s)
; {
.dbline 78
; uart_putchar(*s);
movw R30,R20
ldd R16,z+0
rcall _uart_putchar
.dbline 79
; s++;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 80
; }
L19:
.dbline 76
movw R30,R20
ldd R2,z+0
tst R2
brne L18
X3:
.dbline 81
; uart_putchar(0x0a);//回車換行
ldi R16,10
rcall _uart_putchar
.dbline 82
; uart_putchar(0x0d);
ldi R16,13
rcall _uart_putchar
.dbline 83
; return 1;
ldi R16,1
ldi R17,0
.dbline -2
L17:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r s 20 pc
.dbend
.dbfunc e uart_prints _uart_prints fV
; s -> R20,R21
.even
_uart_prints::
st -y,R20
st -y,R21
movw R20,R16
.dbline -1
.dbline 87
; }
; //不帶回車換行的字符串輸出
; void uart_prints(char *s)
; {
rjmp L23
L22:
.dbline 89
; while(*s)
; {
.dbline 90
; uart_putchar(*s);
movw R30,R20
ldd R16,z+0
rcall _uart_putchar
.dbline 91
; s++;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 92
; }
L23:
.dbline 88
movw R30,R20
ldd R2,z+0
tst R2
brne L22
X4:
.dbline -2
L21:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r s 20 pc
.dbend
.area vector(rom, abs)
.org 22
rjmp _uart_rec_int
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\設計資料\項目設計\ICCAVR_mega8_C\ICCAVR_mega8_串口發送接收\串口發送接收.c
.dbfunc e uart_rec_int _uart_rec_int fV
.even
_uart_rec_int::
st -y,R0
st -y,R1
st -y,R2
st -y,R3
st -y,R4
st -y,R5
st -y,R6
st -y,R7
st -y,R8
st -y,R9
st -y,R16
st -y,R17
st -y,R18
st -y,R19
st -y,R24
st -y,R25
st -y,R26
st -y,R27
st -y,R30
st -y,R31
in R0,0x3f
st -y,R0
.dbline -1
.dbline 97
; }
; //接收中斷
; #pragma interrupt_handler uart_rec_int:iv_USART_RX
; void uart_rec_int()
; {
.dbline 98
; uart_putchar(UDR);
in R16,0xc
rcall _uart_putchar
.dbline 99
; uart_putchar(0x0a);//回車換行
ldi R16,10
rcall _uart_putchar
.dbline 100
; uart_putchar(0x0d);
ldi R16,13
rcall _uart_putchar
.dbline -2
L25:
.dbline 0 ; func end
ld R0,y+
out 0x3f,R0
ld R31,y+
ld R30,y+
ld R27,y+
ld R26,y+
ld R25,y+
ld R24,y+
ld R19,y+
ld R18,y+
ld R17,y+
ld R16,y+
ld R9,y+
ld R8,y+
ld R7,y+
ld R6,y+
ld R5,y+
ld R4,y+
ld R3,y+
ld R2,y+
ld R1,y+
ld R0,y+
reti
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 105
; }
; //**************************************************************************
;
; void main()
; {
.dbline 106
; port_init();
rcall _port_init
.dbline 107
; init_devices();
rcall _init_devices
.dbline 109
;
; init_uart();
rcall _init_uart
.dbline 110
; uart_print("xiaozhiyong");
ldi R16,<L27
ldi R17,>L27
rcall _uart_print
L28:
.dbline 112
; while(1)
; {
.dbline 113
; ;
.dbline 115
; //delay();
; }
L29:
.dbline 111
rjmp L28
X5:
.dbline -2
L26:
.dbline 0 ; func end
ret
.dbend
.area data(ram, con, rel)
.dbfile E:\xiaozhiyong2009\設計資料\項目設計\ICCAVR_mega8_C\ICCAVR_mega8_串口發送接收\串口發送接收.c
L27:
.blkb 12
.area idata
.byte 'x,'i,'a,'o,'z,'h,'i,'y,'o,'n,'g,0
.area data(ram, con, rel)
.dbfile E:\xiaozhiyong2009\設計資料\項目設計\ICCAVR_mega8_C\ICCAVR_mega8_串口發送接收\串口發送接收.c
; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -