FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
PCD coding errors |
Posted: Mon Sep 29, 2008 11:54 am |
|
|
Hello,
I ported ex_modbus_slave.c to PIC24F and experienced a coding error, that causes failure of the respective operation (resulting in all zero output data in Coil and Input read). The erroneous behaviour can be easily seen in PCD assembly listing:
Code: | data = data & (0xFF>>(8-modbus_rx.data[3])); //0 out values after quantity
02422: MOV #8,W4
02424: MOV 8E8,W3 ; data
02426: LSR W3,#8,W3
02428: SUB.B W4L,W3L,W0L ; substract result to W0L
; here's the bug
0242A: MOV #FF,W0 ; mask also loaded to R0
0242C: CLR.B 1
0242E: LSR W0,W0,W0
02430: AND.B 950 |
Most likely, the error can be removed by rearranging the code. But iit's a serious problem, when any line of code must be suspected to be coded incorrect.
I experienced a similar problem one day before when porting some Microchip code (AN1095, Emulation of Data EEPROM in code memory). In this case, a wrong WREG address has been used at addr 018DA.
Code: | 742: if(latch != (data & 0xFF))
018D2 804800 mov.w 0x0900,0x0000 ; int16 data
018D4 B20FF0 and.w #0xff,0x0000
018D6 804864 mov.w 0x090c,0x0008 ; int8 latch
018D8 EF6009 clr.b 0x0009
018DA E30004 cp.w 0x0004 ; must be cp.w 0x0008 !!
018DC 320006 bra z, 0x0018ea |
Both cases are related to int8 variables. The compiler version is V4.079.
Best regards,
Frank |
|