Hi, all. I'm a beginer in PIC MCU. Recently I did a project about "PIC and PC serial communication" but just ran into trouble.
In the project I use Matlab to send out signal through Maxim232cpe and then PIC picked up the signal and lighted the LEDs.
My codes are listed below:
MATLAB code:
% test_serial.m
% send control message to PIC and light different LED combination.
% initiate serial port
clear all
s = serial('COM2');
% set serial object properties
set(s,'Baudrate',2400,'Databits',8,'Parity','none','Stopbits',1,'Flowcontrol','none');
fopen(s); % open the serial port to PIC
% send a decimal digit to the PIC with no terminator('%s')
% for instance k = 003 = 00000011 in binary, so first two LEDs will be lit
fprintf(s,'%s','003');
fclose(s) % close the serial port
delete(s)
clear s
Probasic Code:
' this program receives information to PC through serial port
Include "bs2defs.bas"
TRISB = %00000000 ' set ProtB as all output pins
PortB = %00000000 ' set LED ports to all zeros
main:
serin2 PORTA.1, 396, [DEC B0]
PortB = B0
Pause 2000
end
***********************
DB9 pin3 TX --> Max232 pin13 (and from MAx232 pin 12) to PIC portA.1, pin 18
***********************
problem:
1,I use a scope to monitor the serial port and the pic pin, I saw data sent from the DB9 pin 3 also responds were there on the PIC pin18
However the led didn't light...
2,Also, I noticed the TTL level was inverted, say, if I sent a bin format data: 01001001from matlab, at the
PIC chip pin18, I observed 10110110, which was reversed.
3,Again, I don't understand the meaning of Mode in a serin2/serout2 command, what's 'Inverted' and 'True' mean?
Would you guys help me out? Thanks a thousand!
Nick