📄 rs485_51device.s
字号:
.module RS485_51Device.c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\LCU904~1\固件程序\RS485_51Device.c
.dbfunc e get_Device51_TIME _get_Device51_TIME fV
.dbstruct 0 260 Device51_StructOfProtocol
.dbfield 0 Address c
.dbfield 1 Length i
.dbfield 3 Command c
.dbfield 4 Data A[256:256]c
.dbend
.dbstruct 0 4 data
.dbfield 0 pc_rxd c
.dbfield 1 pc_txd c
.dbfield 2 c51_rxd c
.dbfield 3 c51_txd c
.dbend
; communication -> R16,R17
; C51_buf -> R18,R19
.even
_get_Device51_TIME::
.dbline -1
.dbline 7
;
; #include"include.h"
;
; //------------------------------------------------------------------------------
; //获取51板的时间
; void get_Device51_TIME(void)
; {
.dbline 10
; struct Device51_StructOfProtocol *C51_buf;
; struct data *communication;
; *Buffer485 = *C51Buffer485;
lds R2,_C51Buffer485
sts _Buffer485,R2
.dbline 11
; C51_buf = (struct Device51_StructOfProtocol *)C51Buffer485;
ldi R18,<_C51Buffer485
ldi R19,>_C51Buffer485
.dbline 12
; if(C51_buf->Length ==5)
movw R30,R18
ldd R24,z+1
ldd R25,z+2
cpi R24,5
ldi R26,0
cpc R25,R26
brne L3
X0:
.dbline 13
; {//发送时间给PC
.dbline 14
; DayOfTime = ((unsigned int)C51_buf->Data[0] << 8) | C51_buf->Data[1];
ldd R2,z+5
ldd R3,z+4
clr R4
sts _DayOfTime+1,R3
sts _DayOfTime,R2
.dbline 15
; SecondOfTime = ((unsigned int)C51_buf->Data[2] << 8) | C51_buf->Data[3];
ldd R2,z+7
ldd R3,z+6
clr R4
sts _SecondOfTime+1,R3
sts _SecondOfTime,R2
.dbline 16
; communication->pc_txd = 1;
ldi R24,1
movw R30,R16
std z+1,R24
.dbline 17
; Cyc_manage |= 0x01;
lds R24,_Cyc_manage
ori R24,1
sts _Cyc_manage,R24
.dbline 18
; }
L3:
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym r communication 16 pS[data]
.dbsym r C51_buf 18 pS[Device51_StructOfProtocol]
.dbend
.dbfunc e get_Device51_EVENT _get_Device51_EVENT fV
.even
_get_Device51_EVENT::
.dbline -1
.dbline 23
; }
; //------------------------------------------------------------------------------
; //取控制器历史事件
; void get_Device51_EVENT(void)
; {
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e communication_with_51director _communication_with_51director fV
.dbstruct 0 256 Device51_Address
.dbfield 0 Address A[256:256]c
.dbend
; communication -> R12,R13
; Device51 -> R10,R11
; C51_buf -> R22,R23
; i -> R20
.even
_communication_with_51director::
xcall push_xgsetF03C
.dbline -1
.dbline 33
;
;
;
;
; }
; //------------------------------------------------------------------------------
; //------------------------------------------------------------------------------
; //与51控制板进行通讯
; void communication_with_51director(void)
; {
.dbline 38
; unsigned char i;
; struct Device51_StructOfProtocol *C51_buf;
; struct Device51_Address *Device51;
; struct data *communication;
; C51_buf = (struct Device51_StructOfProtocol *)C51Buffer485;
ldi R22,<_C51Buffer485
ldi R23,>_C51Buffer485
.dbline 39
; if(communication->c51_txd)
movw R30,R12
ldd R2,z+3
tst R2
breq L7
X1:
.dbline 40
; {//发送数据给51控制板
.dbline 41
; communication->c51_txd = 0;
clr R2
std z+3,R2
.dbline 42
; for(i=0;i<sizeof(struct ReadHC165Switch);i++)
clr R20
xjmp L12
L9:
.dbline 43
; {
.dbline 44
; C51_buf->Address = Device51->Address[i];
mov R30,R20
clr R31
add R30,R10
adc R31,R11
ldd R2,z+0
movw R30,R22
std z+0,R2
.dbline 45
; BUS_SendPacket_51Device();//发送数据给51板
xcall _BUS_SendPacket_51Device
.dbline 46
; }
L10:
.dbline 42
inc R20
L12:
.dbline 42
cpi R20,3
brlo L9
X2:
.dbline 47
; }
L7:
.dbline 48
; if(communication->c51_rxd)
movw R30,R12
ldd R2,z+2
tst R2
brne X11
xjmp L13
X11:
X3:
.dbline 49
; {//接收51控制板发送过来的数据
.dbline 50
; communication->c51_rxd = 0;
clr R2
std z+2,R2
.dbline 51
; if(!BUS_GetPacket_51Device())
xcall _BUS_GetPacket_51Device
tst R16
brne L15
X4:
.dbline 52
; {
.dbline 53
; for(i=0;i<sizeof(struct ReadHC165Switch);i++)
clr R20
xjmp L20
L17:
.dbline 54
; {
.dbline 55
; if((C51_buf->Address==Device51->Address[i])||(C51_buf->Address == 0xff))
movw R30,R22
ldd R2,z+0
clr R3
movw R4,R2
mov R30,R20
clr R31
add R30,R10
adc R31,R11
ldd R2,z+0
cp R4,R2
breq L23
X5:
mov R24,R4
cpi R24,255
brne L21
X6:
L23:
.dbline 56
; {
.dbline 57
; switch(C51_buf->Command)
movw R30,R22
ldd R12,z+3
clr R13
movw R24,R12
cpi R24,2
ldi R30,0
cpc R25,R30
breq L27
X7:
cpi R24,2
ldi R30,0
cpc R25,R30
brlt L25
X8:
L29:
movw R24,R12
cpi R24,17
ldi R30,0
cpc R25,R30
breq L28
X9:
xjmp L25
L27:
.dbline 60
; {
; case CMD_GET_TIME://获取C51控制板的时间
; get_Device51_TIME();
xcall _get_Device51_TIME
.dbline 61
; break;
xjmp L25
L28:
.dbline 63
; case CMD_GET_EVENT://取控制器历史事件
; get_Device51_EVENT();
xcall _get_Device51_EVENT
.dbline 64
; break;
.dbline 66
; default:
; break;
L25:
.dbline 68
; }
; }
L21:
.dbline 69
; }
L18:
.dbline 53
inc R20
L20:
.dbline 53
cpi R20,3
brlo L17
X10:
.dbline 70
; }
L15:
.dbline 71
; }
L13:
.dbline -2
L6:
.dbline 0 ; func end
xjmp pop_xgsetF03C
.dbsym r communication 12 pS[data]
.dbsym r Device51 10 pS[Device51_Address]
.dbsym r C51_buf 22 pS[Device51_StructOfProtocol]
.dbsym r i 20 c
.dbend
.dbfunc e set_Device51_TIME _set_Device51_TIME fV
; communication -> R16,R17
; C51_buf -> R18,R19
.even
_set_Device51_TIME::
.dbline -1
.dbline 78
; }
; //------------------------------------------------------------------------------
; //******************************************************************************
; //------------------------------------------------------------------------------
; //下载系统时间
; void set_Device51_TIME(void)
; {
.dbline 81
; struct Device51_StructOfProtocol *C51_buf;
; struct data *communication;
; C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
ldi R18,<_C51Buffer485
ldi R19,>_C51Buffer485
.dbline 82
; C51_buf->Data[0] = DayOfTime >> 8;
lds R2,_DayOfTime
lds R3,_DayOfTime+1
mov R2,R3
clr R3
movw R30,R18
std z+4,R2
.dbline 83
; C51_buf->Data[1] = DayOfTime;
lds R2,_DayOfTime
lds R3,_DayOfTime+1
std z+5,R2
.dbline 84
; C51_buf->Data[2] = SecondOfTime >> 8;
lds R2,_SecondOfTime
lds R3,_SecondOfTime+1
mov R2,R3
clr R3
std z+6,R2
.dbline 85
; C51_buf->Data[3] = SecondOfTime;
lds R2,_SecondOfTime
lds R3,_SecondOfTime+1
std z+7,R2
.dbline 86
; C51_buf->Length = 5;
ldi R24,5
ldi R25,0
std z+2,R25
std z+1,R24
.dbline 87
; communication->c51_txd = 1;
ldi R24,1
movw R30,R16
std z+3,R24
.dbline 88
; Cyc_manage |= 0x02;
lds R24,_Cyc_manage
ori R24,2
sts _Cyc_manage,R24
.dbline -2
L30:
.dbline 0 ; func end
ret
.dbsym r communication 16 pS[data]
.dbsym r C51_buf 18 pS[Device51_StructOfProtocol]
.dbend
.dbfunc e set_Device51_CARDSET _set_Device51_CARDSET fV
; communication -> R20,R21
; count -> R12,R13
; C51_buf -> R22,R23
; point -> R10,R11
.even
_set_Device51_CARDSET::
xcall push_xgsetF03C
sbiw R28,1
.dbline -1
.dbline 93
; }
; //------------------------------------------------------------------------------
; //下载系统卡注册表
; void set_Device51_CARDSET(void)
; {
.dbline 97
; unsigned int point,count;
; struct Device51_StructOfProtocol *C51_buf;
; struct data *communication;
; C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
ldi R22,<_C51Buffer485
ldi R23,>_C51Buffer485
.dbline 98
; point = *(unsigned int *)C51_buf->Data;
movw R30,R22
ldd R10,z+4
ldd R11,z+5
.dbline 99
; if (point < sizeof(struct StructOfRegister))
movw R24,R10
cpi R24,252
ldi R26,5
cpc R25,R26
brlo X14
xjmp L32
X14:
X12:
.dbline 100
; {//发送系统卡注册表给51控制板
.dbline 101
; count = sizeof(struct StructOfRegister) - point;
ldi R24,1532
ldi R25,5
movw R12,R24
sub R12,R10
sbc R13,R11
.dbline 102
; if (count < 256 - 8) C51_buf->Length = count + 1;
movw R24,R12
cpi R24,248
ldi R26,0
cpc R25,R26
brsh L34
X13:
.dbline 102
adiw R24,1
std z+2,R25
std z+1,R24
xjmp L35
L34:
.dbline 103
; else C51_buf->Length = 256 - 8;
ldi R24,248
ldi R25,0
movw R30,R22
std z+2,R25
std z+1,R24
L35:
.dbline 104
; point += CARDSET_Address;
movw R24,R10
subi R24,65 ; offset = 38079
sbci R25,107
movw R10,R24
.dbline 105
; I2C_Initial();
xcall _I2C_Initial
.dbline 106
; AT24_Read((unsigned char *)&C51_buf->Data,point,C51_buf->Length-1);
movw R30,R22
ldd R24,z+1
ldd R25,z+2
sbiw R24,1
std y+0,R24
movw R18,R10
movw R16,R30
subi R16,252 ; offset = 4
sbci R17,255
xcall _AT24_Read
.dbline 107
; I2C_Close();
xcall _I2C_Close
.dbline 108
; communication->c51_txd = 1;
ldi R24,1
movw R30,R20
std z+3,R24
.dbline 109
; Cyc_manage |= 0x02;
lds R24,_Cyc_manage
ori R24,2
sts _Cyc_manage,R24
.dbline 110
; }
L32:
.dbline -2
L31:
.dbline 0 ; func end
adiw R28,1
xjmp pop_xgsetF03C
.dbsym r communication 20 pS[data]
.dbsym r count 12 i
.dbsym r C51_buf 22 pS[Device51_StructOfProtocol]
.dbsym r point 10 i
.dbend
.dbfunc e set_Device51_USER _set_Device51_USER fV
; communication -> R20,R21
; count -> R12,R13
; C51_buf -> R22,R23
; point -> R10,R11
.even
_set_Device51_USER::
xcall push_xgsetF03C
sbiw R28,1
.dbline -1
.dbline 115
; }
; //------------------------------------------------------------------------------
; //下载门禁时间组(设用户楼层授权资料)
; void set_Device51_USER(void)
; {
.dbline 119
; unsigned int point,count;
; struct Device51_StructOfProtocol *C51_buf;
; struct data *communication;
; C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
ldi R22,<_C51Buffer485
ldi R23,>_C51Buffer485
.dbline 120
; point = *(unsigned int *)C51_buf->Data;
movw R30,R22
ldd R10,z+4
ldd R11,z+5
.dbline 121
; if (point < sizeof(struct StructOfUserInformation))
movw R24,R10
cpi R24,48
ldi R26,117
cpc R25,R26
brlo X17
xjmp L37
X17:
X15:
.dbline 122
; {//发送用户楼层授权资料给51控制板
.dbline 123
; count = sizeof(struct StructOfUserInformation) - point;
ldi R24,30000
ldi R25,117
movw R12,R24
sub R12,R10
sbc R13,R11
.dbline 124
; if (count < 256 - 8) C51_buf->Length = count + 1;
movw R24,R12
cpi R24,248
ldi R26,0
cpc R25,R26
brsh L39
X16:
.dbline 124
adiw R24,1
std z+2,R25
std z+1,R24
xjmp L40
L39:
.dbline 125
; else C51_buf->Length = 256 - 8;
ldi R24,248
ldi R25,0
movw R30,R22
std z+2,R25
std z+1,R24
L40:
.dbline 126
; point += USER_INFORMATION_Address;
movw R24,R10
subi R24,115 ; offset = 8077
sbci R25,224
movw R10,R24
.dbline 127
; I2C_Initial();
xcall _I2C_Initial
.dbline 128
; AT24_Read((unsigned char *)&C51_buf->Data,point,C51_buf->Length-1);
movw R30,R22
ldd R24,z+1
ldd R25,z+2
sbiw R24,1
std y+0,R24
movw R18,R10
movw R16,R30
subi R16,252 ; offset = 4
sbci R17,255
xcall _AT24_Read
.dbline 129
; I2C_Close();
xcall _I2C_Close
.dbline 130
; communication->c51_txd = 1;
ldi R24,1
movw R30,R20
std z+3,R24
.dbline 131
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -