hi,
This is a tipical K***l bug.
Is a simple bit swap routine for a remote keyboard wit some led.
The routine must swap bit 4 and 5.
This is not dependent by optimizing level. I tryed also with volatile declaration without solution.
If someone Know how to solve in a better way is welcome !!!
// ------------------------------------
// Shared flags
// ------------------------------------
volatile unsigned char bdata bTmp4Swap;
sbit fTmp4SwapBit0 = bTmp4Swap^0;
sbit fTmp4SwapBit1 = bTmp4Swap^1;
sbit fTmp4SwapBit2 = bTmp4Swap^2;
sbit fTmp4SwapBit3 = bTmp4Swap^3;
sbit fTmp4SwapBit4 = bTmp4Swap^4;
sbit fTmp4SwapBit5 = bTmp4Swap^5;
sbit fTmp4SwapBit6 = bTmp4Swap^6;
sbit fTmp4SwapBit7 = bTmp4Swap^7;
// -------------------------------
/*-------------------------------------------------------------------------*/
CASE 1 Bugged routine
/*-------------------------------------------------------------------------*/
void RxLedStatus(void) // Msg from R5P to R5L
{
bit fTmp;
bTmp4Swap = I2cPack.bDati[0]; // Received data (unsigned char)
fTmp = fTmp4SwapBit4; // Save LedWash
fTmp4SwapBit4 = fTmp4SwapBit5; // Move LedZero in pos. 4
fTmp4SwapBit5 = fTmp; // Restore LedWash in pos. 5
bLocalLeds = bTmp4Swap; // Update Local Leds
UpdateTBLeds(); // Refresh TB Leds
}
/* ASM LISTING
; FUNCTION RxLedStatus (BEGIN)
; SOURCE LINE # 167
0000 7800 E MOV R0,#LOW I2cPack+04H
0002 E6 MOV A,@R0
0003 F500 E MOV bTmp4Swap,A
; SOURCE LINE # 168
0005 A200 E MOV C,fTmp4SwapBit4
0007 9200 R MOV fTmp,C
; SOURCE LINE # 169
0009 A200 E MOV C,fTmp4SwapBit5
000B 9200 E MOV fTmp4SwapBit4,C
; SOURCE LINE # 170
000D A200 R MOV C,fTmp
000F 9200 E MOV fTmp4SwapBit5,C
; SOURCE LINE # 172
0011 F500 E MOV bLocalLeds,A
; SOURCE LINE # 174
0013 020000 E LJMP UpdateBodyTBLeds
; FUNCTION RxLedStatus (END)
*/
/*-------------------------------------------------------------------------*/
CASE 2 Patched routine
/*-------------------------------------------------------------------------*/
void RxLedStatus(void) // Msg from R5P to R5L
{
bit fTmp;
bTmp4Swap = I2cPack.bDati[0]; // Received data (unsigned char)
fTmp = fTmp4SwapBit4; // Save LedWash
fTmp4SwapBit4 = fTmp4SwapBit5; // Move LedZero in pos. 4
fTmp4SwapBit5 = fTmp; // Restore LedWash in pos. 5
ACC = 0; // REQUIRED BY COMPILER BUG !!!!!!!
bLocalLeds = bTmp4Swap; // Update Local Leds
UpdateTBLeds(); // Refresh TB Leds
}
/*
; FUNCTION RxLedStatus (BEGIN)
; SOURCE LINE # 167
0000 7800 E MOV R0,#LOW I2cPack+04H
0002 E6 MOV A,@R0
0003 F500 E MOV bTmp4Swap,A
; SOURCE LINE # 168
0005 A200 E MOV C,fTmp4SwapBit4
0007 9200 R MOV fTmp,C
; SOURCE LINE # 169
0009 A200 E MOV C,fTmp4SwapBit5
000B 9200 E MOV fTmp4SwapBit4,C
; SOURCE LINE # 170
000D A200 R MOV C,fTmp
000F 9200 E MOV fTmp4SwapBit5,C
; SOURCE LINE # 172
0011 E4 CLR A
; SOURCE LINE # 174
0012 850000 E MOV bLocalLeds,bTmp4Swap
; SOURCE LINE # 175
0015 120000 E LCALL UpdateTBLeds
; SOURCE LINE # 176
0018 22 RET
; FUNCTION RxLedStatus (END)
*/