MATLAB to PIC serial interface using PIC16F877 microcontroller
MATLAB to PIC serial interface
Code with comments
below is some code I pasted in. Download the .txt file if you want the code. See the pictures for help witht he serial interface. One shows the 22kohm resistor method of connecting your serial port to a PIC. The other shows the max232 method of connecting your serial port to a PIC.
With serial connections the most common problem is not setting the computer and the PIC to the same Baud Rate, so make sure you do that (as it’s done in my code).
Also, make sure you’ve connected all of the GNDs together (PIC, MAX232, and Computer GNDs all connected).
Also, make sure that you’re using the right capacitor value for the max232 (max232 vs. max232A), see diagram in the instructable for the proper values.
Also, make sure that your computer is sending the values you think it is sending. To do this, stick wires into your DB9 cable to make a serial loopback. This will make the computer get back exactly what it has just sent. Here’s a diagram of how to wire this up:
So make your matlab code do a serial read right after the serial write.
You can also use free serial port monitoring software to makesure serial communications are occuring properly (here’s one example http://www.batchconverter.com/FreeSerialPortMonitor-download-20643.shtml).
For All Your PCB Need, One-stop PCB Solution Services Appear:
EasyEDA: free PCB design tool, 200,000+ engineers are using
PCBs: 10pcs 2-layer 10x10cm only $8.21, on-time global shipping
Components: save 50% on cost, save on freight if shipped with ordered PCBs
Current Project / Post can also be found using:
- max232 interface with pic16f877a
- interfacing microcontroller with matlab through serial port
- pic 16F877 image