matlab help for fwrite

조회 수: 1 (최근 30일)
anas qazaz
anas qazaz 2013년 3월 25일
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
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.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by