??? 05/08/08 17:03 Read: times |
#154586 - Ah makes sense..... Responding to: ???'s previous message |
Here is the "hopefully" the final go round, I ran it through and it seems to do a very nice job. Original code size was 912 bytes, now reduced to 726 bytes. I have an ocean of space @ 16KB using the LPC936, but it makes for a more efficient and better coding technique and with the added bonus of learning a bit more.....thanks folks. void RS232_Write(unsigned char reg, unsigned char dat0, unsigned char dat1) { unsigned char REG_H, REG_L, DAT1_H, DAT1_L, DAT2_H, DAT2_L, CHECKSUM_H, CHECKSUM_L, CHECKSUM_T; REG_H = Hex2Ascii(reg >> 4); // do the Upper Nibble REG_L = Hex2Ascii(reg & 0x0F); // do the Lower Nibble DAT1_H = Hex2Ascii(dat0 >> 4); // do the Upper Nibble DAT1_L = Hex2Ascii(dat0 & 0x0F); // do the Lower Nibble DAT2_H = Hex2Ascii(dat1 >> 4); // do the Upper Nibble DAT2_L = Hex2Ascii(dat1 & 0x0F); // do the Lower Nibble CHECKSUM_T = (cam_header + cam_ID_H + cam_ID_L + REG_H + REG_L + DAT1_H + DAT1_L + DAT2_H + DAT2_L); CHECKSUM_H = Hex2Ascii(CHECKSUM_T >> 4); // do the Upper Nibble CHECKSUM_L = Hex2Ascii(CHECKSUM_T & 0x0F); // do the Lower Nibble //*********************************************************************** uart_init(); uart_transmit(cam_header); Wait(2); // header uart_transmit(cam_ID_H); Wait(2); // ID H uart_transmit(cam_ID_L); Wait(2); // ID L uart_transmit(REG_H); Wait(2); // Register H uart_transmit(REG_L); Wait(2); // Register L uart_transmit(DAT1_H); Wait(2); // Data 1 H uart_transmit(DAT1_L); Wait(2); // Data 1 L uart_transmit(DAT2_H); Wait(2); // Data 2 H uart_transmit(DAT2_L); Wait(2); // Data 2 L uart_transmit(CHECKSUM_H); Wait(2); // Send calculated checksum 1 uart_transmit(CHECKSUM_L); Wait(2); // Send calculated checksum 2 //*********************************************************************** } unsigned char Hex2Ascii(unsigned char HexValue) { return "0123456789ABCDEF"[HexValue]; } |