Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/08/08 03:36
Read: times


 
#154559 - the final result:
Responding to: ???'s previous message
Will do a final test in hardware tomorrow since it is 11:30PM.....LOL

Keil simulation shows that its 100% functional, basically I have an address, and two data bytes for command control. It is then framed and sent via RS232 to the slave device.

Very interesting problem, and I really enjoyed working through it.....(everyday stuff)

I was thinking of submitting the lookup function to the code library since it seems there is nothing out there than can take a byte, break it in half, convert it to ASCII and send it serially without using SPRINTF() functions. Would it be worth it?

Either way I'm happy and here are the final results, once again, thank you to everyone.....:)....:
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, HexValue ;

REG_H  = (reg  & 0xF0);   // Mask the Upper Nibble
HexValue = REG_H;
HexValue = Hex2Ascii(HexValue);
REG_H = HexValue;

REG_L  = (reg  & 0x0F );  // Mask the Lower Nibble
HexValue = REG_L;
HexValue = Hex2Ascii(HexValue);
REG_L = HexValue;

DAT1_H = (dat0 & 0xF0 );  // Mask the Upper Nibble
HexValue = DAT1_H;
HexValue = Hex2Ascii(HexValue);
DAT1_H = HexValue;

DAT1_L = (dat0 & 0x0F );  // Mask the Lower Nibble
HexValue = DAT1_L;
HexValue = Hex2Ascii(HexValue);
DAT1_L = HexValue;

DAT2_H = (dat1 & 0xF0 );  // Mask the Upper Nibble
HexValue = DAT2_H;
HexValue = Hex2Ascii(HexValue);
DAT2_H = HexValue;

DAT2_L = (dat1 & 0x0F );  // Mask the Lower Nibble
HexValue = DAT2_L;
HexValue = Hex2Ascii(HexValue);
DAT2_L = HexValue;

CHECKSUM_T = (cam_header + cam_ID_H + cam_ID_L + REG_H + REG_L + DAT1_H + 
			 DAT1_L + DAT2_H + DAT2_L);

CHECKSUM_H = (CHECKSUM_T & 0xF0 );
HexValue = CHECKSUM_H;
HexValue = Hex2Ascii(HexValue);
CHECKSUM_H = HexValue;

CHECKSUM_L = (CHECKSUM_T & 0x0F );
HexValue = CHECKSUM_L;
HexValue = Hex2Ascii(HexValue);
CHECKSUM_L = HexValue;

//***********************************************************************
uart_init();
uart_transmit(cam_header); 	// Header
uart_transmit(cam_ID_H); 	// ID H
uart_transmit(cam_ID_L); 	// ID L
uart_transmit(REG_H); 		// Register H
uart_transmit(REG_L); 		// Register L
uart_transmit(DAT1_H); 		// Data 1 H
uart_transmit(DAT1_L); 		// Data 1 L
uart_transmit(DAT2_H); 		// Data 2 H
uart_transmit(DAT2_L); 		// Data 2 L
uart_transmit(CHECKSUM_H); 	// Send calculated checksum 1
uart_transmit(CHECKSUM_L); 	// Send calculated checksum 2
//***********************************************************************
}

