This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

interfacing problem

I am doing a project in which I am using Microcontroller Atmel 89C52. The problem I am facing is interfacing between MatLab and Keil.
Characters sent by MatLab are directly recognised as characters by Keil, but I am having problems in Integers being sent by MatLab and recognised by Keil.
Although both Keil & MatLab use C hence their data types are same

Keil data type:

signed int bits:16 bytes:2 range:-32768 to +32767
unsigned int bits:16 bytes:2
range:0 to 65535

data types in MatLab

uint8 range: 0 to 255
Unsigned 8-bit integer
bytes per element: 1


uint16 range: 0 to 65535
Unsigned 16-bit integer
bytes per element: 2


uint32 range: 0 to 4294967295
Unsigned 32-bit integer
bytes per element: 4


the range of unsigned integers match in both MatLab & Keil then why the problem?

1:_getkey only reads characters
2:unsigned int a;
scanf("%u",a);
(not working why?)

please help.....

Parents
  • Although both Keil & MatLab use C hence their data types are same

    This is not quite as exactly true as you assume. The most important differences are that Keil in default mode doesn't respect all rules of ANSI C about integer promotions, and that range is not all that you need to define the internal representation of a given type.

    unsigned int a;
    scanf("%u",a);
    (not working why?)

    Because it's wrong code. Unless you deliberatlely turned off all warnings, the compiler will even tell you why. Hint: there's at least one '&' missing somewhere.

Reply
  • Although both Keil & MatLab use C hence their data types are same

    This is not quite as exactly true as you assume. The most important differences are that Keil in default mode doesn't respect all rules of ANSI C about integer promotions, and that range is not all that you need to define the internal representation of a given type.

    unsigned int a;
    scanf("%u",a);
    (not working why?)

    Because it's wrong code. Unless you deliberatlely turned off all warnings, the compiler will even tell you why. Hint: there's at least one '&' missing somewhere.

Children