Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 13th February 2004, 04:30 PM   (permalink)
Default how to accept an double byte from telnet? (CCS coding)

#include "C:\javatest\str1.h"
#include "input.c"


void main() {
int8 data1, data2;
int16 data;

while (1){
printf("press any key...\n\r");
//getch();

data1 = gethex();
data2 = gethex();
data = data1 << 8 + data2;

printf("...data %4x \n\r", data);
}
}

I want to get a double byte figure from user input,
but it shows 0000 instead of 4-digit(hex). So, is there any better way to accept double/multiple byte from user input?
janetsmith2000@yahoo.com is offline   Reply With Quote
Old 13th February 2004, 06:25 PM   (permalink)
Default Re: how to accept an double byte from telnet? (CCS coding)

Quote:
Originally Posted by janetsmith2000@yahoo.com
int8 data1, data2;
int16 data;

...
data1 = gethex();
data2 = gethex();
data = data1 << 8 + data2;
...

printf("...data %4x \n\r", data);
I dont know what your gethex function does. In any case, what is
happening might be because the x format specifier is expecing an
int or unsigned (in your case maybe an int32). As a result it is
reading the low/high word depending on the endianess of your
machine, which may not be what you want. You could try to
set data to an int32 type or better yet an unsigned since in this
case, you just want the hex value.
crust is offline   Reply With Quote
Old 13th February 2004, 06:31 PM   (permalink)
Default

gethex - get-hex is a function in input.h.

I want to do something like, let's say, when the user input

1234

or perhaps, 12345678
the system will take the whole string as hex number.
janetsmith2000@yahoo.com is offline   Reply With Quote
Old 14th February 2004, 04:23 PM   (permalink)
Default

in your code, data1 is declared as int8
so, your instruction of "data1<<8" is probably make the entire byte become zero, as 8 zero shifted in
maybe u can try this

data=data1;
data<<=8;
StupidDum is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 07:55 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.