matlab help for fwrite
显示 更早的评论
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
回答(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.
类别
在 帮助中心 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!