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

Back to Subject List

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


 
#154548 - Problem with the toascii() w/ clarification
I'm sending data to the UART of a philips lpc936, all communications are fine, but I want to start passing arguements into the data stream. All my arguements pass properly, what isn't happening is the hex nibbles are not being converted to ascii properly.

Now if I sent say:
uart_transmit('B'); //the SBUF shows 0x42 as it should

But if I use a variable that is assigned by a passed arguement, it just sends the regular hex without converting it. Now I know you can not have something like '7B' since that is an invalid ascii character. So what i've done is mask with F0 and 0F to get the byte broken into two nibbles. I want to convert the nibble data into ASCII.

The Keil help file says to use this:
int toascii (int c); 

so I try
unsigned char REG_H;
REG_H  = (reg  & 0xF0);
REG_H  = (toascii (REG_H));

But it basically ignores it. I have #include <ctype.h> on the UART.C page.

It compiles with no warnings or errors, but when I run the Keil debugger, it never converts correctly. Not sure what I'm doing wrong or why it won't convert. But if I do the ('B'), the UART simulates the proper ASCII character in the SBUF and send.....this is also validated in the hardware that i'm sending via RS232.

Any ideas what could be up? GRANTED: I have not tried to use the toascii on anything but the REG_H thus far, figuring if REG_H isn't converting, nothing else will. Trying to find the right answer and then I'll implement it for the rest of the REG, DAT variables.

Here is the function:
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  = (reg  & 0xF0);
REG_L  = (reg  & 0x0F );
DAT1_H = (dat0 & 0xF0 );
DAT1_L = (dat0 & 0x0F );
DAT2_H = (dat1 & 0xF0 );
DAT2_L = (dat1 & 0x0F );

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);
CHECKSUM_L = (CHECKSUM_T & 0x0F);

//***********************************************************************
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('B');             Wait(2); <<<<<<<<WORKS AS IT SHOULD
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); 			// Send calculated checksum 2
//***********************************************************************
}



Hopefully its something simple? Does it HAVE to be an int for the toascii?? All my variables are unsigned chars to keep them as small as possible.

Thanks
Chris

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