matlab help for fwrite
1 回表示 (過去 30 日間)
古いコメントを表示
i read matlab help about fwrite it say that write binary data to device ,not decimal you answered to my question why when i use code below
s=serial('com3','baudrate',9600);
>> set(s,'flowcontrol','none');
>> set(s,'parity','none');
>> set(s,'databit',8);
>> set(s,'stopbit',1);
>> fopen(s)
>> fwrite(s,10101010,'int8')
my 8051 receive the data via serial port and display it on led as 11111110 then when i use (s,00000110,'int8') 8051 display it 00000110 what is the wrong and what is the code to send data using fwrite in binary fourm,and how i can send like this numbers -34.3 -1.1 please heeeelp
0 件のコメント
回答 (1 件)
Walter Roberson
2013 年 3 月 25 日
fwrite(s, bin2dec('10101010'), 'int8');
fwrite(s, bin2dec('00000110'), 'int8');
Numbers such as -34.3 and -1.1 do not have a unique binary form. Use whatever form you prefer. You are going to have to write all the code for the 8051 to handle the decimal fractions, as the 8051 instruction set is strictly integer.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!