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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/25/09 00:47
Read: times


 
#166433 - Re: use a cast
Responding to: ???'s previous message
Hi Maarten,

Maarten said:
I suspect that your compiler sends the small (<256) number 1 as a char to the printf function which interprets it as an unsigned int. So it reads 0x01FF of which only 0x01 was really sent to it. Try casting the constant to unsigned int.

I have declared unsigned int variable and assigned to a constant value but the data received on the HyperTerminal is not reliable:

Code:
//Declaration:
xdata unsigned int data1=1;
xdata unsigned int data2=1550;
xdata unsigned int data3=15550;

//Output to UART:
printf("DATA 1:%un",data1); //Output result to UART
printf("DATA 2:%un",data2); //Output result to UART
printf("DATA 3:%un",data3); //Output result to UART

Output on HyperTerminal:

DATA 1:53925
DATA 2:53926
DATA 3:30127
;--------------------------------------
I have also tested by using "printf" to send string and SBUF to send data, but nothing come up on the terminal:

e.g.

void serial_init(void)
{ //Configure UART
T3CON = 0x83; //configure timer 3...
T3FD = 0x12; //...for 9600 baud
SCON = 0x50;
TI=1; //Initialise to send
}

printf("DATA 1:");

SBUF=data1;
while(! TI) {} // Wait for transmission completion
TI =0; // Clear the interrupt
;--------------------------------------
Do you have any idea why it went wrong?




List of 44 messages in thread
TopicAuthorDate
CMP-10 thermal printer & 8051            01/01/70 00:00      
   Printer settings            01/01/70 00:00      
   Some hints/advice..            01/01/70 00:00      
   I sent commands like "BEL", or "ESC RS"            01/01/70 00:00      
      ASCII table            01/01/70 00:00      
      HyperTerminal & ASCII code            01/01/70 00:00      
         Would it be realistic....            01/01/70 00:00      
         Not text,            01/01/70 00:00      
            Not text,            01/01/70 00:00      
               Spend more time with the ASCII table.            01/01/70 00:00      
                  Still fail to test the printer            01/01/70 00:00      
                     The printer is working            01/01/70 00:00      
                     ASCII char on HyperTerminal            01/01/70 00:00      
                        Re: ASCII char on HyperTerminal            01/01/70 00:00      
                     ASCII char on HyperTerminal            01/01/70 00:00      
                        Is that guaranteed?            01/01/70 00:00      
                           I use it that way            01/01/70 00:00      
   XOn/XOff set on MCU side            01/01/70 00:00      
      You have to do it yourself            01/01/70 00:00      
         Re:You have to do it yourself            01/01/70 00:00      
            Intern? [edited]            01/01/70 00:00      
   HyperTerminal and microcontroller - please help!            01/01/70 00:00      
      HyperTerminal and microcontroller - please help!            01/01/70 00:00      
         May be I need to use cross over serial cable            01/01/70 00:00      
   Use printf to output to UART, but receive incorrect data            01/01/70 00:00      
      Re: Use printf to output to UART, but receive incorrect dat            01/01/70 00:00      
         printf only can output value from 256 to 32767 correctly            01/01/70 00:00      
            Hasn't Maarten already explained this?            01/01/70 00:00      
               Re: Hasn't Maarten already explained this?            01/01/70 00:00      
                  Show it!            01/01/70 00:00      
                     Re: Show it            01/01/70 00:00      
      use a cast            01/01/70 00:00      
         or RTFM            01/01/70 00:00      
            Re: RTFM            01/01/70 00:00      
            I found the solution. Thanks            01/01/70 00:00      
               Direct Memory?            01/01/70 00:00      
                  Re: Direct memory            01/01/70 00:00      
                     Definitely a BAD Idea!            01/01/70 00:00      
                        Re:Definitely a BAD Idea!            01/01/70 00:00      
                           Could you please suggest?            01/01/70 00:00      
                              Re: Do not call from ISR            01/01/70 00:00      
                                 I didn't say that            01/01/70 00:00      
                                    Thanks!            01/01/70 00:00      
         Re: use a cast            01/01/70 00:00      

Back to Subject List