📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile E:\atmega16子函数\TWI_master\main.c
.dbfunc e Start _Start fV
.even
_Start::
.dbline -1
.dbline 20
; #include"iom16v.h"
; #include <iom16v.h>
; #include<macros.h>
; #include"UART.h"
; #include"DELAY.h"
;
; #define uchar unsigned char
; #define STATUS (TWSR&0xf8)
; #define SLA_W 0x32
; #define SLA_R 0x33
; #define SLAVER_ADDRESS 0x32
; #define START 0x08
; #define RE_START 0x10
; #define MT_SLA_WRITE_ACK 0x18
; #define MT_SLA_READ_ACK 0x40
; #define MT_DATA_ACK 0x28
; #define MT_READ_ACK 0x58
;
; void Start(void)
; {
.dbline 21
; TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
ldi R24,164
out 0x36,R24
L2:
.dbline 22
L3:
.dbline 22
; while(!(TWCR&(1<<TWINT)));
in R2,0x36
sbrs R2,7
rjmp L2
.dbline -2
.dbline 23
; }
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Stop _Stop fV
.even
_Stop::
.dbline -1
.dbline 25
; void Stop(void)
; {
.dbline 26
; TWCR=(1<<TWINT)|(1<<TWSTO)|(1<<TWEN);
ldi R24,148
out 0x36,R24
.dbline -2
.dbline 27
; }
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Load _Load fV
; i -> R16
.even
_Load::
.dbline -1
.dbline 29
; void Load(uchar i)
; {
.dbline 30
; TWDR=i;
out 0x3,R16
.dbline 31
; TWCR=(1<<TWINT)|(1<<TWEN);
ldi R24,132
out 0x36,R24
L7:
.dbline 32
L8:
.dbline 32
; while(!(TWCR&(1<<TWINT)));
in R2,0x36
sbrs R2,7
rjmp L7
.dbline -2
.dbline 34
;
; }
L6:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.dbfunc e Get _Get fV
; d -> R16,R17
.even
_Get::
.dbline -1
.dbline 37
;
; void Get(unsigned char *d)
; {
.dbline 38
; TWCR=(1<<TWINT)|(1<<TWEN);
ldi R24,132
out 0x36,R24
L11:
.dbline 39
L12:
.dbline 39
; while(!(TWCR&(1<<TWINT)));
in R2,0x36
sbrs R2,7
rjmp L11
.dbline 40
; *d= TWDR;
in R2,0x3
movw R30,R16
std z+0,R2
.dbline -2
.dbline 41
; }
L10:
.dbline 0 ; func end
ret
.dbsym r d 16 pc
.dbend
.dbfunc e ERROR _ERROR fV
; state -> R20
.even
_ERROR::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 43
; void ERROR(uchar state)
; {Stop();
.dbline 43
rcall _Stop
.dbline -2
.dbline 44
; }
L14:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r state 20 c
.dbend
.dbfunc e SendByte _SendByte fc
; data -> R20
.even
_SendByte::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 49
;
; /*写一个字节data,成功则返回1,否则
; 返回0*/
; uchar SendByte(uchar data)
; {
.dbline 51
; //启动I2C
; Start();
rcall _Start
.dbline 52
; if(STATUS!=START) //{ERROR(STATUS);return 0;}
in R24,0x1
andi R24,248
cpi R24,8
breq L16
.dbline 53
; puts("Start ERRor");
ldi R16,<L18
ldi R17,>L18
rcall _puts
L16:
.dbline 55
; //发送从机地址(写),等待回应, 错误检测
; Load(0);
clr R16
rcall _Load
.dbline 56
; if(STATUS!=MT_SLA_WRITE_ACK) //{ERROR(STATUS);return 0;}
in R24,0x1
andi R24,248
cpi R24,24
breq L19
.dbline 57
; puts("SLA_W RROR");
ldi R16,<L21
ldi R17,>L21
rcall _puts
L19:
.dbline 64
; /*
; //发送EEPROM地址,等待回应,错误检测
; Load(addr);
; if(STATUS!=MT_DATA_ACK) {ERROR(STATUS);return 0;}
; */
; //发送数据,等待回应,错误检测
; Load(data);
mov R16,R20
rcall _Load
.dbline 65
; if(STATUS!=MT_DATA_ACK) //{ERROR(STATUS);return 0;}
in R24,0x1
andi R24,248
cpi R24,40
breq L22
.dbline 66
; puts("Date Error");
ldi R16,<L24
ldi R17,>L24
rcall _puts
L22:
.dbline 67
; Stop();
rcall _Stop
.dbline 68
; return 1;//发送成功,返回1;
ldi R16,1
.dbline -2
L15:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e Init_Io _Init_Io fV
.even
_Init_Io::
.dbline -1
.dbline 73
;
; }
;
; void Init_Io(void)
; {
.dbline 74
; DDRC&=~((1<<PC0)&(1<<PC1)&(1<<PC2));
in R24,0x14
andi R24,255
out 0x14,R24
.dbline 75
; PORTC|= (1<<PC0)|(1<<PC1)|(1<<PC2);
in R24,0x15
ori R24,7
out 0x15,R24
.dbline 76
; TWCR=(1<<TWEA)|(1<<TWEN); //主机模式,使能TWI
ldi R24,68
out 0x36,R24
.dbline 77
; TWBR=32;//波特率 100K 8M晶振
ldi R24,32
out 0x0,R24
.dbline -2
.dbline 78
; }
L25:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
; temp -> <dead>
.even
_main::
.dbline -1
.dbline 80
; void main()
; {
.dbline 82
; uchar temp;
; Init_Io();
rcall _Init_Io
.dbline 83
; uart_init();
rcall _uart_init
.dbline 85
; // puts("串口工作");
; SendByte(0x30);
ldi R16,48
rcall _SendByte
L27:
.dbline 87
.dbline 88
.dbline 89
L28:
.dbline 86
rjmp L27
X0:
.dbline -2
.dbline 96
; while(1)
; {
; ;
; }
; /*for(temp=0;temp<10;temp++)
; {
; SendByte(temp+0x30);
; Delay_nms(10);
; }
; */
; }
L26:
.dbline 0 ; func end
ret
.dbsym l temp 1 c
.dbend
.area data(ram, con, rel)
.dbfile E:\atmega16子函数\TWI_master\main.c
L24:
.blkb 11
.area idata
.byte 'D,'a,'t,'e,32,'E,'r,'r,'o,'r,0
.area data(ram, con, rel)
.dbfile E:\atmega16子函数\TWI_master\main.c
L21:
.blkb 11
.area idata
.byte 'S,'L,'A,95,'W,32,'R,'R,'O,'R,0
.area data(ram, con, rel)
.dbfile E:\atmega16子函数\TWI_master\main.c
L18:
.blkb 12
.area idata
.byte 'S,'t,'a,'r,'t,32,'E,'R,'R,'o,'r,0
.area data(ram, con, rel)
.dbfile E:\atmega16子函数\TWI_master\main.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -