matlab

Status
Not open for further replies.
hi guys
can any body post a code that can get an array of data from pic to matlab.i am new to matlab doesnt even know the basics correctly ,so any tips might be helpful i am posting my code along with it


SerPIC = serial('COM1'); %<--change this appropriately
set(SerPIC,'BaudRate', 9600, 'DataBits', 8, 'Parity', 'none','StopBits', 1, 'FlowControl', 'none');
fopen(SerPIC); %--open the serial port to the PIC

% fprintf(SerPIC, '%s', '003');%--send a _three_ digit string to the PIC with no terminator ('%s')

int8y = fread (SerPIC,'003','int8'); %-- 003 = 00000011 in binary, so first two LEDs of PIC will light
t = 1:10;
plot (y);

fclose(SerPIC); %--close the serial port when done
delete(SerPIC);
clear SerPIC


this is the code i have entered . it keeps on returning the error, that fread should have a double value . but if i type
y = fread(SerPIC,'003')
y is not filled with any value - i checked it in the variable editor.
my actual problem i guess is to intake a 'double' array so that i can plot a graph . please help me with the input part . i guess i can do the plotting and other things

and here is the mplab code

#include <htc.h>

__CONFIG(2, PWRTDIS & WDTPS1 & WDTDIS);
__CONFIG(4, STVRDIS);

#define _XTAL_FREQ 20000000
void _delay(unsigned long int cycles);
void main()
{
TRISC =0X00;
TXSTA = 0X00;
SYNC = 0;
BRGH =1;
BRG16 =0;
RCSTA =0X90;
SPBRG = 129;


SPEN =1;
TXEN = 1;
int a =0;
while(1)
{
RC0 =~RC0;
TXREG = 65;
while(!TXIF)
TXIF =0 ;


TXREG = 0xff;
while(!TXIF)
TXIF =0 ;


}
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…