Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

transmit numbers thru usart

Status
Not open for further replies.

asham

Junior Member level 1
Joined
Jan 24, 2006
Messages
19
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,454
i need a c program that transmits the number 1 to 20 from the hardware to the PC hyperterminal thru USART...My hardware is PICDEM PLUS 2 from microchip...and i'm using mplab ide to write this program..any help will be greatly appreciated...:
 

R00KIE

Full Member level 3
Joined
Jan 19, 2003
Messages
150
Helped
23
Reputation
46
Reaction score
3
Trophy points
1,298
Location
Portugal
Activity points
1,255
Hello, i can't give you the code but i think i can point you in the right direction.
You can only transmit 8 bits at a time, this makes a byte so to transmit a number equal to or larger than 10 you'll need to transmit two bytes (or two chars).
The number from 0 to 9 are represented in the ascii table with the numbers 48 to 57 (decimal) so that mean they are represented from 30 to 39 (hexadecimal) so you need to send through the usart 30h to send a zero, 31h to send an one 32h to send a two, and so on. to send 10 you'll need to send 31h and then 30h.
I hope this helps you understand the concept. with this knowledge you can then send anything you want, text numbers and other chars.
If i'm not wrong Ah is the carriage return, you'll need it to make numbers print in a new line.
 

asham

Junior Member level 1
Joined
Jan 24, 2006
Messages
19
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,454
thanks rookie...i get what u mean,but how do i define before using ascii,is there any special definitions...?like int,char or etc...
 

Benny

Junior Member level 2
Joined
Dec 2, 2005
Messages
23
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,281
Activity points
1,552
Hi Asham,

You should define the byte you sending as an Unsigned char.

the asci table dec values are starting at 0x00, and the char variable type is from -128 to 127. the unsigned char is from 0 to 255 : therefor this type will cover all the asci table characters.

Good luck,

Ben.
 

pvinbox@yahoo.com

Full Member level 2
Joined
May 28, 2004
Messages
125
Helped
8
Reputation
16
Reaction score
2
Trophy points
1,298
Location
Coimbatore, INDIA
Activity points
944
hai
when transmitting numbers u have to send ascii value of that number
so add 0x30 with your number
for example for 1 u need to send as 0x31

ok
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top