Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to accept an double byte from telnet? (CCS coding)

Status
Not open for further replies.
#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 said:
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.
 
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.
 
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;
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top