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).
From Schematic to PCB Production, Just Need One Tool
Free Circuit Design Software: learn to use Editor quickly and easily
Cheapest PCB: 10pcs 2-layers 10cm×10cm only $8.21, 3-day build time, 100% E-test
Current Project / Post can also be found using:
- max232 interface with pic16f877a
- interfacing microcontroller with matlab through serial port
- pic 16F877 image