我在使用MATLAB GUI将pic微控制器与pc连接时遇到了麻烦 Matlab给了我这个错误"警告:在达到终结者之前发生超时"
这是mikroc代码:
void main()
{
char x,send;
TRISD = 0x00;
TRISB = 1;
while(1)
{
if (PORTB.f0==1)
{
UART1_Init(9600);
Delay_ms(100);
UART_Write('s');
x = 0;
while(x==0)
{
x = UART1_Read();
if (x=='y')
{
PORTD.f0=1; Delay_ms(1000); PORTD.f0=0;
}
else if (x=='n')
{
PORTD.f1 = 1;
Delay_ms(1000);
PORTD.f1 = 0;
}
}
}
}
}
这是matlab代码:
function pushno_Callback(hObject, eventdata, handles)
delete(instrfind);
s = serial('COM4');
set(s,'BaudRate',9600,'DataBits', 8, 'Parity', 'none','StopBits', 1, 'FlowControl', none','Terminator','CR');
s.BytesAvailableFcnCount = 1;
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcn=@mycallback;
handles.pushno=s;
fopen(s);
function mycallback(hObject, event, handles)
s=handles.pushno;
out=fscanf(s);
if (out=='s')
pause(1);
fprintf(s,'y');
end
fclose(s);
delete(s);
clear s;