PC to PIC serial communication using Matlab

10 次查看(过去 30 天)
Hi, all. I'm a work in project using PIC 16f877A and dc motor where dc motor represent door . In the project I use Matlab to send out signal (bit )(zero or one ) through Maxim232cpe and then PIC picked up the signal, if signal one bit the green LED will lighted where this lighted represent door open , if signal zero bit the green LED not light where represent door stile closed My codes are listed below:
eees=serial('COM3');
set(eees,'BaudRate',9600);
fopen(es);
fwrite(eees,1);
fwrite(eees,0);
fclose(eees);
delete(eees);
clear eees;
PIC code
if(UART1_Data_Ready()=1) then
es_pic=UART1_Read()
if(es_pic=1)then
portb.0=1 'signal to work motor
if(es_pic=0)then
portB=0
the problem when send 1 bit from matlab to PIC via Max232cpe and USB to serial adapter,the green LED will light 23 times where should be light only one time thanks ,sorry for bad English*

回答(1 个)

Walter Roberson
Walter Roberson 2013-10-19
fwrite(eees, uint8([1 0]))
  3 个评论
Walter Roberson
Walter Roberson 2013-10-19
What is the LED monitoring? Is it monitoring the USB wires? Is it monitoring the serial data that is being unpacked from the USB data packet? Do you have a USB driver on your PIC?
I recall reading that the first two bytes of each serial USB packet are reserved for indicating virtual pin status, but I do not seem to be finding that page at the moment.
esra
esra 2013-10-19
i have matlab code this code find matching between images in folder A and B, when i insert new image in folder B, matlab code will Comparing new image with images stored in folder A , the matlab will send (zero or one ) as bit to PIC (microcontroller 16F877A) if PIC received 1 , the green LED was connect with PIC will lighit,if PIC received 0 will no action.
where LED represent if there any matching .

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by