CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Hex data on RS232.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PIC_ECM



Joined: 23 Apr 2007
Posts: 2

View user's profile Send private message

Hex data on RS232.
PostPosted: Tue Apr 24, 2007 9:52 pm     Reply with quote

Hello all,

I am using a PIC16f690 with compiler version 4.

I have a MAX232 level translator connected to the hardware UART of the PIC.

In my code I am trying to output the HEX value 0x0a to the rs232.

I am viewing the output of the rs232 with the serial port monitor within the CCS program. When viewing the two screens, ie Hex and ASCII, 0a is apearing in the ASCII window and the HEX value 30 61 is apearing in the hex window.

I have pasted a copy of my code below all of this.

Why is this so? Should'nt the value 0a appear in the Hex window given that I have specified the value in HEX?

Have I specified something wrong in my code?

#include <stdio.h>
#include <stdlib.h>

unsigned int val = 0;

void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(False);

val = 0a;

while(1)
{
printf("%x", val);

}
}

I belive that there nust be something that I am doing incorrectly.
Ultimately I would like to be able to print a hex string to the serial port but I would like to get just a single byte first then expand on that.

Any help that anyone can offer would be greatly appreciated.
Many thanks in advanced.
Carlos.
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Tue Apr 24, 2007 10:08 pm     Reply with quote

Always remember that every number the PIC deals with is always binary. We only change the format of how we see that binary number.

I can see what's happening with your code but the pros would have to explain it.

Code:
 val = 0a;


Should be:

Code:
 val = 0x0a;


That way the compiler will know that you are feeding it a hex value.

The output you are getting is the ASCII for 0 and a.

I think if you change the assignment statement above and change your printf to:

Code:
 printf("%u", val);


You should see what you want.

Good luck,

John
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Wed Apr 25, 2007 2:20 am     Reply with quote

If you want to output the value 0A hex itself.

val = 0x0A;
printf("%c", val);

or you can also use:
putc(val);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group