??? 09/07/06 23:26 Read: times |
#123889 - update code (working) and clarification Responding to: ???'s previous message |
Well I attempted to re-structure my code, I think this is more readable and easier to make data specific changes to if nothing else. As you can see, the variable Checksum is unsigned char volatile. I don't know why this has to be so, but it won't work otherwise. There should be nothing else in the program that would affect it. This routine also takes place within an ISR, (the only only one in the whole program), so I don't know if that makes a difference?
Anyway, Thanks to those who posted to help me. A month ago I didn't really know what an 8051 or "C" was, so I've got a lot of learning yet to do. But I'm getting there, and this site has been a big help so far. Here's the code as it sits now, which seems to work well. void ZW_SendButton (void){ unsigned char volatile Checksum ; char BasicSetFrame[10]; //LEN, TYPE, CMD, NODE, COMMLEN, COMMCLASS, COMM, LASTKEY, TXOPT, FUNCID int pos; //position within array char Length = 0xA; //Length of frame, excluding SOF and Checksum BasicSetFrame[0] = Length; BasicSetFrame[1] = 0x00; //TYPE BasicSetFrame[2] = 0x13; //CMD SendData BasicSetFrame[3] = IconNodeID; //NODE (Target Node) BasicSetFrame[4] = 0x03; //CommLen (Length of data specific payload within Frame) BasicSetFrame[5] = 0x20; //CommClass Basic BasicSetFrame[6] = 0x01; //Basic Set BasicSetFrame[7] = LastKey; // Decoded Button Press/Release BasicSetFrame[8] = 0x05; //TXOpt BasicSetFrame[9] = 0x00; //FUNCID Checksum = 0xFF; //-Initialize checksum while (!TI0); TI0 = 0; SBUF0 = SOF; //send Start Of Frame for (pos = 0; pos < Length; pos++){ while (!TI0); TI0 = 0; SBUF0 = BasicSetFrame[pos]; Checksum ^= BasicSetFrame[pos]; } while (!TI0); TI0 = 0; SBUF0 = Checksum; } |
Topic | Author | Date |
^= , Checksum, Problem | 01/01/70 00:00 | |
Have you tried a simulator? | 01/01/70 00:00 | |
well, | 01/01/70 00:00 | |
OK | 01/01/70 00:00 | |
volatile? | 01/01/70 00:00 | |
volatile | 01/01/70 00:00 | |
using ICE ? | 01/01/70 00:00 | |
update code (working) and clarification | 01/01/70 00:00 | |
Style | 01/01/70 00:00 | |
Think about your variable types | 01/01/70 00:00 | |
Thanks | 01/01/70 00:00 | |
Magic numbers | 01/01/70 00:00 | |
but don't be "oversmart" | 01/01/70 00:00 | |
example? | 01/01/70 00:00 | |
advantages | 01/01/70 00:00 | |
the most often forgotten quality guarantee![]() | 01/01/70 00:00 | |
so, use structures! | 01/01/70 00:00 | |
padding | 01/01/70 00:00 | |
| 01/01/70 00:00 | |
Actual Output | 01/01/70 00:00 | |
C99 | 01/01/70 00:00 | |
making up your own | 01/01/70 00:00 | |
Names | 01/01/70 00:00 | |
FYI - C99 Exact- & Minimum-width types | 01/01/70 00:00 |