unsigned char Hex2Ascii(unsigned char HexValue)
{
   switch (HexValue)
   {
    case 0x00: return (HexValue + 0x30); break; // ASCII 0 0x30
    case 0x01: return (HexValue + 0x30); break; // ASCII 1 0x31
    case 0x02: return (HexValue + 0x30); break; // ASCII 2 0x32
    case 0x03: return (HexValue + 0x30); break; // ASCII 3 0x33
    case 0x04: return (HexValue + 0x30); break; // ASCII 4 0x34
    case 0x05: return (HexValue + 0x30); break; // ASCII 5 0x35
    case 0x06: return (HexValue + 0x30); break; // ASCII 6 0x36
    case 0x07: return (HexValue + 0x30); break; // ASCII 7 0x37
    case 0x08: return (HexValue + 0x30); break; // ASCII 8 0x38
    case 0x09: return (HexValue + 0x30); break; // ASCII 9 0x39
    case 0x0A: return (HexValue + 0x37); break; // ASCII A 0x41
    case 0x0B: return (HexValue + 0x37); break; // ASCII B 0x42
    case 0x0C: return (HexValue + 0x37); break; // ASCII C 0x43
    case 0x0D: return (HexValue + 0x37); break; // ASCII D 0x44
    case 0x0E: return (HexValue + 0x37); break; // ASCII E 0x45
    case 0x0F: return (HexValue + 0x37); break; // ASCII F 0x46
//*********************************************
    case 0x10: return (HexValue + 0x21); break; // ASCII 1 0x31
    case 0x20: return (HexValue + 0x12); break; // ASCII 2 0x32
    case 0x30: return (HexValue + 0x03); break; // ASCII 3 0x33
    case 0x40: return (HexValue - 0x0C); break; // ASCII 4 0x34
    case 0x50: return (HexValue - 0x1B); break; // ASCII 5 0x35
    case 0x60: return (HexValue - 0x2A); break; // ASCII 6 0x36
    case 0x70: return (HexValue - 0x39); break; // ASCII 7 0x37
    case 0x80: return (HexValue - 0x48); break; // ASCII 8 0x38
    case 0x90: return (HexValue - 0x57); break; // ASCII 9 0x39
    case 0xA0: return (HexValue - 0x5F); break; // ASCII A 0x41
    case 0xB0: return (HexValue - 0x6E); break; // ASCII B 0x42
    case 0xC0: return (HexValue - 0x7D); break; // ASCII C 0x43
    case 0xD0: return (HexValue - 0x8C); break; // ASCII D 0x44
    case 0xE0: return (HexValue - 0x9B); break; // ASCII E 0x45
    case 0xF0: return (HexValue - 0xAA); break; // ASCII F 0x46   
    default: break;
    }

}


List of 35 messages in thread
TopicAuthorDate
Problem with the toascii() w/ clarification            01/01/70 00:00      
   toascii not what you want            01/01/70 00:00      
      Ah yes.....makes sense            01/01/70 00:00      
         C does know ASCII            01/01/70 00:00      
            the final result:            01/01/70 00:00      
               That is a LOT of code            01/01/70 00:00      
                  It won't compile in its state because...            01/01/70 00:00      
               Grossly inefficient!            01/01/70 00:00      
                  A small trick            01/01/70 00:00      
                     small trick is cool.....            01/01/70 00:00      
                        Same as Neil's            01/01/70 00:00      
                           Ah makes sense.....            01/01/70 00:00      
                              You can still do better            01/01/70 00:00      
                                 LOL....Russ.......LOL            01/01/70 00:00      
                                    sprintf()            01/01/70 00:00      
                                       I had you at <>            01/01/70 00:00      
                                          So why not sprintf()?            01/01/70 00:00      
                                             You are right......I did say that            01/01/70 00:00      
                        How the small trick works            01/01/70 00:00      
                           Is it worth it?            01/01/70 00:00      
                              Same assembly generated for me            01/01/70 00:00      
                           You said index.....click click....very nice            01/01/70 00:00      
                              fast (sic?) lookup table            01/01/70 00:00      
                                 Faster? Probably not.            01/01/70 00:00      
               What's in a name?            01/01/70 00:00      
                  true.....but at this point.......            01/01/70 00:00      
                     Tricks and treats            01/01/70 00:00      
                     there is no time lost by doing it right            01/01/70 00:00      
                        You guys are completely right,            01/01/70 00:00      
                           the very simple way to (almost) do it right            01/01/70 00:00      
                           For the sake of learning            01/01/70 00:00      
                              Good point            01/01/70 00:00      
   UART doesn't know ASCII            01/01/70 00:00      
      Good point....but            01/01/70 00:00      
   Unhelpful documentation            01/01/70 00:00      

Back to Subject List