📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile F:\ChengXuCunFang\ChengXU\AVR单片机程序存放\max485多机通讯1\从机1/delay.h
.dbfunc e delay_1us _delay_1us fV
.even
_delay_1us::
.dbline -1
.dbline 15
; //从机11
; #include<iom16v.h>
; #include <macros.h>
; #include "delay.h"
; #include "1602.h"
;
; #define amount 10 //设定通讯数据量
; #define address 11 //请在这里设定本机地址
; #define max485_out PORTD |=(1<<PD4)
; #define max485_in PORTD &=~(1<<PD4)
; #define max485_RW_ok DDRD|=(1<<PD4)
;
; unsigned char send[amount]; //发件箱
; unsigned char inbox[amount]; //收件箱
; unsigned char n=0; //记忆中断次数
.dbline 16
;
nop
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay_nus _delay_nus fV
; i -> R20,R21
; n -> R22,R23
.even
_delay_nus::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 20
; //波特率9600/9个数据位/1个停止位/奇校验/收发开启/接收中断/地址过滤
; void usart_init(void)
; {
; UCSRA=0x01;
.dbline 21
; UCSRB=0x9C;
clr R20
clr R21
.dbline 22
; UCSRC=0xB6;
xjmp L6
L3:
.dbline 23
xcall _delay_1us
L4:
.dbline 22
subi R20,255 ; offset = 1
sbci R21,255
L6:
.dbline 22
cp R20,R22
cpc R21,R23
brlo L3
.dbline -2
L2:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 22 i
.dbend
.dbfunc e delay_1ms _delay_1ms fV
; i -> R16,R17
.even
_delay_1ms::
.dbline -1
.dbline 27
; UBRRH=0x00;
; UBRRL=47;
; }
;
; unsigned char crc8(unsigned char *ptr, unsigned char len)
.dbline 29
clr R16
clr R17
xjmp L11
L8:
.dbline 29
L9:
.dbline 29
subi R16,255 ; offset = 1
sbci R17,255
L11:
.dbline 29
; {
; unsigned char i;
cpi R16,116
ldi R30,4
cpc R17,R30
brlo L8
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e delay_nms _delay_nms fV
; i -> R20,R21
; n -> R22,R23
.even
_delay_nms::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 33
; unsigned char crc=0;
; while(len--!=0)
; {
; for(i=1; i!=0; i*=2)
.dbline 34
; {
clr R20
clr R21
.dbline 35
; if((crc&1)!=0) {crc/=2; crc^=0x8C;}
xjmp L16
L13:
.dbline 36
xcall _delay_1ms
L14:
.dbline 35
subi R20,255 ; offset = 1
sbci R21,255
L16:
.dbline 35
cp R20,R22
cpc R21,R23
brlo L13
.dbline -2
L12:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 22 i
.dbend
.dbfile F:\ChengXuCunFang\ChengXU\AVR单片机程序存放\max485多机通讯1\从机1/1602.h
.dbfunc e LCD_init _LCD_init fV
.even
_LCD_init::
.dbline -1
.dbline 44
; else crc/=2;
; if((*ptr&i)!=0) crc^=0x8C;
; }
; ptr++;
; }
; return(crc);
; }
;
;
.dbline 45
;
in R24,0x14
ori R24,15
out 0x14,R24
.dbline 46
; //**************************************************************************************
sbi 0x14,5
.dbline 47
;
sbi 0x14,4
.dbline 48
; void usart_out(unsigned char *datas,unsigned char n)
ldi R16,40
xcall _LCD_write_command
.dbline 49
; {
xcall _LCD_en_write
.dbline 50
; unsigned char i=0;
ldi R16,40
ldi R17,0
xcall _delay_nus
.dbline 51
; max485_out; //使MAX485处于发送状态
ldi R16,40
xcall _LCD_write_command
.dbline 52
; while(i<n) //一共发送n个数据
ldi R16,12
xcall _LCD_write_command
.dbline 53
; {
ldi R16,1
xcall _LCD_write_command
.dbline 54
; if(i==0) UCSRB|=1; else UCSRB&=254;
ldi R16,2
ldi R17,0
xcall _delay_nms
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_en_write _LCD_en_write fV
.even
_LCD_en_write::
.dbline -1
.dbline 61
; UDR=*(datas+i); //装载数据开始发送
; while((UCSRA&64)==0); //等待发送结束
; UCSRA|=64; //清除发送结束标志
; i++; //发送次数统计
; }
; max485_in; //使MAX485处于接收状态
; }
.dbline 62
;
sbi 0x15,5
.dbline 63
; //**************************************************************************************
ldi R16,1
ldi R17,0
xcall _delay_nus
.dbline 64
; #pragma interrupt_handler RXC_Int: 12
cbi 0x15,5
.dbline -2
L18:
.dbline 0 ; func end
ret
.dbend
.dbfunc e LCD_write_command _LCD_write_command fV
; command -> R20
.even
_LCD_write_command::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 68
; void RXC_Int(void) //接收中断
; {
; if( UCSRA&28 ){ n=UDR; n=0; UCSRA|=0x01; } else //接收出错就重新打开地址帧筛选功能
; {
.dbline 82
; if( UCSRB&2 ) n=0; //检测到地址信息时计数清零
; inbox[n]=UDR; n++; //把接收到的数据保存到收件箱
; if( inbox[0]==address ) UCSRA&=254; else UCSRA|=0x01; //地址筛选
; if( n==amount ) //如果接收到完整的数据包
; {
; if( inbox[amount-1]==crc8(inbox,amount-1) ) //如果crc8校验正确就...
; {
; send[0]=1; //发件箱地址指向主机
; //send[1]=? //请更新发件箱的数据
; //send[n]=?
; send[amount-1]=crc8(send,amount-1); //产生发件箱的crc8校验码
; usart_out(send,amount); //发送发件箱的数据包/查询方式比较耗时
; OCR1A=inbox[3]; //收件箱测试(控制T/C1的PWM驱动LED)
; }
ldi R16,16
ldi R17,0
xcall _delay_nus
.dbline 83
; }
cbi 0x15,4
.dbline 84
; }
in R24,0x15
andi R24,240
out 0x15,R24
.dbline 85
; }
mov R24,R20
swap R24
andi R24,#0x0F
andi R24,15
in R2,0x15
or R2,R24
out 0x15,R2
.dbline 86
;
xcall _LCD_en_write
.dbline 87
; //**************************************************************************************
in R24,0x15
andi R24,240
out 0x15,R24
.dbline 88
;
mov R24,R20
andi R24,15
in R2,0x15
or R2,R24
out 0x15,R2
.dbline 89
; void main(void)
xcall _LCD_en_write
.dbline -2
L19:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r command 20 c
.dbend
.dbfunc e LCD_write_data _LCD_write_data fV
; data -> R20
.even
_LCD_write_data::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 95
; {
; usart_init();
; LCD_init();
; max485_in;
; max485_RW_ok;
; TCCR1A =0B10000001; //OCR1A/PD5/8位快速PWM
.dbline 109
; TCCR1B =0B00001001; //时钟1分频
; DDRD |=0b00100000; //输出使能
; OCR1A =255; //初始化PWM输出100%占空比
; SEI(); //打开全局中断,需要macros.h支持
; LCD_write_string(0,0,"Send:");
; LCD_write_string(0,1,"Rev:");
;
; while (1)
; {
;
; };
; }
;
;
ldi R16,16
ldi R17,0
xcall _delay_nus
.dbline 110
;
sbi 0x15,4
.dbline 111
;
in R24,0x15
andi R24,240
out 0x15,R24
.dbline 112
;
mov R24,R20
swap R24
andi R24,#0x0F
andi R24,15
in R2,0x15
or R2,R24
out 0x15,R2
.dbline 113
;
xcall _LCD_en_write
.dbline 115
;
;
in R24,0x15
andi R24,240
out 0x15,R24
.dbline 116
;
mov R24,R20
andi R24,15
in R2,0x15
or R2,R24
out 0x15,R2
.dbline 117
;
xcall _LCD_en_write
.dbline -2
L20:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e LCD_set_xy _LCD_set_xy fV
; address -> R20
; y -> R20
; x -> R22
.even
_LCD_set_xy::
xcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 124
;
;
;
;
;
;
;
.dbline 126
;
;
tst R20
brne L22
.dbline 126
mov R20,R22
subi R20,128 ; addi 128
xjmp L23
L22:
.dbline 127
;
mov R20,R22
subi R20,64 ; addi 192
L23:
.dbline 128
;
mov R16,R20
xcall _LCD_write_command
.dbline -2
L21:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r address 20 c
.dbsym r y 20 c
.dbsym r x 22 c
.dbend
.dbfunc e LCD_write_string _LCD_write_string fV
; s -> R20,R21
; Y -> R10
; X -> R22
.even
_LCD_write_string::
xcall push_gset3
mov R10,R18
mov R22,R16
ldd R20,y+6
ldd R21,y+7
.dbline -1
.dbline 132
;
;
;
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -