PC to PIC serial communication using Matlab

3 views (last 30 days)
esra
esra on 19 Oct 2013
Commented: esra on 19 Oct 2013
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*

Answers (1)

Walter Roberson
Walter Roberson on 19 Oct 2013
fwrite(eees, uint8([1 0]))
  3 Comments
Walter Roberson
Walter Roberson on 19 Oct 2013
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 on 19 Oct 2013
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 .

Sign in to comment.

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!