📄 rs485_pc.s
字号:
.module RS485_PC.C
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\LCU904~1\固件程序\RS485_PC.C
.dbfunc e CommandReply _CommandReply fV
.dbstruct 0 260 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 -> R20,R21
; p_buf -> R22,R23
; command -> R16
.even
_CommandReply::
xcall push_xgsetF000
.dbline -1
.dbline 5
;
; #include"include.h"
;
; void CommandReply(unsigned char command)
; {//发送返回值给PC
.dbline 8
; struct StructOfProtocol *p_buf;
; struct data *communication;
; p_buf = (struct StructOfProtocol *)Buffer485;
ldi R22,<_Buffer485
ldi R23,>_Buffer485
.dbline 9
; p_buf->Length = 1;
ldi R24,1
ldi R25,0
movw R30,R22
std z+2,R25
std z+1,R24
.dbline 10
; p_buf->Command = command;
std z+3,R16
.dbline 11
; communication->pc_txd = 1;
movw R30,R20
std z+1,R24
.dbline -2
L2:
.dbline 0 ; func end
xjmp pop_xgsetF000
.dbsym r communication 20 pS[data]
.dbsym r p_buf 22 pS[StructOfProtocol]
.dbsym r command 16 c
.dbend
.area lit(rom, con, rel)
_UnitID::
.byte 'L,'C,'U,57,48,52,48,47,49,32,'V,51,46,48,32,32
.dbsym e UnitID _UnitID A[16:16]kc
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\LCU904~1\固件程序\RS485_PC.C
.dbfunc e GET_NAME _GET_NAME fV
; communication -> R20,R21
; p_buf -> R22,R23
.even
_GET_NAME::
xcall push_xgsetF000
sbiw R28,2
.dbline -1
.dbline 25
; }
; //------------------------------------------------------------------------------
; //------------------------------------------------------------------------------
; /*
; 取控制器名称和版本号
; 命令码: CMD_GET_DCUID
; 数据: NONE
; 回应数据:
; [设备名称] 10 byte(字符串形式)
; [软件版本号] 6 byte(字符串形式)
; */
; flash unsigned char UnitID[16] = { "LCU9040/1 V3.0 " }; /*设备标示代码*/
; void GET_NAME(void)
; {
.dbline 28
; struct StructOfProtocol *p_buf;
; struct data *communication;
; p_buf = (struct StructOfProtocol *)Buffer485;
ldi R22,<_Buffer485
ldi R23,>_Buffer485
.dbline 29
; if(p_buf->Address==Device_Address)
lds R2,_Device_Address
movw R30,R22
ldd R3,z+0
cp R3,R2
brne L4
X0:
.dbline 30
; {
.dbline 31
; if(p_buf->Length==1)
ldd R24,z+1
ldd R25,z+2
cpi R24,1
ldi R26,0
cpc R25,R26
brne L6
X1:
.dbline 32
; {
.dbline 33
; p_buf->Length = sizeof(UnitID) + 1;
ldi R24,17
ldi R25,0
std z+2,R25
std z+1,R24
.dbline 34
; memcpy(p_buf->Data,UnitID,sizeof(UnitID));
ldi R24,16
std y+1,R25
std y+0,R24
ldi R18,<_UnitID
ldi R19,>_UnitID
movw R16,R30
subi R16,252 ; offset = 4
sbci R17,255
xcall _memcpy
.dbline 35
; communication->pc_txd = 1;
ldi R24,1
movw R30,R20
std z+1,R24
.dbline 36
; }
xjmp L7
L6:
.dbline 37
; else if(TEST) CommandReply(RESP_INVALID_DATA);
xjmp L8
L8:
L7:
.dbline 38
; }
L4:
.dbline -2
L3:
.dbline 0 ; func end
adiw R28,2
xjmp pop_xgsetF000
.dbsym r communication 20 pS[data]
.dbsym r p_buf 22 pS[StructOfProtocol]
.dbend
.dbfunc e GET_TIME _GET_TIME fV
; communication -> R16,R17
; p_buf -> R18,R19
.even
_GET_TIME::
.dbline -1
.dbline 51
; }
; //------------------------------------------------------------------------------
; //------------------------------------------------------------------------------
; /*
; 取系统时间
; 命令码:CMD_GET_TIME
; 数据: NONE
; 正常回应数据:
; 日期表示: 2 bytes
; 时间表示: 2 bytes
; */
; void GET_TIME(void)
; {
.dbline 54
; struct StructOfProtocol *p_buf;
; struct data *communication;
; p_buf = (struct StructOfProtocol *)Buffer485;
ldi R18,<_Buffer485
ldi R19,>_Buffer485
.dbline 55
; *C51Buffer485 = *Buffer485;
lds R2,_Buffer485
sts _C51Buffer485,R2
.dbline 56
; if(p_buf->Address == Device_Address)
lds R2,_Device_Address
movw R30,R18
ldd R3,z+0
cp R3,R2
brne L11
X2:
.dbline 57
; {
.dbline 59
;
; if(p_buf->Length==1)
ldd R24,z+1
ldd R25,z+2
cpi R24,1
ldi R30,0
cpc R25,R30
brne L13
X3:
.dbline 60
; {//发送获取时间给51控制板
.dbline 61
; communication->c51_txd = 1;
ldi R24,1
movw R30,R16
std z+3,R24
.dbline 62
; }
xjmp L14
L13:
.dbline 63
; else if(TEST) CommandReply(RESP_INVALID_DATA);
xjmp L15
L15:
L14:
.dbline 64
; }
L11:
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbsym r communication 16 pS[data]
.dbsym r p_buf 18 pS[StructOfProtocol]
.dbend
.dbfunc e SET_TIME _SET_TIME fV
; p_buf -> R20,R21
.even
_SET_TIME::
st -y,R20
st -y,R21
.dbline -1
.dbline 74
; }
; //------------------------------------------------------------------------------
; /*
; 下载系统时间
; 命令码:CMD_SET_TIME
; 数据: 日期2字节,时间2字节
; 正常回应:[OK]
; */
; void SET_TIME(void)
; {
.dbline 76
; struct StructOfProtocol *p_buf;
; p_buf = (struct StructOfProtocol *)Buffer485;
ldi R20,<_Buffer485
ldi R21,>_Buffer485
.dbline 77
; *C51Buffer485 = *Buffer485;
lds R2,_Buffer485
sts _C51Buffer485,R2
.dbline 78
; if(p_buf->Length ==5)
movw R30,R20
ldd R24,z+1
ldd R25,z+2
cpi R24,5
ldi R26,0
cpc R25,R26
brne L18
X4:
.dbline 79
; {//发送设置时间给51控制板
.dbline 80
; DayOfTime = ((unsigned int)p_buf->Data[0] << 8) | p_buf->Data[1];
ldd R2,z+5
ldd R3,z+4
clr R4
sts _DayOfTime+1,R3
sts _DayOfTime,R2
.dbline 81
; SecondOfTime = ((unsigned int)p_buf->Data[2] << 8) | p_buf->Data[3];
ldd R2,z+7
ldd R3,z+6
clr R4
sts _SecondOfTime+1,R3
sts _SecondOfTime,R2
.dbline 82
; if (p_buf->Address != 0xff)
ldd R24,z+0
cpi R24,255
breq L19
X5:
.dbline 83
; {
.dbline 84
; Cyc_manage |= 0x04;//打开更新51控制板的数据
lds R24,_Cyc_manage
ori R24,4
sts _Cyc_manage,R24
.dbline 85
; CommandReply(RESP_CMD_OK);
ldi R16,129
xcall _CommandReply
.dbline 86
; }
.dbline 87
; }
xjmp L19
L18:
.dbline 88
; else if(TEST && p_buf->Address != 0xff)
xjmp L22
L22:
L19:
.dbline -2
L17:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r p_buf 20 pS[StructOfProtocol]
.dbend
.dbfunc e GET_CARDSET _GET_CARDSET fV
; communication -> R20,R21
; count -> R12,R13
; point -> R10,R11
; p_buf -> R22,R23
.even
_GET_CARDSET::
xcall push_xgsetF03C
sbiw R28,1
.dbline -1
.dbline 101
; CommandReply(RESP_INVALID_DATA);
; }
; //------------------------------------------------------------------------------
; //------------------------------------------------------------------------------
; /*
; 取系统卡注册表
; 命令码: CMD_GET_CARDSET
; 数据: NONE
; 正常回应数据:
; 卡注册表数据结构
; */
; void GET_CARDSET(void)
; {
.dbline 105
; unsigned int point,count;
; struct StructOfProtocol *p_buf;
; struct data *communication;
; p_buf = (struct StructOfProtocol *)Buffer485;
ldi R22,<_Buffer485
ldi R23,>_Buffer485
.dbline 106
; if(p_buf->Address==Device_Address)
lds R2,_Device_Address
movw R30,R22
ldd R3,z+0
cp R3,R2
breq X10
xjmp L25
X10:
X6:
.dbline 107
; {
.dbline 108
; if(p_buf->Length==3)
ldd R24,z+1
ldd R25,z+2
cpi R24,3
ldi R26,0
cpc R25,R26
breq X11
xjmp L27
X11:
X7:
.dbline 109
; {
.dbline 110
; point = *(unsigned int *)p_buf->Data;
ldd R10,z+4
ldd R11,z+5
.dbline 111
; if (point < sizeof(struct StructOfRegister))
movw R24,R10
cpi R24,252
ldi R26,5
cpc R25,R26
brlo X12
xjmp L29
X12:
X8:
.dbline 112
; {//发送系统卡注册表给PC
.dbline 113
; count = sizeof(struct StructOfRegister) - point;
ldi R24,1532
ldi R25,5
movw R12,R24
sub R12,R10
sbc R13,R11
.dbline 114
; if (count < 256 - 8) p_buf->Length = count + 1;
movw R24,R12
cpi R24,248
ldi R26,0
cpc R25,R26
brsh L31
X9:
.dbline 114
adiw R24,1
std z+2,R25
std z+1,R24
xjmp L32
L31:
.dbline 115
; else p_buf->Length = 256 - 8;
ldi R24,248
ldi R25,0
movw R30,R22
std z+2,R25
std z+1,R24
L32:
.dbline 116
; point += CARDSET_Address;
movw R24,R10
subi R24,65 ; offset = 38079
sbci R25,107
movw R10,R24
.dbline 117
; I2C_Initial();
xcall _I2C_Initial
.dbline 118
; AT24_Read((unsigned char *)&p_buf->Data,point,p_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 119
; I2C_Close();
xcall _I2C_Close
.dbline 120
; communication->pc_txd = 1;
ldi R24,1
movw R30,R20
std z+1,R24
.dbline 121
; }
xjmp L28
L29:
.dbline 122
; else if(TEST) CommandReply(RESP_INVALID_DATA);
xjmp L28
L27:
.dbline 124
; }
; else if(TEST) CommandReply(RESP_INVALID_DATA);
xjmp L35
L35:
L28:
.dbline 125
; }
L25:
.dbline -2
L24:
.dbline 0 ; func end
adiw R28,1
xjmp pop_xgsetF03C
.dbsym r communication 20 pS[data]
.dbsym r count 12 i
.dbsym r point 10 i
.dbsym r p_buf 22 pS[StructOfProtocol]
.dbend
.dbfunc e SET_CARDSET _SET_CARDSET fV
; count -> R10,R11
; point -> R22,R23
; p_buf -> R20,R21
.even
_SET_CARDSET::
xcall push_xgsetF00C
sbiw R28,1
.dbline -1
.dbline 135
; }
; //------------------------------------------------------------------------------
; /*
; 下载系统卡注册表
; 命令码: CMD_SET_CARDSET
; 数据: 卡注册表
; 正常回应: [OK]
; */
; void SET_CARDSET(void)
; {
.dbline 138
; unsigned int point,count;
; struct StructOfProtocol *p_buf;
; p_buf = (struct StructOfProtocol *)Buffer485;
ldi R20,<_Buffer485
ldi R21,>_Buffer485
.dbline 139
; *C51Buffer485 = *Buffer485;
lds R2,_Buffer485
sts _C51Buffer485,R2
.dbline 140
; point = *(unsigned int *)p_buf->Data;
movw R30,R20
ldd R22,z+4
ldd R23,z+5
.dbline 141
; if (point < sizeof(struct StructOfRegister))
cpi R22,252
ldi R26,5
cpc R23,R26
brlo X17
xjmp L38
X17:
X13:
.dbline 142
; {
.dbline 143
; count = sizeof(struct StructOfRegister) - point;
ldi R24,1532
ldi R25,5
movw R10,R24
sub R10,R22
sbc R11,R23
.dbline 144
; p_buf->Length -= 3;
movw R24,R30
adiw R24,1
movw R30,R24
ldd R24,z+0
ldd R25,z+1
sbiw R24,3
std z+1,R25
std z+0,R24
.dbline 145
; if (p_buf->Length && (p_buf->Length <= count))
movw R30,R20
ldd R2,z+1
ldd R3,z+2
tst R2
brne X14
tst R3
breq L40
X14:
cp R10,R2
cpc R11,R3
brlo L40
X15:
.dbline 146
; {//保存系统卡注册表
.dbline 147
; point += CARDSET_Address;
subi R22,65 ; offset = 38079
sbci R23,107
.dbline 148
; I2C_Initial();
xcall _I2C_Initial
.dbline 149
; AT24_Write((unsigned char *)&p_buf->Data[2],point,p_buf->Length);
movw R30,R20
ldd R2,z+1
ldd R3,z+2
std y+0,R2
movw R18,R22
movw R16,R30
subi R16,250 ; offset = 6
sbci R17,255
xcall _AT24_Write
.dbline 150
; I2C_Close();
xcall _I2C_Close
.dbline 151
; if (p_buf->Address != 0xff)
movw R30,R20
ldd R24,z+0
cpi R24,255
breq L39
X16:
.dbline 152
; {
.dbline 153
; Cyc_manage |= 0x04;//打开更新51控制板的数据
lds R24,_Cyc_manage
ori R24,4
sts _Cyc_manage,R24
.dbline 154
; CommandReply(RESP_CMD_OK);
ldi R16,129
xcall _CommandReply
.dbline 155
; }
.dbline 156
; }
xjmp L39
L40:
.dbline 157
; else if(TEST && p_buf->Address != 0xff)
xjmp L39
L38:
.dbline 160
; CommandReply(RESP_INVALID_DATA);
; }
; else if(TEST && p_buf->Address != 0xff)
xjmp L46
L46:
L39:
.dbline -2
L37:
.dbline 0 ; func end
adiw R28,1
xjmp pop_xgsetF00C
.dbsym r count 10 i
.dbsym r point 22 i
.dbsym r p_buf 20 pS[StructOfProtocol]
.dbend
.dbfunc e GET_USER _GET_USER fV
; communication -> R20,R21
; count -> R12,R13
; point -> R10,R11
; p_buf -> R22,R23
.even
_GET_USER::
xcall push_xgsetF03C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -